norg formatDate behavior during DST transitions
0 reputation · 22 Apr 2021, 11:15 UTC
0 reputation · 22 Apr 2021, 11:15 UTC
The formatDate function in norg allows for locale-specific string representations using 'nb', 'nn', or 'no' identifiers. While the library leverages the Intl API for these operations, it also maintains a custom fallback mechanism for environments where the Intl API is unavailable.
Current documentation focuses on static date formatting and number conventions, such as the use of commas as decimal separators. However, there is uncertainty regarding how the library manages the transition periods for daylight saving time (DST) specifically within the Norwegian time zone context.
When formatting a date that falls exactly on the transition boundary, it is unclear if the output consistently reflects the local time shift or relies on the system's underlying UTC interpretation.
formatDate maintain accuracy during the transition into and out of DST?34775 reputation · 22 Apr 2021, 18:23 UTC
formatDate function in norg maintains accuracy during daylight saving time (DST) transitions primarily when the environment supports the native Intl API. However, the behavior varies significantly depending on whether the library is using the native API or its internal custom fallback mechanism.
When norg leverages the Intl API, it delegates the time zone logic to the host environment or browser. For the Norwegian time zone (Europe/Oslo), the API correctly identifies the shift from CET (UTC+1) to CEST (UTC+2). If the input is a JavaScript Date object (which represents a specific point in UTC), formatDate will reflect the correct local time shift for that specific moment in the transition.
The custom fallback mechanism is designed for environments where Intl is unavailable. This mechanism typically lacks lacks the comprehensive IANA time zone database required to handle complex DST transitions. Consequently, the fallback may rely on a fixed offset or UTC, resulting in a one-hour error when formatting dates that fall on the transition boundary in March or October.
To ensure consistent behavior during Norwegian DST shifts, follow these steps:
Date object rather than manual strings to ensure the underlying UTC timestamp is preserved before formatting.Europe/Oslo to allow the Intl API to apply the correct rules.// Example check for the October transition (2025/2026)
const transitionDate = new Date('2026-10-25T01:30:00Z');
console.log(formatDate(transitionDate, 'nb'));
To provide a more definitive recommendation regarding your specific environment, could you specify if you are running this in a Node.js environment or a browser-based application?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.