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

respect region time format on NTP #3256

Merged
merged 1 commit into from
Sep 3, 2019
Merged

respect region time format on NTP #3256

merged 1 commit into from
Sep 3, 2019

Conversation

cezaraugusto
Copy link
Contributor

@cezaraugusto cezaraugusto commented Aug 26, 2019

fix brave/brave-browser#1308

this change allows users with 24-hour format to see time on NTP the same way their system defined. defaults to whichever locale user defined on their system settings.

Test Plan:

  1. Go to NTP and assert time there is on the same time format (12-hour or 24-hour) as your system
  2. Change your system locale to a language that defaults to the opposite time format (en-US uses the 12-hour system, pt-BR uses the 24-hour system)
  3. Relaunch Brave
  4. NTP should follow the change

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

petemill
petemill previously approved these changes Aug 26, 2019
@petemill
Copy link
Member

petemill commented Aug 26, 2019

I don't see that this respects 24-hour clock in macOS @cezaraugusto how did you get the test plan to pass in macOS?

Either way, I think it's better than current
image

Edit: I don't think there's a way to get the system 24-hour / 12-hour preference. Instead I think we should mark that this PR solves the issue of the incorrect 0 prefix, and keep the 24-hour / 12-hour issue as unsolved untile we make a preference (perhaps double-clicking the clock switches between 24-hour / 12-hour like in the Momentum extension NTP).

return new Intl.DateTimeFormat([], { hour: '2-digit', minute: '2-digit' })
// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
const options = { hour: 'numeric', minute: 'numeric' }
return new Intl.DateTimeFormat([], options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that this fixes the issue, but according to the linked documentation, the first parameter should be undefined, right?

A string with a BCP 47 language tag, or an array of such strings. To use the browser's default locale, omit this argument or pass undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, but I think the algorithm ignores it anyway. I just left it with what we had

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@cezaraugusto
Copy link
Contributor Author

@petemill this fix does solve the issue as stated by OP Please respect region time format on new tab (brave/brave-browser#1308). if you change your system locale to one that uses the 24-hour system (such as Brazilian Portuguese) then restarting the browser should update the time, so region time is indeed respected.

In fact, the above was my test plan, but to avoid asking reviewers to change their system to an unknown language, I changed the test plan for just the time format, which doesn't work to my surprise. In my opinion, if the Web API integration with the system is limited, then there's nothing we can do, and instead of marking the issue as fixed we should mark it as wontfix since there's no action we can do.

worth noting that I also tried using toLocaleDateString() but the output is the same. So it seems to be a truly web API limitation:

const event = new Date(Date.now())
event.toLocaleDateString(undefined, {timeStyle: 'short'})

I'm going to update both the issue and this PR test plan to reflect the above.

petemill
petemill previously approved these changes Aug 27, 2019
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice update to the issue and test plan. Let's see why Jenkins is complaining before merging

@petemill
Copy link
Member

Just needs rebasing @cezaraugusto

fix brave/brave-browser#1308

this change allows users with 24-hour format to see time
on NTP the same way their system defined. defaults to whichever
locale user defined on their system settings.
@cezaraugusto
Copy link
Contributor Author

rebased

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested out, LGTM; comments made in brave/brave-browser#1308 (comment) definitely make sense 👍

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.

Please respect region time format on new tab
3 participants