Here is similar code (not mine) in espBASIC...
Code: Select all[calculate_DST]
dow = time("dow")
day = time("day")
month = time("month")
hour = time("hour")
if ((DST = 1) and (dow = "Sun") and (month = "Nov") and (day >= 1) and (day < 8)) then
DST = 0
write(DaylightSavings,str(DST))
endif
if ((DST = 0) and (dow = "Sun") and (month = "Mar") and (day >=8) and (day < 15)) then
DST = 1
write(DaylightSavings,str(DST))
endif
return
it came from this thread...
- See more at:
viewtopic.php?f=41&t=11518&start=32#sthash.nbm3X642.dpufI believe one problem with this type of code is that it must be running DURING the time change or it may not catch it. ie. what happens if you start the clock up mid summer after DST took effect. You may have to manually tell it that DST is now in effect.
Here is how I did it in PIC basic which runs on a PIC microcontroler. I think it could easily be implemented in espBASIC.
Code: Select all'================================================
'--- DST Calc (dec1 dow,dec2 mth,dec2 date) ---
'================================================
dstcalc:
dst = 1 'covers Apr, May, Jun, Jul, Aug, Sep, Oct
If mth=01 then dst = 0 'Jan
If mth=02 then dst = 0 'Feb
If mth=12 then dst = 0 'Dec
March:
if mth=03 then 'March
if date <8 then
dst=0
elseif (date>7 and date<15) and dow=1 and hours<2 then
dst=0
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
'===========================================
The above code is universal and can determine if DST is in effect any time it is run.
It gets its input from an esp module running this bit of code... which simply gets the time from NTP and converts the dow to a number and the mth to a number then combines it all together into a string and sends it serially over to the PIC
Code: Select all[gettime]
bla = time()
dy = mid(bla,1,3) 'dow
mh = mid(bla,5,3) 'month
dd = mid(bla,9,2) 'date
hh = mid(bla,12,2) 'hour
mm = mid(bla,15,2) 'min
ss = mid(bla,18,2) 'sec
yr = mid(bla,21,4) 'year
'
if dy == "Sun" then dow = "1/"
if dy == "Mon" then dow = "2/"
if dy == "Tue" then dow = "3/"
if dy == "Wed" then dow = "4/"
if dy == "Thu" then dow = "5/"
if dy == "Fri" then dow = "6/"
if dy == "Sat" then dow = "7/"
'
if mh == "Jan" then mth = "01/"
if mh == "Feb" then mth = "02/"
if mh == "Mar" then mth = "03/"
if mh == "Apr" then mth = "04/"
if mh == "May" then mth = "05/"
if mh == "Jun" then mth = "06/"
if mh == "Jul" then mth = "07/"
if mh == "Aug" then mth = "08/"
if mh == "Sep" then mth = "09/"
if mh == "Oct" then mth = "10/"
if mh == "Nov" then mth = "11/"
if mh == "Dec" then mth = "12/"
'
picout = dow & mth
picout = picout & dd
picout = picout & "/"
picout = picout & hh
picout = picout & mm
picout = picout & ss
'
serialprint picout
return
cheers
dwight