-
Notifications
You must be signed in to change notification settings - Fork 30
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
Consistent Timezone Abbreviations #5002
Conversation
- Switched `formatLocal` over to use `localTimeZoneAbbr` - `localTimeZone` only produces abbreviated time zones in some browsers - This browser behaviour is implementation specific in the spec - Removed now-unused `localTimeZone`
⚡️ Lighthouse report for the changes in this PRLighthouse tested 2 URLs Report for Article
Report for Front
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 glad this change was easy(ish)! Would be interested to hear any follow-up about differences between safari desktop and safari mobile
"This PR is stale because it has been open 30 days with no activity. Unless a comment is added or the “stale” label removed, this will be closed in 3 days" |
This PR was closed because it has been stalled for 3 days with no activity. |
Why?
TL;DR Spec-compliant differences in browser implementations of the Date API resulted in different variations of the timezone name on Android and iOS.
Publication Timestamp
The publication timestamp at the top of articles looks something like this:
For apps this timestamp and the corresponding timezone are in the user's local time, and so both the datetime and the timezone name can have a large number of values. We calculate this on the user's device rather than setting it on the server. This differs from dotcom, which I believe uses a handful of timezones based on edition, calculated on the server.
The Bug
We've had a long-standing issue where the publication timestamp at the top of AR articles has sometimes shown the full timezone name, rather than an abbreviation. This means users see "British Summer Time" rather than "BST". This is unusual enough that it's previously been reported as a bug.
It turns out that "sometimes" is actually platform specific. Android users are seeing the full timezone, iOS users are seeing the abbreviation. It also transpires that if you view AR in a normal browser, Safari shows the abbreviated timezone but Firefox shows the long-form version. This suggests that Chrome (Android webviews) and Firefox are displaying timezones one way, and Safari (iOS webviews) are displaying them another.
What's Going On?
For the web publication date, AR has been using JavaScript's
Date.toTimeString()
method and a regex to retrieve the timezone name. The JavaScriptDate
API is capable of generating timezone names, but doesn't expose them directly, so you have to extract them from one of the strings produced by other methods (this is awkward).It turns out that Safari's implementation of this method produces a string that looks like this:
whereas Chrome/Firefox produce one that looks like this:
As far as I can tell, this isn't due to a bug but actually an ambiguity in the spec. The spec for that method and the spec for the timezone name state that this name is "implementation-defined". So Chrome, Safari and Firefox have decided to implement this differently 🤷.
The Fix
Thanks to @DavidLawes (⭐️) we have an alternate function called
localTimeZoneAbbr
that instead usesDate.toLocaleString
and its ability to explicitly specify a "short" timezone name. So I've switched over to using that 🙂.I've also dropped the enclosing braces, so the whole timestamp should now appear in a format identical to dotcom's. See the screenshots below.
Node also implements the long-form version, likely because it has the same V8 engine as Chrome. This meant that our tests were previously set up to expect this - I've now updated them to expect the short-form version.
Changes
formatLocal
over to uselocalTimeZoneAbbr
localTimeZone
Screenshots