Replies: 2 comments 1 reply
-
@Hebelub I think this question is appropriate for the Q&A section. |
Beta Was this translation helpful? Give feedback.
1 reply
-
It would be good to know of a more elegant solution than my current workaround. Here is my workaround:
These fixes works to compensate for the lost and gained hour because hours is ignored when formatting only the date and not the time to a string. (So as long as you add a few hours to the date before any date-only parsing, it should do the trick since hours will be ignored anyways) There is also another related problem where I did a dirty trick:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem: When handling dates during Daylight Saving Time (DST), subtracting or adding days sometimes shifts the time by one hour too much or little, causing the formatted date to show the wrong day (usually a day earlier than the intended).
Question: Is there a way to convert dates by one day from any format without caring about hours and which would work for any time zone? Our website need to be able to handle any date format but should always add or subtract exactly one day.
Reproduce problem: You need to put the computer to (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna in the Date & time settings of your computer for the conversion to be a problem for dates around the last Sunday in march. These last Sundays of march is when these countries change DST time and the days only contain 23 hours instead of 24.
Context: I receive dates from the backend in yyyy-MM-dd format as strings. The received dates are off by one day, so I have to subtract a day when using them in the frontend. Before sending data to the backend I, I have to add the day back. However, during the conversion, the day is sometimes incorrectly adjusted due to timezone issues, especially around DST changes.
Here is a simplified version of my date handling logic:
Issue: When converting the date back to one day ahead, the transformation sometimes doesn’t occur properly, but is missing one hour to transform correctly, around DST transitions. Instead of just adding or subtracting a day, it may be off by one hour, leading to the date before the conversion when removing the time from the date.
Beta Was this translation helpful? Give feedback.
All reactions