Skip to content

test(time): fix roundTime_locale DST failure in time.test.ts#21539

Open
davesecops wants to merge 1 commit intoapache:masterfrom
davesecops:fix-21538
Open

test(time): fix roundTime_locale DST failure in time.test.ts#21539
davesecops wants to merge 1 commit intoapache:masterfrom
davesecops:fix-21538

Conversation

@davesecops
Copy link

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Fixes the roundTime_locale test in test/ut/spec/util/time.test.ts which fails in any DST-observing timezone (~70% of world timezones).

Fixed issues

Details

Before: What was the problem?

The getISOTimezone() helper computed the UTC offset from new Date(0) (January 1, 1970) and applied that fixed offset string to construct expected dates across different months (January and October 1986):

function getISOTimezone(): string {
    const offsetMinutes = (new Date(0)).getTimezoneOffset(); // ← always January offset
    // ...
}

// January offset applied to October date:
new Date(\`1986-10-01T00:00:00.000\${timezoneStr}\`)

In DST-observing timezones the offset in January differs from October. For example, US Eastern: January = UTC-5 (EST), October = UTC-4 (EDT). The test constructs "midnight EST" for an October date, but roundTime() correctly rounds to midnight EDT — producing a 1-hour mismatch.

This affects any developer running npm run test in a DST-observing timezone (US, EU, Australia, NZ, Brazil, etc.).

After: How does it behave after the fixing?

Replaced ISO string construction with the Date constructor using numeric arguments:

const time1 = new Date(1986, 9, 6, 11, 25, 45, 678);

expect(roundTime(new Date(time1), 'year', false).getTime())
    .toEqual(new Date(1986, 0, 1).getTime());
expect(roundTime(new Date(time1), 'month', false).getTime())
    .toEqual(new Date(1986, 9, 1).getTime());

The Date constructor with numeric arguments always interprets them in the machine's local timezone, automatically using the correct offset for each specific date (including DST transitions). This is exactly what roundTime(..., false) computes — local time boundaries — so the expected and actual values always agree regardless of timezone.

The getISOTimezone() helper is removed as it has no other callers in the codebase.

Document Info

  • This PR doesn't relate to document changes

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes.

Related test cases or examples to use the new APIs

The fix is to the test itself. Full test suite passes (24/24 suites, 189/189 tests) after this change.

Merging options

  • Please squash the commits into a single one when merging.

Other information

This is a test-only change — no production code modified. The fix is 8 lines added, 20 lines removed (simpler code that works in all timezones).

@echarts-bot
Copy link

echarts-bot bot commented Mar 11, 2026

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant