Sidebar

Can I determine if a date is daylight savings in effect?

0 votes
197 views
asked Oct 20, 2023 by brandon-w-8204 (33,330 points)
I have a date but need to know if I should apply daylight savings time to it or not.

1 Answer

0 votes

Here is a function in that will return true if daylight savings is in effect:

function isDST(d) {
   d = qie.deduceDate(d);
   return java.util.TimeZone.getDefault().inDaylightTime( new Date(d) );
}

Here is a sample on how it is used:

qie.debug(
   'jan 2: ' + isDST('20230102102300') + '\r' +
   'feb 2: ' + isDST('20230202102300') + '\r' +
   'march 8: ' + isDST('20230308102300') + '\r' +
   'march 16: ' + isDST('20230316102300') + '\r' +
   'april 2: ' + isDST('20230402102300') + '\r' +
   'may 2: ' + isDST('20230502102300') + '\r' +
   'jun 2: ' + isDST('20230602102300') + '\r' +
   'jul 2: ' + isDST('20230702102300') + '\r' +
   'aug 2: ' + isDST('20230802102300') + '\r' +
   'sept 2: ' + isDST('20230902102300') + '\r' +
   'oct 2: ' + isDST('20231002102300') + '\r' +
   'nov 1: ' + isDST('20231101102300') + '\r' +
   'nov 10: ' + isDST('20231110102300') + '\r' +
   'dec 2: ' + isDST('20231202102300') + '\r'
);

Here is the output from the debug statement:

jan 2: false
feb 2: false
march 8: false
march 16: true
april 2: true
may 2: true
jun 2: true
jul 2: true
aug 2: true
sept 2: true
oct 2: true
nov 1: true
nov 10: false
dec 2: false

answered Oct 20, 2023 by brandon-w-8204 (33,330 points)
...