Hey group,
Been working on code to universally determine if Daylight Saving Time is or is not in effect.
Would love a second set of eyes to make sure I have not missed anything or if there is a cleaner (less code) way of doing it.
I have used the following rules as a basis...
At present, daylight saving time in the United States
begins at 2:00 a.m. on the second Sunday of March and
ends at 2:00 a.m. on the first Sunday of November
below is a shot of a spread sheet that I made to try and account for all possibilities for when a given month (March and November) might begin.
Note 1:the seven colums across represent the seven possibilities for what day of the week the month may begin on.
Note 2: the numbers next to the letter for the day of the week represent the numberd day of the week (ie sun=1, mon=2... sat=7)
Here is my code...
Code:
'===========================================
'--- DST Calc (dec1 dow,dec2 mth,dec2 date) ---
dstcalc:
dst = 1 'covers Apr, May, Jun, Jul, Aug, Sep, Oct
If (mth=1) then dst = 0 'Jan
If (mth=2) then dst = 0 'Feb
If (mth=12) then dst = 0 'Dec
March:
if mth=3 then 'March
if date <8 then
dst=0
elseif (date>7 and date<15) and dow=1 and hours<2 then
dst=0 'Mar
elseif (date=8 and dow>1) then
dst=0
elseif (date=9 and dow>2) then
dst=0
elseif (date=10 and dow>3) then
dst=0
elseif (date=11 and dow>4) then
dst=0
elseif (date=12 and dow>5) then
dst=0
elseif (date=13 and dow>6) then
dst=0
endif
endif
November:
if (mth=11) then 'November
if date >7 then
dst=0
elseif (date <8 and dow=1) and hours>1 then
dst=0
elseif (date=2 and dow<3) then
dst=0
elseif (date=3 and dow<4) then
dst=0
elseif (date=4 and dow<5) then
dst=0
elseif (date=5 and dow<6) then
dst=0
elseif (date=6 and dow<7) then
dst=0
endif
endif
return
Note that the code assumes that DST is in effect (dst=1) and tries to find reasons that dst should be set to zero (dst=0)
your thoughts or ways to improve or simplify??
thanks
Bookmarks