Repository navigation
feat: normalizeDate() uses defaultTimeZone to reinterpret Z-suffix timestamps - #1
Merged
Merged
Conversation
…mestamps When backends (Drizzle, Prisma) append Z to timestamps that are actually stored in local time, normalizeDate() now replaces the Z with the real UTC offset from defaultTimeZone config. Changes: - Add getIANAOffset() helper using Intl.DateTimeFormat - normalizeDate() accepts optional defaultTimeZone parameter - All date methods (asDate, asTime, asDatetime, asTimestamp, asRelativeTime) pass this.defaultTimeZone to normalizeDate() - parseDate() also supports defaultTimeZone for reinterpretation - formatDate() global utility uses formatter's defaultTimeZone - Export getIANAOffset from package - Bump version to 1.1.0 - 285 tests passing (25 new timezone tests)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When backends like Drizzle or Prisma store timestamps in local time but append
Zsuffix (e.g."2026-09-18T14:26:06.136Z"for Vietnam time),new Date()misinterprets them as UTC, causing a 7-hour shift.Solution
A single, focused change in
normalizeDate()that usesdefaultTimeZoneconfig to reinterpret Z-suffix strings. All date methods automatically benefit.Changes
A.
normalizeDate(value, defaultTimeZone?)— Reinterpret Z-suffix timestampsWhen
defaultTimeZoneis set and differs from"UTC", Z-suffix ISO strings have theirZreplaced with the real UTC offset:B. All date methods pass
this.defaultTimeZonetonormalizeDate()asDate(),asTime(),asDatetime(),asTimestamp(),asRelativeTime()C. New helper:
getIANAOffset(iana, refDate)Uses
Intl.DateTimeFormatto resolve IANA timezone names to UTC offset strings. Handles DST transitions and half-hour offsets (e.g.Asia/Kolkata=+05:30).D.
parseDate()andformatDate()also support timezone reinterpretationUsage
Backward Compatibility
defaultTimeZonedefaults to"UTC"— existing behavior is unchanged+07:00) are not reinterpretatedTests
25 new tests covering:
getIANAOffset()utilityparseDate()with timezone paramformatDate()global utility with defaultTimeZone285 tests total, all passing.
Version
1.0.4->1.1.0(new feature, semver minor)