-
-
Notifications
You must be signed in to change notification settings - Fork 60
refactor: leverage Temporal across the codebase - simplify timezone internals #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d99fc93
refactor(tz-utils): replace convergeLocalInstant with Temporal
KristjanESPERANTO ef5df29
refactor(node-ical): replace Intl.DateTimeFormat EXDATE check with ge…
KristjanESPERANTO e7ea611
refactor(tz-utils): replace Intl-based formatDateForRrule with Temporal
KristjanESPERANTO 9ebd66e
fix(ical): normalize DATE-only RRULE start to midnight; replace Intl …
KristjanESPERANTO 17eea35
refactor(exports): move getDateKey into main module.exports object
KristjanESPERANTO bdde0fa
refactor(ical): warn on silent UTC fallback when TZID resolves to nei…
KristjanESPERANTO 167b615
refactor(ical): replace silent catches with console.warn in timezone …
KristjanESPERANTO 19d9847
refactor(ical): move getDateKey to internal lib/date-utils module
KristjanESPERANTO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // Load Temporal polyfill if not natively available | ||
| const Temporal = globalThis.Temporal || require('temporal-polyfill').Temporal; | ||
|
|
||
| const tzUtil = require('../tz-utils.js'); | ||
|
|
||
| /** | ||
| * Construct a date-only key (YYYY-MM-DD) from a Date object. | ||
| * For date-only events, uses local date components to avoid timezone shifts. | ||
| * For date-time events with a timezone, uses Temporal to extract the calendar date | ||
| * in the original timezone (avoids UTC shift, e.g. Exchange O365 RECURRENCE-ID | ||
| * midnight-CET becoming previous day in UTC – see GitHub issue #459). | ||
| * For date-time events without timezone, extracts the date from the ISO timestamp. | ||
| * @param {Date} dateValue - Date object with optional dateOnly and tz properties | ||
| * @returns {string} Date key in YYYY-MM-DD format | ||
| */ | ||
| function getDateKey(dateValue) { | ||
| if (dateValue.dateOnly) { | ||
| return `${dateValue.getFullYear()}-${String(dateValue.getMonth() + 1).padStart(2, '0')}-${String(dateValue.getDate()).padStart(2, '0')}`; | ||
| } | ||
|
|
||
| // When the Date carries timezone metadata, extract the calendar date in that timezone. | ||
| // This prevents midnight-in-local-tz (e.g. 00:00 CET = 23:00 UTC the day before) | ||
| // from being mapped to the wrong calendar day. | ||
| // Temporal handles both IANA zones and fixed-offset strings (e.g. "+01:00") uniformly. | ||
| if (dateValue.tz) { | ||
| try { | ||
| const resolved = tzUtil.resolveTZID(dateValue.tz); | ||
| const tzId = resolved?.iana || resolved?.offset; | ||
| if (resolved && !tzId) { | ||
| console.warn( | ||
| '[node-ical] Could not resolve TZID to an IANA name or UTC offset; falling back to UTC-based date key.', | ||
| {tzid: dateValue.tz, resolved}, | ||
| ); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| if (tzId) { | ||
| return Temporal.Instant.fromEpochMilliseconds(dateValue.getTime()) | ||
| .toZonedDateTimeISO(tzId) | ||
| .toPlainDate() | ||
| .toString(); | ||
| } | ||
| } catch (error) { | ||
| console.warn(`[node-ical] Failed to resolve timezone for date key (TZID="${dateValue.tz}"), falling back to UTC: ${error?.message ?? String(error)}`); | ||
| } | ||
| } | ||
|
|
||
| return dateValue.toISOString().slice(0, 10); | ||
| } | ||
|
|
||
| module.exports = {getDateKey}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.