Repository navigation
Dates and Timezones
Paulius Juzenas edited this page Oct 12, 2026
·
1 revision
The server always runs in UTC. No timezone is set in the containers. So the server should never ask what day, month or hour a date falls on. It should only compare instants with Date, Date.now() and .getTime().
Displaying a date to a user is different. For that you need a timezone, and it should always be Europe/Oslo. Almost everything we show, like event times and deadlines, should look the same to every user. It should not change based on the visitor's own device.
There is one exception. Native HTML date and datetime-local inputs are always local to the browser. That is fine and already handled by DateInput and displayDefaultInputValue.ts.
- Never write
new Date(year, month, day, ...). It reads the fields using the local timezone of whatever machine runs the code. Use an ISO string,Date.UTC(...), or plain instant math likeDate.now() + msinstead. - Never call
date.getDate(),.getMonth(),.getFullYear(),.getHours(),.getMinutes(),.getSeconds()or.getDay()insidesrc/servicesorsrc/lib. Use thegetUTCversions instead. If you need the date in Oslo time for display, useosloDateTime(date)from@/lib/dates/oslo. - Never call
.toLocaleString(),.toLocaleDateString()or.toLocaleTimeString()without atimeZoneoption. UsedisplayDate(date)from@/lib/dates/displayDate, or passtimeZone: 'Europe/Oslo'yourself.
All three rules are enforced by eslint and will fail the build if broken.