Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
create definitions for time values in right place
Browse files Browse the repository at this point in the history
tools.h
  • Loading branch information
janbar committed Sep 7, 2015
1 parent 725a519 commit b527d15
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/cppmyth/MythEPGInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ std::string MythEPGInfo::ChannelNumber() const

int MythEPGInfo::MakeBroadcastID(unsigned int chanid, time_t starttime)
{
int timecode = (int)(difftime(starttime, 0) / 60) & 0xFFFF;
int timecode = (int)(difftime(starttime, 0) / INTERVAL_MINUTE) & 0xFFFF;
return (int)((timecode << 16) | (chanid & 0xFFFF));
}

Expand All @@ -135,7 +135,7 @@ void MythEPGInfo::BreakBroadcastID(int broadcastid, unsigned int *chanid, time_t
struct tm epgtm;

now = time(NULL);
ntc = (int)(difftime(now, 0) / 60) & 0xFFFF;
ntc = (int)(difftime(now, 0) / INTERVAL_MINUTE) & 0xFFFF;
ptc = (broadcastid >> 16) & 0xFFFF; // removes arithmetic bits
if (ptc > ntc)
distance = (ptc - ntc) < 0x8000 ? ptc - ntc : ptc - ntc - 0xFFFF;
Expand All @@ -144,7 +144,7 @@ void MythEPGInfo::BreakBroadcastID(int broadcastid, unsigned int *chanid, time_t
localtime_r(&now, &epgtm);
epgtm.tm_min += distance;
// Time precision is minute, so we are looking for program started before next minute.
epgtm.tm_sec = 59;
epgtm.tm_sec = INTERVAL_MINUTE - 1;

*attime = mktime(&epgtm);
*chanid = (unsigned int)broadcastid & 0xFFFF;
Expand Down
4 changes: 2 additions & 2 deletions src/cppmyth/MythScheduleHelper75.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,15 @@ bool MythScheduleHelper75::FillTimerEntryWithRule(MythTimerEntry& entry, const M
// fill timeslot starting at next recording
entry.startTime = rule.NextRecording(); // it includes offset correction
// WARNING: if next recording has been overriden then offset could be different
timeadd(&entry.startTime, 60 * rule.StartOffset()); // remove start offset
timeadd(&entry.startTime, INTERVAL_MINUTE * rule.StartOffset()); // remove start offset
entry.endTime = 0; // any time
}
else if (difftime(rule.LastRecorded(), 0) > 0)
{
// fill timeslot starting at last recorded
entry.startTime = rule.LastRecorded(); // it includes offset correction
// WARNING: if last recorded has been overriden then offset could be different
timeadd(&entry.startTime, 60 * rule.StartOffset()); // remove start offset
timeadd(&entry.startTime, INTERVAL_MINUTE * rule.StartOffset()); // remove start offset
entry.endTime = 0; // any time
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cppmyth/MythScheduleHelper76.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ bool MythScheduleHelper76::FillTimerEntryWithRule(MythTimerEntry& entry, const M
// fill timeslot starting at next recording
entry.startTime = rule.NextRecording(); // it includes offset correction
// WARNING: if next recording has been overriden then offset could be different
timeadd(&entry.startTime, 60 * rule.StartOffset()); // remove start offset
timeadd(&entry.startTime, INTERVAL_MINUTE * rule.StartOffset()); // remove start offset
entry.endTime = 0; // any time
}
else if (difftime(rule.LastRecorded(), 0) > 0)
{
// fill timeslot starting at last recorded
entry.startTime = rule.LastRecorded(); // it includes offset correction
// WARNING: if last recorded has been overriden then offset could be different
timeadd(&entry.startTime, 60 * rule.StartOffset()); // remove start offset
timeadd(&entry.startTime, INTERVAL_MINUTE * rule.StartOffset()); // remove start offset
entry.endTime = 0; // any time
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/pvrclient-mythtv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ PVR_ERROR PVRClientMythTV::GetRecordings(ADDON_HANDLE handle)
PVR_STRCPY(tag.strFanartPath, strFanartPath.c_str());

// EPG Entry (Enables "Play recording" option and icon)
if (difftime(now, it->second.EndTime()) < 60 * 60 * 24 ) // Up to 1 day in the past
if (difftime(now, it->second.EndTime()) < INTERVAL_DAY) // Up to 1 day in the past
tag.iEpgEventId = MythEPGInfo::MakeBroadcastID(FindPVRChannelUid(it->second.ChannelID()), it->second.StartTime());

// Unimplemented
Expand Down Expand Up @@ -1737,12 +1737,12 @@ MythTimerEntry PVRClientMythTV::PVRtoTimerEntry(const PVR_TIMER& timer, bool che
hasChannel = true;
}
// Fix timeslot as needed
if (st == 0 && difftime(et, 0) > 86400)
if (st == 0 && difftime(et, 0) > INTERVAL_DAY)
{
st = now;
}
// near 0 or invalid unix time seems to be ANY TIME
if (difftime(st, 0) < 86400)
if (difftime(st, 0) < INTERVAL_DAY)
{
st = et = 0;
hasTimeslot = false;
Expand Down
10 changes: 7 additions & 3 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ static inline struct tm *localtime_r(const time_t *clock, struct tm *result)
#include <time.h>
#endif

#define INTERVAL_MINUTE 60 ///< number of seconds in minute
#define INTERVAL_HOUR 3600 ///< number of seconds in hour
#define INTERVAL_DAY 86400 ///< number of seconds in day

static inline int daytime(time_t *time)
{
struct tm dtm;
localtime_r(time, &dtm);
int retval = dtm.tm_sec + dtm.tm_min * 60 + dtm.tm_hour * 3600;
int retval = dtm.tm_sec + dtm.tm_min * INTERVAL_MINUTE + dtm.tm_hour * INTERVAL_HOUR;
return retval;
}

Expand All @@ -59,10 +63,10 @@ static inline int weekday(time_t *time)

static inline void timeadd(time_t *time, double diffsec)
{
double dh = trunc(diffsec / 3600);
double dh = trunc(diffsec / INTERVAL_HOUR);
struct tm newtm;
localtime_r(time, &newtm);
newtm.tm_hour += (int)dh;
newtm.tm_sec += (int)(diffsec - dh * 3600);
newtm.tm_sec += (int)(diffsec - dh * INTERVAL_HOUR);
*time = mktime(&newtm);
}

0 comments on commit b527d15

Please sign in to comment.