yaroslav.korotaev
yaroslav.korotaev
TTCTheo's Typesafe Cult
Created by rNdom on 4/4/2025 in #questions
how to handle DST and/or timezones on javascript?
Tinkering with date-fns could also be helpful – https://date-fns.org/v4.1.0/docs/Time-Zones
6 replies
TTCTheo's Typesafe Cult
Created by rNdom on 4/4/2025 in #questions
how to handle DST and/or timezones on javascript?
Probably there is no single anwser to that. But here some thoughts on it, hope these could be useful. 1. Save both a UTC timestamp + desired timezone. Not UTC+N, but something like EEST/CST, which is related to location and it's daylight saving policies. So you can infer specific time shift at specific date when needed by looking up timezone database; 2. Store only schedule parameters, not pregenerate events upfront. Starting point + timezone + repeat pattern + (maybe) amendments. Generate series of events only on frontend just for viewing. Save only past/commited events in database for reporting, linked back to original schedule; 3. For simple repeated daily intervals it may be useful to store date and time separately. Like date = "2025-04-05", start = 1400 (14:00), duration = 100 (1h). So you can calculate final timestamps by advancing date to +N days and building timestamp for specified date, time and timezone.
6 replies