Search code examples
htmldatetimebrowsertimezoneutc

Is browser required to detect user timezone for datetime input?


I installed Opera browser because it is currently the only browser that possess the HTML5 datetime calender functionality. There are two types of datetime input: one is the datetime-local where timezone information is omitted; the other is datetime itself where time-zone information is added.

From what I observe in Opera, the timezone is fixed at UTC instead of following the user's time-zone for datetime input. This seems counter-intuitive as user would normally not know what UTC time is, let alone calculate the correct UTC time based on his own time-zone.

Does W3C requires UTC to be the default timezone for datetime input, or is Opera browser doing the right thing by fixing timezone as UTC?

Upon further research, this is what I find:

whatwg seems to suggest the opposite way:

  • datetime (specific year, month, day, time)
  • datetime-local (specific year, month, day, time, timezone)

Mozilla documentation says this:

  • datetime: HTML5 A control for entering a date and time (hour, minute, second, and fraction of a second) based on UTC time zone.

W3C proposes the following:

  • User agents must not allow the user to set the value to a non-empty string that is not a valid global date and time string expressed in UTC, though user agents may allow the user to set and view the time in another time zone and silently translate the time to and from the UTC time zone in the value. If the user agent provides a user interface for selecting a global date and time, then the value must be set to a valid global date and time string expressed in UTC representing the user's selection.

  • The format shown to the user is independent of the format used for form submission. Browsers are encouraged to use user interfaces that present dates and times according to the conventions of the user's preferred locale.

It seems to me that W3C allows datetime input to be in local format but requires the final value submitted by the form to be expressed in UTC format.


Solution

  • The only question you asked was:

    Does W3C requires UTC to be the default timezone for datetime input, or is Opera browser doing the right thing by fixing timezone as UTC?

    But as you pointed out:

    user agents may allow the user to set and view the time in another time zone

    So the answer to your question is that W3C does not require UTC for the input, but does allow it, so Opera would be doing the right thing either way.

    These kinds of ambiguous specifications are pretty silly. Actually, they are fairly counterproductive. I don't understand why they even bother if they're not going to actually define the required behavior.