Heckler don't you get your time sync from NTP? Do you have the day of week?
If so:
Code:Delta = Date - 7 IF Month=3 AND Day=Sunday AND (Delta>0 OR Delta<8) Then DST!
By the way thank you for the ESPBasic code! Got some ideas...
Heckler don't you get your time sync from NTP? Do you have the day of week?
If so:
Code:Delta = Date - 7 IF Month=3 AND Day=Sunday AND (Delta>0 OR Delta<8) Then DST!
By the way thank you for the ESPBasic code! Got some ideas...
Hi All
I've used this for many years, works for Europe and I suppose could be adapted for USA. DST Europe changes in March or October, last weekend of the month. The routine calculates the date in the respective month that the change occurs on.
DSTStart holds the start date for DST
DSTEnd holds the end date for DST
Year holds the year in this format e.g 2016
DSTCheck:
DSTStart = (31 - (((5*Year)/4)+ 4) mod 7)
DSTEnd = (31 - (((5*Year/4)) + 1) mod 7)
Return
That's it, Pete
Can you explain how did you get this formulas?
I was searching whole net few years ago, and best I could think is to type dates for whole century find pattern, and put it in lookup table.
EDIT:
Heckler,
Just found this
http://delphiforfun.org/programs/mat...cs/dstcalc.htm
Basically what Enigma wrote, but it have calculation for US.
Last edited by pedja089; - 11th March 2016 at 22:36.
thanks enigma
that's very neat and tidy
for australia
#au DSTEnd 1st sunday in april = (7- (((5*Year/4)) + 4) % 7)
#au DSTStart 1st sunday in october = (7- (((5*Year/4)) + 5) % 7)
@MichelJasmin
yes I do use NTP as the starting point of my calculation and I do get the date in the following format...
Thu Jan 01 00:00:00 1970
But your example would (I believe) only work if I happened to check the time on the actual day that the DST or STD time began and only be persistent if I kept track of whether DST or STD was in effect.
However in my case I may power up the clock say on March 12 or any other day of the year and need to determine the current DST/STD status.
I could probably use your example and then check to see if the current date was before or after that date.
@Enigma (Pete)
So how do you translate this bit of code into PICbasic??
Does MOD 7 mean Y= X // 7 (in your example is MOD the same as the remainder?)DSTStart = (31 - (((5*Year)/4)+ 4) mod 7)
At this point I think I am going to give my code a spin and see how it performs.
but great discussion
Thanks all
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Hi Heckler
So how do you translate this bit of code into PICbasic??
DSTStart = (31 - (((5*Year)/4)+ 4) mod 7)
The whole subroutine is cut directly from my PBP program and will work as is. If you want to check it write it as a small program, set Year word variable to 2016 and debug out the start and end dates.
Cheers Pete
@Pete,
I'll give it a try.
I scanned through my PBP3 manual and could not find "MOD" anywhere. It doesn't show in the reserved word list either.
From the link that Pedja089 posted...
USA starting in 2007, extended DST to
begin on the 2nd Sunday in March (Day of month = 14 - (1+Y*5/4) mod 7)
and end on the 1st Sunday in November (Day of month = 7 - (1 + 5*Y/4) mod 7).
For Europe...
DST begins on the last Sunday in March (Day of month = 31 - (4+ 5*Y/4 ) mod 7)
and ends on the last Sunday in October (Day of month = 31 - (1 + 5*Y/4) mod 7)
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
// Remainder (Modulus)
Thanks and Regards;
Gadelhas
Hi
I think it depends on the manual you have, mine has MOD as a reserved word in it but an earlier version does not.
Cheers Pete
Bookmarks