Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in localization for datetime with override option for datetime and numbers #985

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

willfarrell
Copy link

Features:

  • new option to override browser locale for measurment and datetime
  • timeAxisStamps updated to leverage Intl.DateTimeFormat provided by @Christian-Sander
  • numbers and datetime will now show in the same locale now

Breaking changes:

  • fmtDate using strings is no longer supported

Notes:

  • type defs might need a little update. I don't know TS.
  • Will be testing over the next week.

Closes #474

@leeoniya
Copy link
Owner

leeoniya commented Aug 11, 2024

hey @willfarrell

thanks for the PR :)

since this introduces many breaking changes, i will not be able to merge it into any v1.x release in its current form. perhaps it is possible to implement this as an additionally supported formatting strategy rather than breaking existing templates?

this PR changes the behavior of many demos, for example https://leeoniya.github.io/uPlot/demos/timezones-dst.html no longer shows hours/minutes in the legend, which is the main purpose of that demo.

this is more difficult for me to read than what currently exists. it also greatly increases the risk of overlapping tick labels:

image

vs

image

also, i don't think this PR addresses the concern raised in #474 of being unable to insert line breaks into the tick strings?

anyways, this is a good starting point for something that might evolve into something real. 👍

@willfarrell willfarrell marked this pull request as draft August 11, 2024 12:48
@willfarrell
Copy link
Author

willfarrell commented Aug 11, 2024

Yes, this is a starting point, but wanted to make sure it was shared early. Sorry, should have converted to a draft.

Agreed, I used the timeAxisStamps provided by a commenter, looks like it needs some tweaking. Maybe another demo for all the stamp patterns would be helpful for testing this.

perhaps it is possible to implement this as an additionally supported formatting strategy rather than breaking existing templates?

I looked into this initially, but couldn't figure out how to override the existing timeAxisStamps via options.

unable to insert line breaks into the tick strings?

I'll reread in detail, must have missed that. Was kinda focused on my own use case and saw it has a lot of overlap.

@willfarrell
Copy link
Author

willfarrell commented Aug 17, 2024

PR is updated to support multi-line date/times and localized legend date-time.

Notable differences (en-us) at lower zoom levels:

  • 2-digit vs 4-digit year
  • , added between date and year
  • added between time and hourCycle indicator
    These make the date-time 4-char longer, but I feel this is fine because it's on a different line. One could set the hourCycle to h24 to trim by 3 char.
Screenshot 2024-08-17 at 07 24 10

Did some testing with a bunch of locale, using https://en.wikipedia.org/wiki/List_of_date_formats_by_country seems to look good.

Update; Add in hourCycle option to better support countries that allow both h12 & h24 https://en.wikipedia.org/wiki/Date_and_time_representation_by_country. ie in CA engligh formats to h12, when french formats to h24. This option will allow consistency multi language countries.

@willfarrell willfarrell marked this pull request as ready for review August 17, 2024 14:07
# Conflicts:
#	dist/uPlot.cjs.js
#	dist/uPlot.esm.js
#	dist/uPlot.iife.js
#	dist/uPlot.iife.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time format depending on the locale (bcp47)
2 participants