Skip to content

fix(time): format midnight as 12 in 12-hour {hh}/{h} templates - #21802

Open
Enesuygurs wants to merge 1 commit into
apache:releasefrom
Enesuygurs:fix-time-12-hour-midnight
Open

Enesuygurs wants to merge 1 commit into
apache:releasefrom
Enesuygurs:fix-time-12-hour-midnight

Conversation

@Enesuygurs

Copy link
Copy Markdown

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Formats hour 0 (midnight) as 12 instead of 0/00 for the 12-hour {h} and {hh} time template placeholders.

Fixed issues

N.A.

Details

Before: What was the problem?

The docs describe {hh} as 01-12 and {h} as 1-12, but at midnight echarts.time.format (also used by time axis labels and tooltip templates) produced 00/0:

echarts.time.format(new Date('2023-12-19 00:05:00 UTC'), '{hh}:{mm} {A}', true);
// '00:05 AM', expected '12:05 AM'

The 12-hour value was computed as (H - 1) % 12 + 1. In JavaScript -1 % 12 is -1, so H = 0 gave 0.

After: How does it behave after the fixing?

The 12-hour value is now computed as H % 12 || 12, so midnight gives 12:05 AM. Noon (12) and all other hours are unchanged. No built-in default template uses {h}/{hh}, so only user-provided templates are affected.

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

Added a unit test in test/ut/spec/util/time.test.ts covering midnight, noon and 23:00 with {hh}, {h} and {A}. It fails before the fix and passes after.

Validation: all 227 unit tests pass, and npm run lint and npm run checktype pass.

Merging options

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

Other information

@echarts-bot

echarts-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown

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.

This branch has not been deployed

No deployments
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