I’m using dayjs. I have a date time picker, 1 date input field and 1 time input field where you can freely navigate and change the datetime, either past or future. I also have a global timezone selector that I need to reflect it into the date.
Starting timezone is local, and if you change it, that needs to be reflected into the datetime as well. So if you’re on UTC+3 and you change to UTC, the datetime should also change (in this case -3hours).
All is good, problem is the DST. If I’m in the summer period and I try to go some months back (like in February), I need to somehow convert my current date (let’s say today) to that in February, but at the same time to keep track of the timezone.
The problem is the timezone in summer is different than the one in February, so If I have now selected UTC+3 (because today is UTC+3), when going back to February the timezone should be UTC+2 and somehow I’m missing 1 hour.
const newDateTime = date
.set('year', date.year())
.set('month', date.month())
.set('date', date.date());
Something like this where date
is the previous value before selecting a new one, and the newDateTime
would be the value that reflects the change. The date was set such that it considers the selected timezone, but now, if I go to February, newDateTime
will miss 1 hour due to the hours
on date (e.g. If now I’m on 07.06 at 00:00UTC+3, going back to February 10 will actually set me back to February 9).
Anyone have any ideas how to shift both the date and the time to the matching selected day so that DST is not messed up?
rsm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.