General area when it fits no where else

Moderator: Mmiscool

User avatar
By heckler
#66097 Ok... So it would make more sense if the dst in time.setup(zone,dst) were a flag indicating if you were in a location that actually follows DST and changes time twice a year.

So, for example Arizona, USA, does NOT ever change time so that would be a location to enter time.setup(zone,0) whereas Utah, USA DOES follow DST so there you would enter time.setup(-7,1).

Too bad it does NOT work :?

dwight
User avatar
By Joaquim Boavida
#66457 Hi All,

I have found this function. I'm not very good at C but I think it will work.
My question is: It will be possible to conver it to basic and use it?
My concern is how to access the internal time variable to add 3600 seconds.

Code: Select all
void checkDayLight() {

   
    //Check Daylight - CET/CEST (March to October)

    if(weekday() == 1 && month() == 3 && day()>=25 && day()<=31 && hour()==2 && !DST){
        setTime((now()+3600));
        DST = true;
    }else if( month() >= 4 && month() <= 9 && !DST){
        setTime((now()+3600));
        DST = true;
    }else if( month() == 10 && day() < 25 && !DST){
        setTime((now()+3600));
        DST = true;
    }
      if(weekday()==1 && month()==10 && day()>=25 && day()<=31 && hour()==3 && DST){
        DST = false;
    }
       
}

 


This function should be inside the time.setup() function I think.
Any comments?
Joaquim
User avatar
By heckler
#66464 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.dpuf

I 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