Browse Source

Merge pull request #186 from cwalther/time

Fix KI daylight saving time calculation
Adam Johnson 13 years ago
parent
commit
b6122ff7aa
  1. 10
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  2. 4
      Sources/Plasma/PubUtilLib/plUnifiedTime/plUnifiedTime.cpp
  3. 2
      Sources/Plasma/PubUtilLib/plUnifiedTime/plUnifiedTime.h

10
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -648,11 +648,11 @@ time_t cyMisc::ConvertGMTtoDni(time_t gtime)
plUnifiedTime utime = plUnifiedTime(); plUnifiedTime utime = plUnifiedTime();
utime.SetSecs(dtime); utime.SetSecs(dtime);
// check for daylight savings time in New Mexico and adjust // check for daylight savings time in New Mexico and adjust
if ( utime.GetMonth() >= 3 && utime.GetMonth() < 11 ) if ( utime.GetMonth() >= 3 && utime.GetMonth() <= 11 )
{ {
plUnifiedTime dstStart = plUnifiedTime(); plUnifiedTime dstStart = plUnifiedTime();
dstStart.SetGMTime(utime.GetYear(),3,7,2,0,0); dstStart.SetGMTime(utime.GetYear(),3,8,2,0,0);
// find first Sunday after 3/7 (second Sunday of March) // find first Sunday after (including) 3/8 (second Sunday of March)
int days_to_go = 7 - dstStart.GetDayOfWeek(); int days_to_go = 7 - dstStart.GetDayOfWeek();
if (days_to_go == 7) if (days_to_go == 7)
days_to_go = 0; days_to_go = 0;
@ -660,13 +660,13 @@ time_t cyMisc::ConvertGMTtoDni(time_t gtime)
plUnifiedTime dstEnd = plUnifiedTime(); plUnifiedTime dstEnd = plUnifiedTime();
dstEnd.SetGMTime(utime.GetYear(),11,1,1,0,0); dstEnd.SetGMTime(utime.GetYear(),11,1,1,0,0);
// find first sunday after 11/1 (first Sunday of November) // find first sunday after (including) 11/1 (first Sunday of November)
days_to_go = 7 - dstEnd.GetDayOfWeek(); days_to_go = 7 - dstEnd.GetDayOfWeek();
if (days_to_go == 7) if (days_to_go == 7)
days_to_go = 0; days_to_go = 0;
time_t dstEndSecs = dstEnd.GetSecs() + days_to_go * kOneDay; time_t dstEndSecs = dstEnd.GetSecs() + days_to_go * kOneDay;
if ( dtime > dstStartSecs && dtime < dstEndSecs ) if ( dtime >= dstStartSecs && dtime < dstEndSecs )
// add hour for daylight savings time // add hour for daylight savings time
dtime += kOneHour; dtime += kOneHour;
} }

4
Sources/Plasma/PubUtilLib/plUnifiedTime/plUnifiedTime.cpp

@ -257,9 +257,9 @@ void plUnifiedTime::ToCurrentTime()
SetToUTC(); SetToUTC();
} }
hsBool plUnifiedTime::SetGMTime(short year, short month, short day, short hour, short minute, short second, unsigned long usec, int dst) hsBool plUnifiedTime::SetGMTime(short year, short month, short day, short hour, short minute, short second, unsigned long usec)
{ {
if( !SetTime( year, month, day, hour, minute, second, usec, dst ) ) if( !SetTime( year, month, day, hour, minute, second, usec, 0 ) )
return false; return false;
fSecs -= IGetLocalTimeZoneOffset(); fSecs -= IGetLocalTimeZoneOffset();

2
Sources/Plasma/PubUtilLib/plUnifiedTime/plUnifiedTime.h

@ -128,7 +128,7 @@ public:
void SetSecsDouble(double secs); void SetSecsDouble(double secs);
void SetMicros(const uint32_t micros) { fMicros = micros; } void SetMicros(const uint32_t micros) { fMicros = micros; }
hsBool SetTime(short year, short month, short day, short hour, short minute, short second, unsigned long usec=0, int dst=-1); hsBool SetTime(short year, short month, short day, short hour, short minute, short second, unsigned long usec=0, int dst=-1);
hsBool SetGMTime(short year, short month, short day, short hour, short minute, short second, unsigned long usec=0, int dst=-1); hsBool SetGMTime(short year, short month, short day, short hour, short minute, short second, unsigned long usec=0);
hsBool SetToUTC(); hsBool SetToUTC();
void ToCurrentTime(); void ToCurrentTime();
void ToEpoch() { fSecs = 0; fMicros = 0;} void ToEpoch() { fSecs = 0; fMicros = 0;}

Loading…
Cancel
Save