How to handle daylight savings time when calculating time/date

Glen Collins December 8, 2021

Hello everyone! I have run across an interesting issue. I created a form which my users use a calendar pull down to select a date in the future. When they select the start date, I calculate the end date for 7 days later and adding an additional 7 hours to the end date so the end time would show 2022-02-07 07:00.

When my users select 2022-03-07 as a start date the end date gets set 

2022-03-14 08:00

when it should be 2022-03-14 07:00.

Since our daylight savings time starts 2022-03-13 I'm wondering how I can programmatically work this field calculation for this one specific issue. I know this is also probably going to happen when our DST ends. So is there any way I can fix this little annoyance?

This is how I set the field.....

OnCallEnd=[entry.BeginDate.timestamp.add(604800000+25200000).formatDate(yyyy-MM-dd HH:mm)]

the 604800000 is 7 days ahead and the 25200000 is 7 hours ahead. I tried to set the timezone to the formatDate but that didn't help.

Any help in this little annoyance would be appreciated.

Thanks.

Glen

 

2 answers

0 votes
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2021

Hi

Honestly, I am quite puzzled by this complexity and probably not getting the whole reasoning behind it, but...

If you know when you need to calculate the end date adding another hours then I suggest to make the calculation conditional, based on that.

So, basically having two functions - one that calculates your end date before the certain date and another one that calculates it after

Alex

0 votes
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 8, 2021

Is this via a user macro? In other words, is the calculation rendered each time the page is refreshed?

Does your server time adjust for DST? In other words, can you detect the change by the server time zone marker?

Otherwise, you either have to a) live with the edge cases 2 weeks out of the year, or b) you have to programmitaclly keep track of the dates the times change and do your own adjustment (not pretty, but workable).

Glen Collins December 21, 2021

This is within confiforms and not a user macro. The calculation is done when the date dialog is closed and it then performs the calculations based upon the data I have provided. I don't know if confiforms uses it own method of determining daylight savings or if they rely on confluence to do this. All I know is it starts one week before the actual time change takes place. But I'm just worried about monday as this is the specific day users are allowed to select.

This is a minor annoyance and I've just notified my users to watch out for this twice a year.

Thanks.

Glen

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events