[windev] Calculating DST switch moments of many future years

Mark McGinty mmcginty at dbunwired.com
Thu Mar 26 11:42:30 GMT 2009


 

> -----Original Message-----
> From: windev-bounces at windev.org 
> [mailto:windev-bounces at windev.org] On Behalf Of Goran Pusic
> Sent: Thursday, March 26, 2009 2:29 AM
> To: windev at windev.org
> Subject: [windev] Calculating DST switch moments of many future years
> 
> 
> Hi all!
> 
> I need to calculate UTC moment for DST switches for a given 
> time zone (perhaps different from system's time zone), for a 
> couple of decades in advance. (If it sounds like a WTF: this 
> info is sent to an embedded system to help it know about it's 
> timezone bias at every moment in time, for as long as it will 
> live, so that it can calculate local time).

Was the code written to apply the new DST rules for dates in 2007 and later?
If not your couple decades worth of data generated in advance contains
flaws.

My approach to converting to UTC was this:

1. Get tz bias for a given zone for 2 dates, each of which is definitively
in std time, and DST, respectively.  01 Jan and 01 June work nicely, for
every year since the inception of DST, new years day has fallen within DST,
and the first day of June under standard time.  This gives you both standard
bias and DST bias that are guaranteed correct for a given time zone.

2. Then I determine whether the date in question fell within DST, using the
rules that applied to the year in which the date occurred, which in turn
determines which of the two bias values [acquired in step 1] is the correct
one to apply.


Start of DTC:

    USA:
        Year <= 2006:
            Month = 4
            Day = (2 + 6 * Year - (short)(Year / 4)) % 7 + 1

        2007 and after:
            Month = 3
            Day = 14 - ((short)(1 + Year * 5 / 4) % 7)

    Europe:
        Month = 3
        Day = (31 - ((short)(Year * 5 / 4) + 4) % 7)


End of DTC:
    
    USA:
        Year <= 2006:
            Month = 10
            Day = (31 - (short)(Year * 5 / 4) + 1) % 7)

        2007 and after:
            Month = 11
            Day = 7 - (short)(1 + Year * 5 / 4) % 7)

    Europe (same as USA prior to 2007):
        Month = 10
        Day = (31 - (short)(Year * 5 / 4) + 1) % 7)


In your case you could calc those 4 values once for each year you were going
to generate, and cache them in an array or something.


-MM


 
> For that, I have a calculation that relies on Windows 
> TIME_ZONE_INFORMATION and friends. However, recently (after 
> some 5-6 years after the code was written), people found out 
> there are bugs inside my calculation :-( .
> 
> Now... Before I delve into this again (it's not urgent, it's 
> for next autumn ;-) ), do you guys have any pointers on how 
> to do it? Did anyone do it before?
> 
> HTH,
> Goran.
> 
> P.S.
> 
> Yes, I know that DST rules change, so calculation may be good 
> now, but bad in the future. Nothing I can do about that, it's 
> on shoulders of users. 
> 
> P.P.S Hi, Serge W! Remember this? (Bug is mine, though)
> 
> 
> 
>       
> --
> Windev mailing list at Windev at windev.org
> 
> Lost your password?  Need to unsubscribe or change your 
> delivery options?  
> Go to http://lists.windev.org/mailman/listinfo/windev
> --
> Search the Windev Archives - www.windev.org
> 



More information about the Windev mailing list