-
Notifications
You must be signed in to change notification settings - Fork 324
[Repo Assist] [JS/TS] Fix DateTimeOffset.ToString using local timezone instead of stored offset#4521
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
...fset Root cause: dateToStringWithOffset created the adjusted date with new Date(...), which has no kind property. The day(), month(), year(), dayOfWeek() helpers all fall back to local-timezone JS methods when kind is undefined, so on any runner whose local timezone is not UTC the formatted date/time components were wrong. Fix: use DateTime(..., DateTimeKind.Utc) so the helpers consistently call the UTC getters on the offset-adjusted timestamp. Fixes #4375 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
github-actions
Bot
added
automation
Automated changes
repo-assist
Created by Repo Assist
labels
Apr 10, 2026
41 tasks
24 tasks
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.
You can’t perform that action at this time.
🤖 This pull request was created by Repo Assist, an automated AI assistant.
Summary
Fixes
DateTimeOffset.ToStringwith format specifiersD,d,T,t, and custom format strings producing wrong date/time components when the runner or end-user machine is in a non-UTC timezone.Closes #4375
Root Cause
dateToStringWithOffsetinDate.tsconstructed the offset-adjusted date withnew Date(...), which produces a plain JavaScriptDatewith nokindproperty:The helper functions
day(),month(),year(),dayOfWeek(),hour(), etc. all branch ond.kind:When
kindisundefined, they fall through to the local-timezone JS methods (.getDate(),.getMonth(), etc.). On a machine in e.g. Australia/Melbourne (UTC+10), aDateTimeOffsetof2014年09月01日T16:37:02+02:00(UTC:14:37:02 on Sep 1) produces an offset-adjusted timestamp of2014年09月01日T16:37:02Z. But.getDate()in Melbourne returns September 2 (since it is past midnight local time).Fix
Use the
DateTime()factory withDateTimeKind.Utcinstead ofnew Date():Since we have already added the stored offset to shift the UTC epoch to the "wall clock" time, reading via UTC getters (
getUTCDate(),getUTCMonth(), etc.) gives the correct result regardless of local timezone.Trade-offs
dateToStringWithOffsetD,d,T,t,O/o, custom) remain correcttoUniversalTime(d)now returnsdunchanged (alreadyUtckind), correct forT/tformattingdateToISOStringWithOffsetacceptsDateandIDateTime extends Date, TypeScript typing is satisfied