Calculating Daylight Saving Time


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    I don't understand your tables... Column c,d,e are years? If there are, what years?
    The seven columns represent ANY year. Since in any given year, the first day of March or November could be a Sun, Mon, Tue, etc. I had to account for that fact that there are 7 POSSIBLE starting days for each month.

    The reason I also show Sun=1, Mon=2, etc., is so I could ask "less than" or "greater than" questions.

    I wanted this to be a universal calculation for USA.

    The code will only apply for these rules...
    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
    If you are in another part of the world where you have different rules (or no DST at all) then obviously this would not apply.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    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!
    Name:  CalculsDST.png
Views: 4769
Size:  26.1 KB

    By the way thank you for the ESPBasic code! Got some ideas...

  3. #3
    Join Date
    Jul 2003
    Location
    Lancashire
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    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

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    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 21:36.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    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)

  6. #6
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    @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??
    DSTStart = (31 - (((5*Year)/4)+ 4) mod 7)
    Does MOD 7 mean Y= X // 7 (in your example is MOD the same as the remainder?)

    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.

  7. #7
    Join Date
    Jul 2003
    Location
    Lancashire
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    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

  8. #8
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Calculating Daylight Saving Time

    @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.

Similar Threads

  1. Calculating time delay between two inputs?
    By grimmjow in forum General
    Replies: 11
    Last Post: - 18th October 2010, 14:52
  2. Calculating Time for clock's preset
    By menta in forum General
    Replies: 33
    Last Post: - 5th July 2008, 06:09
  3. Calculating elapsed time, how?
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st June 2006, 09:00
  4. FYI Daylight Saving Time in the U.S.
    By ccsparky in forum General
    Replies: 1
    Last Post: - 7th November 2005, 15:05
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 28th November 2004, 23:56

Members who have read this thread : 7

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts