Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling Daylight Savings Time
#1
Is there a way to handle the UTC to Local time for time stamps that are in the future that accounts for Daylight Savings Time?  I am capturing a UTC time for an event in the future, but want it to display in my current time, but this future time stamp is past the time change.  It will show up an hour off until my local time is the same time offset as the future event.

I didn't see anything in the CML documentation for MEng.Time documentation.
Reply
#2
You would need to probably create the actual time by setting the individual details, then get the stamp out. That should have the correct time accounting for such adjustments.
Dean Roddey
Explorans limites defectum
Reply
#3
I vote to abolish DST Smile
Reply
#4
Here is the routine I am using, which takes a Unix Time that is some time in the future, adds the milliseconds to the end, then creates a CQC Time and CQC Card8 number.  I am not sure what you mean about breaking out the individual pieces first.  In the routine below, it will always set the Local time offset for today, even if the CQCTime is in the future.


Code:
    Method UnixToCQCTime([In] String UnixTime,[Out] Card8 CardTime) Returns Time
    Begin
            Locals=
                Card8   TmpCard;
                String  TmpStr;
                Time    CQCTime;
            EndLocals;

            TmpStr := UnixTime;
            TmpStr.Append("0000000");
            TmpCard := TmpStr.ToCard8();
            CQCTime.SetFromStamp(TmpCard);
            CQCTime.UTCToLocal();
            CardTime := CQCTime.GetStamp();

     Return CQCTime;
Reply
#5
(03-10-2020, 04:22 AM)gReatAutomation Wrote: I vote to abolish DST Smile

I'd back you on that one. It's really ridiculous in this day and age.
Dean Roddey
Explorans limites defectum
Reply
#6
(03-10-2020, 05:23 AM)kblagron Wrote: Here is the routine I am using, which takes a Unix Time that is some time in the future, adds the milliseconds to the end, then creates a CQC Time and CQC Card8 number.  I am not sure what you mean about breaking out the individual pieces first.  In the routine below, it will always set the Local time offset for today, even if the CQCTime is in the future.


Code:
    Method UnixToCQCTime([In] String UnixTime,[Out] Card8 CardTime) Returns Time
    Begin
            Locals=
                Card8   TmpCard;
                String  TmpStr;
                Time    CQCTime;
            EndLocals;

            TmpStr := UnixTime;
            TmpStr.Append("0000000");
            TmpCard := TmpStr.ToCard8();
            CQCTime.SetFromStamp(TmpCard);
            CQCTime.UTCToLocal();
            CardTime := CQCTime.GetStamp();

     Return CQCTime;

Are you sure that time is seconds since 01/01/1970? What types of numbers are you ending up with?
Dean Roddey
Explorans limites defectum
Reply
#7
So a date within the JSON shows 1552456800, and the UnixToCQCTime method posted above will change it to 15524568000000000.  This date converts to 03/13/2020 at 6:00 am (UTC).  If I run this before daylight savings time has occurred on my system and apply the conversion to get it to a local time (UTCtoLocal), it will subtract 6 hours.  If I do this after daylight savings time it will subtract 5 hours.

I guess what would be optimal is if the UTCToLocal() command would know that the time is in Daylight Savings Time, and correct it accordingly.
Reply
#8
I'm not doing any of that stuff myself. Windows is doing those calculations, I just wrap them. It's hard to imagine that Windows would get something that wrong. How are you testing this to make the system thing it is DST or not?
Dean Roddey
Explorans limites defectum
Reply
#9
(03-13-2020, 01:16 PM)Dean Roddey Wrote: I'm not doing any of that stuff myself. Windows is doing those calculations, I just wrap them. It's hard to imagine that Windows would get something that wrong.  How are you testing this to make the system thing it is DST or not?

I have two drivers - Google Calendar & RainMachine - both post dates in the future, of course the Google Calendar does it further out.  If I have a date in DST time, I get the UTC time via a HTTP Get command, and then when I convert it to local time, it uses the current offset for today and applies it to that date.  

I will ponder this a bit, and see if I can figure out a way to know that the date is either DST or normal time.  The optimum solution would be for UTCToLocal() function to know, based on my location, what the proper local time would be for that date in the future.
Reply
#10
I really do not miss having to do time calculations. When I was tackling time issues for a start up where I once worked, time was important because we were delivering over the air content, sending stuff over satellite, etc.

Decided to store anything time related in the data base in UTC represented by Epoch time (milliseconds). This was for everything. Database timestamps, schedules. Literally anything time related. For customer stuff, there was a column in that table that had the customer's UTC offset. Same for other things.

DST was a huge PITA because there are states that do not recognize it, as well as countries. Was another flag it the database.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Triggered Event only works every second time znelbok 2 1,276 10-27-2020, 12:05 PM
Last Post: znelbok
  Timers Driver / Field Time Image / Seconds gReatAutomation 1 1,345 03-16-2020, 05:48 PM
Last Post: Dean Roddey
  LogicServer Elapsed Time and Triggered Event gReatAutomation 6 2,720 08-17-2019, 07:53 AM
Last Post: gReatAutomation
  Time formatting RunTime Time Variable? gReatAutomation 5 2,433 08-14-2019, 05:23 AM
Last Post: gReatAutomation
  Use UI to alter scheduled event time IVB 1 1,310 07-09-2019, 08:42 PM
Last Post: IVB
  Getting a Card8 into a Time Format in CML kblagron 2 1,504 03-14-2019, 11:15 PM
Last Post: kblagron
  What would the proper trigger to be for a time or a X min before sundown? ghurty 1 1,560 01-10-2019, 10:08 AM
Last Post: Dean Roddey
  GetCurMillis immune to system time change? rbroders 6 2,884 12-09-2018, 02:58 PM
Last Post: rbroders
  Down time today Dean Roddey 0 1,194 11-19-2018, 05:07 PM
Last Post: Dean Roddey
  Nice job on the scaling! 1 template for the 1st time! IVB 0 1,663 07-15-2018, 04:38 PM
Last Post: IVB

Forum Jump:


Users browsing this thread: 1 Guest(s)