Browse Source

Fix KI daylight saving time calculation.

The previous implementation had the following bugs:
- DST was truncated to end of October
- DST start was off by one week in years where March 1st is a Monday
- DST start was off by one second (1:59:59 -> 2:00:00 -> 3:00:01 instead of the correct 1:59:59 -> 3:00:00 -> 3:00:01)

Tested against tzdata 2009g.
dst
Christian Walther 13 years ago
parent
commit
a9cb4723d0
  1. 10
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

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

@ -649,11 +649,11 @@ UInt32 cyMisc::ConvertGMTtoDni(UInt32 gtime)
plUnifiedTime utime = plUnifiedTime();
utime.SetSecs(dtime);
// 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();
dstStart.SetGMTime(utime.GetYear(),3,7,2,0,0);
// find first Sunday after 3/7 (second Sunday of March)
dstStart.SetGMTime(utime.GetYear(),3,8,2,0,0);
// find first Sunday after (including) 3/8 (second Sunday of March)
UInt32 days_to_go = 7 - dstStart.GetDayOfWeek();
if (days_to_go == 7)
days_to_go = 0;
@ -661,13 +661,13 @@ UInt32 cyMisc::ConvertGMTtoDni(UInt32 gtime)
plUnifiedTime dstEnd = plUnifiedTime();
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();
if (days_to_go == 7)
days_to_go = 0;
UInt32 dstEndSecs = dstEnd.GetSecs() + days_to_go * kOneDay;
if ( dtime > dstStartSecs && dtime < dstEndSecs )
if ( dtime >= dstStartSecs && dtime < dstEndSecs )
// add hour for daylight savings time
dtime += kOneHour;
}

Loading…
Cancel
Save