vdr-plugin-tvguide/timer.c

123 lines
3.5 KiB
C
Raw Normal View History

2013-01-17 13:16:44 +01:00
#include "timer.h"
cMyTime::~cMyTime(void) {
}
cString cMyTime::printTime(time_t displayTime) {
struct tm *ts;
ts = localtime(&displayTime);
cString strTime = cString::sprintf("%d.%d-%d:%d.%d", ts->tm_mday, ts->tm_mon+1, ts->tm_hour, ts->tm_min, ts->tm_sec);
return strTime;
}
2013-05-26 11:38:05 +02:00
void cMyTime::Now() {
t = time(0);
tStart = t;
tStart = GetRounded();
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
2013-05-31 13:58:22 +02:00
tEnd = tStart + (tvguideConfig.osdHeight - tvguideConfig.statusHeaderHeight - tvguideConfig.channelHeaderHeight - tvguideConfig.channelGroupsHeight - tvguideConfig.footerHeight)/tvguideConfig.minutePixel*60;
2013-05-24 16:23:23 +02:00
} else if (tvguideConfig.displayMode == eHorizontal) {
2013-05-31 13:58:22 +02:00
tEnd = tStart + (tvguideConfig.osdWidth - tvguideConfig.channelHeaderWidth - tvguideConfig.channelGroupsWidth)/tvguideConfig.minutePixel*60;
2013-05-24 16:23:23 +02:00
}
2013-01-17 13:16:44 +01:00
}
void cMyTime::AddStep(int step) {
2013-05-26 11:38:05 +02:00
tStart += step*60;
tEnd += step*60;
2013-01-17 13:16:44 +01:00
}
bool cMyTime::DelStep(int step) {
2013-05-26 11:38:05 +02:00
if ((tStart - step*60)+30*60 < t) {
return true;
}
tStart -= step*60;
tEnd -= step*60;
return false;
2013-01-17 13:16:44 +01:00
}
void cMyTime::SetTime(time_t newTime) {
2013-05-26 11:38:05 +02:00
tStart = newTime;
2013-05-24 16:23:23 +02:00
if (tvguideConfig.displayMode == eVertical) {
2013-05-31 13:58:22 +02:00
tEnd = tStart + (tvguideConfig.osdHeight - tvguideConfig.statusHeaderHeight - tvguideConfig.channelHeaderHeight - tvguideConfig.channelGroupsHeight - tvguideConfig.footerHeight)/tvguideConfig.minutePixel*60;
2013-05-24 16:23:23 +02:00
} else if (tvguideConfig.displayMode == eHorizontal) {
2013-05-31 13:58:22 +02:00
tEnd = tStart + (tvguideConfig.osdWidth - tvguideConfig.channelHeaderWidth - tvguideConfig.channelGroupsWidth)/tvguideConfig.minutePixel*60;
2013-05-24 16:23:23 +02:00
}
2013-01-17 13:16:44 +01:00
}
time_t cMyTime::getPrevPrimetime(time_t current) {
2013-05-26 11:38:05 +02:00
tm *st = localtime(&current);
if (st->tm_hour < 21) {
current -= 24 * 60* 60;
st = localtime(&current);
}
st->tm_hour = 20;
st->tm_min = 0;
time_t primeTime = mktime(st);
return primeTime;
2013-01-17 13:16:44 +01:00
}
time_t cMyTime::getNextPrimetime(time_t current){
2013-05-26 11:38:05 +02:00
tm *st = localtime(&current);
if (st->tm_hour > 19) {
current += 24 * 60* 60;
st = localtime(&current);
}
st->tm_hour = 20;
st->tm_min = 0;
time_t primeTime = mktime(st);
return primeTime;
2013-01-17 13:16:44 +01:00
}
bool cMyTime::tooFarInPast(time_t current) {
2013-05-26 11:38:05 +02:00
if (current < t) {
return true;
}
return false;
2013-01-17 13:16:44 +01:00
}
cString cMyTime::GetCurrentTime() {
2013-05-26 11:38:05 +02:00
char buf[25];
t = time(0);
tm *st = localtime(&t);
//snprintf(text, sizeof(text), "%d:%02d", st->tm_hour, st->tm_min);
if (tvguideConfig.timeFormat == e12Hours) {
strftime(buf, sizeof(buf), "%I:%M %p", st);
} else if (tvguideConfig.timeFormat == e24Hours)
strftime(buf, sizeof(buf), "%H:%M", st);
return buf;
2013-01-17 13:16:44 +01:00
}
cString cMyTime::GetDate() {
2013-05-26 11:38:05 +02:00
char text[6];
tm *st = localtime(&tStart);
snprintf(text, sizeof(text), "%d.%d", st->tm_mday, st->tm_mon+1);
return text;
2013-01-17 13:16:44 +01:00
}
cString cMyTime::GetWeekday() {
2013-05-26 11:38:05 +02:00
return WeekDayName(tStart);
2013-01-17 13:16:44 +01:00
}
int cMyTime::GetTimelineOffset() {
2013-05-26 11:38:05 +02:00
tm *st = localtime(&tStart);
int offset = st->tm_hour*60;
offset += st->tm_min;
return offset;
2013-01-17 13:16:44 +01:00
}
time_t cMyTime::GetRounded() {
2013-05-26 11:38:05 +02:00
tm *rounded = localtime ( &tStart );
rounded->tm_sec = 0;
if (rounded->tm_min > 29)
rounded->tm_min = 30;
else
rounded->tm_min = 0;
return mktime(rounded);
2013-01-17 13:16:44 +01:00
}
void cMyTime::debug() {
2013-05-26 11:38:05 +02:00
esyslog("t: %s, tStart: %s, tEnd: %s", *TimeString(t), *TimeString(tStart), *TimeString(tEnd));
2013-01-17 13:16:44 +01:00
}