Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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
main from
repo-assist/fix-issue-4375-datetimeoffset-format-timezone-ec7abeae6c7276a6
Draft

[Repo Assist] [JS/TS] Fix DateTimeOffset.ToString using local timezone instead of stored offset #4521
github-actions[bot] wants to merge 1 commit into
main from
repo-assist/fix-issue-4375-datetimeoffset-format-timezone-ec7abeae6c7276a6

Conversation

@github-actions

@github-actions github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

🤖 This pull request was created by Repo Assist, an automated AI assistant.

Summary

Fixes DateTimeOffset.ToString with format specifiers D, 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

dateToStringWithOffset in Date.ts constructed the offset-adjusted date with new Date(...), which produces a plain JavaScript Date with no kind property:

const d = new Date(date.getTime() + (date.offset ?? 0));

The helper functions day(), month(), year(), dayOfWeek(), hour(), etc. all branch on d.kind:

export function day(d: IDateTime) {
 return d.kind === DateTimeKind.Utc ? d.getUTCDate() : d.getDate();
}

When kind is undefined, they fall through to the local-timezone JS methods (.getDate(), .getMonth(), etc.). On a machine in e.g. Australia/Melbourne (UTC+10), a DateTimeOffset of 2014年09月01日T16:37:02+02:00 (UTC: 14:37:02 on Sep 1) produces an offset-adjusted timestamp of 2014年09月01日T16:37:02Z. But .getDate() in Melbourne returns September 2 (since it is past midnight local time).

Fix

Use the DateTime() factory with DateTimeKind.Utc instead of new Date():

const d = DateTime(date.getTime() + (date.offset ?? 0), DateTimeKind.Utc);

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

  • Minimal, targeted change — only affects dateToStringWithOffset
  • All format paths (D, d, T, t, O/o, custom) remain correct
  • toUniversalTime(d) now returns d unchanged (already Utc kind), correct for T/t formatting
  • dateToISOStringWithOffset accepts Date and IDateTime extends Date, TypeScript typing is satisfied

Generated by Repo Assist · くろまる 10.4M ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

...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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

automation Automated changes repo-assist Created by Repo Assist

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[JS/TS] Tests fail on timezone Australia/Melbourne (should works perhaps)

0 participants

AltStyle によって変換されたページ (->オリジナル) /