Page MenuHomePhabricator

Improve formatting of offset timezones in the interface
Open, MediumPublic

Description

We currently display offset timezones as +XX:XX, but that's not very user-friendly. See T321717#8423856 and the following comments for context. Instead, we should use a more user-friendly format like "UTC +XX:XX".

Screenshot 2023-01-26 at 16.29.02.png (1×1 px, 253 KB)

Event Timeline

Adding a note to connect with Amir Aharoni (re: translatability) for the engineer who will work on it.

Also worth looking into MWTimestamp::getTimezoneMessage, or DateTime::format( 'T' ) directly. It can convert geographical timezones to abbreviations (for a specific date, and the conversion can change) which is maybe a bit more friendly; offset timezones at least get "GMT" added but no space. Also, this is not localized.

<?php

$tzs = [
    'UTC',
    '+00:00',
    '+02:00',
    'America/New_York',
    'Europe/Rome',
    'Asia/Tokyo',
    'Africa/Johannesburg',
    'Australia/Perth'
];

foreach ( $tzs as $tz ) {
    $dtz = new DateTimeZone( $tz );
    $date = new DateTime( 'now', $dtz );  
    echo $tz, ' -> ', $date->format( 'T' ), "\n";
}
UTC -> UTC
+00:00 -> GMT+0000
+02:00 -> GMT+0200
America/New_York -> EST
Europe/Rome -> CET
Asia/Tokyo -> JST
Africa/Johannesburg -> SAST
Australia/Perth -> AWST

Why not adding the timezone difference immediately to the GMT/UTC time, so the local time can be displayed to the user directly... can be drived via a JavaScript: see https://stackoverflow.com/questions/1091372/getting-the-clients-time-zone-and-offset-in-javascript

console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)

Why not adding the timezone difference immediately to the GMT/UTC time, so the local time can be displayed to the user directly...

I'm not sure if I understand this proposal. The time that we display is already "local" (i.e., in the time zone specified below), no conversion is needed on the user's part. The problem here is how to display the time zone in a human-readable way, specifically in the case of raw offset time zones. The idea being that "+00:00" is not very user friendly ("UTC" or "GMT" would be much easier to understand), and same for the non-zero offsets.

That is the whole point... the user is not interested in UTC time; the user should read his/her own time; the system should add the browser timezone... not the user...

That is the whole point... the user is not interested in UTC time; the user should read his/her own time; the system should add the browser timezone... not the user...

We are talking about two different things, I believe. This task is not about choosing what time zone to use (note, that's surely something we can improve upon, but the task for that would be T362639), but how to format whatever time zone was chosen; and particularly the case when that time zone happens to be a raw UTC offset, as opposed to a geographical IANA time zone or abbreviation.