Sometimes you may need to know if a timestamp occurs in Daylight Saving Time or not. As the underlying time library in processing code is Moment.js, you can use various functions to manipulate or query any time variables in your processing code.
For example, by combining the tz function and the isDST function, you can set the timezone of your current timestamp to be a specific region (such as "America/Chicago" which will use Central time zone), and then ask if the timestamp is within the daylight saving period for that region.
To show a simple example of this, we create a text process named is param1 DST
:
var input = NODE( "param1" );
var ts = T( input.currentTime );
return ts.tz( "America/Chicago" ).isDST();
When tested with some sample data, you can see the change to daylight saving (i.e. from Central Standard Time to Central Daylight Time) occurring at 2:00am on March 13th, 2022:
The main use case for DST detection would be when data has timestamps which are not aware of DST, and you wish to manually correct them. This is usually done automatically when data is acquired, provided the "Ignore Daylight Savings Time" option has been used correctly:
If you have a data logger clock that does not adjust for DST, i.e. it uses the same fixed UTC offset all year round, then checking "Ignore Daylight Savings Time" ensures that eagle.io convert the timestamp to UTC correctly by always adding 6 hours to the timestamps during data acquisition.
However, if you have a data logger clock that adjusts during DST, then don't check the box; eagle.io will convert the timestamps to UTC by adding 6 hours when DST is not in effect, and adding 5 hours when DST is in effect (for the specific time zone). This ensures that all timestamps will be converted to UTC correctly when data is acquired.
Comments
0 comments
Article is closed for comments.