Open zbraniecki opened 9 years ago
There a several similar preferences that the API should either expose now, or be able to add in the future - timezone selection manual/automatic, showing/hiding dayperiod (am/pm) for 12h clock, showing/hiding seconds etc.
I propose the following API:
[NoInterfaceObject, Exposed=(Window,Worker)]
interface NavigatorSystemHour12 {
readonly attribute boolean systemHour12;
};
Navigator implements NavigatorSystemHour12;
WorkerNavigator implements NavigatorSystemHour12;
Also, applications which want to customize the time display according to the OS defaults, and they need to be notified when the OS defaults change in order to have a chance to update their UI. Therefore, I think we need to queue a task to fire a simple event named systemhour12change
event at the Window
or WorkerGlobalScope
object, similar to the languagechange
event, and only return the updated value from systemHour12
when the task begins to execute.
@ehsan - If we decide to add another time formatting setting API like this in the future (let's say, ampm display), will we want navigator.dayperiodStyle
and a new event dayperiodstylechange
on window
?
I'm wondering if it would make sense to plan the API to handle more than one setting (and get one event for all time/date formatting options)?
@ehsan - If we decide to add another time formatting setting API like this in the future (let's say, ampm display), will we want navigator.dayperiodStyle and a new event dayperiodstylechange on window?
What is "ampm display"? If you mean displaying AM/PM next to times, is that not the same as hour12?
I'm wondering if it would make sense to plan the API to handle more than one setting (and get one event for all time/date formatting options)?
I usually prefer specific solutions to specific problems. I don't think we should try to create anything generic here, all we're talking about is a boolean flag. :)
What is the benefit of the "system" prefix? Also, if we return "boolean" we cannot return "undefined", which appears to be necessary per the referenced bug. I think we'll need to use "any" or maybe "(boolean or undefined)" but I don't think that's allowed. @heycam?
What is "ampm display"? If you mean displaying AM/PM next to times, is that not the same as hour12?
No. hour12
is specifying which hour formatting user wants - 12h or 24h. If the user decides to use 12h, he can further choose to display am/pm
token or not.
See MacOS settings screenshot for an example: http://imgur.com/FxosgeL
It means that the same time (14:23) can be formatted as:
So, my thought is that there seem to be a set of options that user specifies in his settings app that should be exposed, read-only, to the web developer. Examples (from macos):
I don't see a need to specify that now, but if we standardize it, I'd be worried about specifying each one of them separately on navigator
until we get to the point where we need a new API to collect them and deprecate the previous ones.
But you guys have way more experience so I trust you when you say that a property on navigator
is a good choice. It's definitely easy for us since that's what we use right now in FxOS :)
We wouldn't add a new API just to collect stuff from elsewhere.
ok, sounds good!
This seems out of scope for HTML. It is rather part of the ES internationalization API, I would think.
Otherwise, I'd expect HTML to grow a huge family of APIs for exposing current system locale settings.
E.g. in .NET their equivalent of the internationalization API contains a CultureInfo.CurrentCulture static value which contains all the locale settings currently present. You then pass these CultureInfo objects to various formatting methods (DateTimeOffset.ToString, etc.).
I really think only the ES internationalization working group will have the expertise to develop the correct system here.
@domenic the ES Internationalization API doesn't expose system settings. navigator
, however, does. E.g., language, languages, OS, online, do not track.
Sure. But I think the ES API should. It's useful in more than just the browser.
Alternately, the 402 group could work on a separate spec extending navigator.
Either way, out of scope for HTML.
What is the benefit of the "system" prefix?
It makes the name different to hour12
which is used in the Internationalization API (but I don't feel strongly about the name.)
Also, if we return "boolean" we cannot return "undefined", which appears to be necessary per the referenced bug. I think we'll need to use "any" or maybe "(boolean or undefined)" but I don't think that's allowed.
That is true. We can also return an enum with three values if the above is not an option.
@caridy - what do you think? Should we take this into Ecma 402?
I feel like there are three ways we can slice it: 1) It's a standalone variable that should be available to the web developer 2) It's part of the Intl Time/Format data and as such should be part of Ecma 402 3) It's part of the "User preferences" data and as such should be part of HTML/DOM.
@domenic How would an ES level solution notify the application when the system settings change?
yes, we can take part of this into 402, open the issues in the ecma 402 repo.
@caridy - do you have an answer to the event question @ehsan ? I'm not sure if it should be 402 or here.
@domenic I really don't see why this would be out of scope, but navigator.languages
(and corresponding event) is not.
Also, if we return "boolean" we cannot return "undefined", which appears to be necessary per the referenced bug. I think we'll need to use "any" or maybe "(boolean or undefined)" but I don't think that's allowed. @heycam?
Right, the only way currently to do that is to use "any". (It's on my todo list to add an "undefined" IDL type to make this easier.)
@annevk Let me clarify a bit. This isn't necessarily out of scope, in that HTML is the kitchen sink and we can justifiably say that anything is in its scope.
However, the OP and the couple of posts following it make it clear that this is a pretty large new undertaking, which ideally integrates deeply with the work done in 402, e.g. allowing passing of this "culture info" or "locale data" object to 402's toLocale{String,DateString,TimeString,LowerCase,UpperCase} overloads or to its Intl.{Collator,DateTimeFormat,NumberFormat} constructors. It would need to integrate with 402's existing notion of locale data, for example. And it would need to tease out the relationship between intrinsic locale data, derived directly from a language tag, and user preferences. (Possibly the former sets defaults that can be overridden by the latter? Possibly user preferences create a new locale, that doesn't have a language tag? Not my area of expertise, but I am sure these problems have been solved before...)
Thus, I think an undertaking like this should ideally be developed in tandem with those 402 APIs for best integration, and maintained by a group that has good familiarity with those APIs and can work alongside those editors (or maybe that group should just be the 402 editors). Making it the responsibility of the HTML editors seems like a bad idea, especially since it doesn't gain anything compared to a separate spec. There are no deep hooks into the HTML spec needed; this would be a fine extension spec. Maybe even navigator.languages
can be moved there, or subsumed into the new model.
as for events, this is tricky for fee reasons:
However, the OP and the couple of posts following it make it clear that this is a pretty large new undertaking.
It really isn't. I am quite puzzled by why you think that.
It really isn't. I am quite puzzled by why you think that.
Here is what the equivalent work looked like for .NET:
I appreciate the OP contained only an incomplete version of DateTimeFormatInfo, i.e. hour12. But then in the second post onward it started expanding to dayperiodstyle---which already mismatches 402, so we're having a group coordination problem here. Other 402 options that might change due to user settings include timeZone and the various formatting parameters, or even the calendar. hourNo0 also is treated as similar to hour12 in 402, so I am not sure why hour12 is included but hourNo0 is not.
If this is going to be an incompletely-done solution, I don't want it in HTML; we should have higher standards for this spec. If it's going to be a completely done solution with good 402 integration, then I think it needs domain expertise outside of what HTML offers. The speed to which people have jumped to nitty-gritty IDL details, and your incomprehension of how large this problem space is, are worrying...
As an idea to get things started, something that integrates better with 402 might be something like Intl.DateTimeFormat.current
or navigator.currentDateTimeFormat
that reflects the user's current choices of date-time formatting. You'd then use Intl.DateTimeFormat
's equivalent for AM/PM style instead of inventing dayperiodstyle
.
I don't fully understand what would be Intl.DateTimeFormat.current
, but if it's a collection of user preferences then it should not belong to Intl.DateTimeFormat
. We'd need sth like Intl.EnvironmentSettings
, which is ok except that Intl doesn't have any prior experience with event handling and we rely on HTML's navigator.languagechange
to reformat when languages change.
I would expect similar navigator.timeformatchange
rather than adding EventHandler to Intl.
Does it make sense?
Wrt. scope. Currently all we need is a single true/false/undefined variable. I wanted to plan it ahead for additional data, but @ehsan suggested to focus on the task at hand which I agree with. So I see it as a single variable and a single event when the variable changes. HTML seems better suited IMO.
I don't fully understand what would be Intl.DateTimeFormat.current
Because Intl.DateTimeFormat instances are what you use to format datetimes, you should have one representing the user's current preferences for how to format datetimes.
You can use navigator
as a storage place, without using HTML as a spec.
@domenic are the maintainers of 402 interested in extending navigator
? I'm happy to add a couple of properties and events as needed over time to HTML. Not a big deal. I don't really want to say out-of-scope when the alternative can take a long time.
@annevk no, we are not interested on navigator
, we only care about the abstract operations to access the default intl values (locales, etc), and potentially expose them to the runtime. One common practice today is that developers will create an instance of Intl.NumberFormat()
just to access locale
from the resolvedOptions
of the instance. We want to provide low level APIs to do the same without having to create an instance.
Aside from that, settings like hour12
are inferred via locales, changing that to use a system setting will imply that the server side can't negotiate all those settings. I'm concern about the navigator's specific properties that can affect the way Intl works because we don't have navigators in all runtimes (e.g.: node), and also the fact that universal/isomorphic code will not produce the same results since we don't have the ability to pick all the user's settings from a request.
@annevk I really do not like the framing of this as "a couple of properties and events". It should integrate better with 402's primitives, e.g. as in https://github.com/whatwg/html/issues/171#issuecomment-142334573.
Even if the 402 group is not interested in extending navigator, I'd expect their help and sign-off on any design of this sort.
@zbraniecki is this still something you want to pursue in the HTML Standard?
I think we have come to "agreement" on the idea of using navigator.locales
(which is BC) and can contains locales with extensions, while all 402 primitives can digest extensions just fine.
Thanks, what does BC mean?
backward-compatible since it is a new member of navigator.
I see, so should we introduce these members in the HTML Standard or will something else introduce an extension of sorts? Anyone willing to provide a PR?
All operating systems allow user to select time format. Usually between 12h, 24h or follow automatic.
Firefox OS is currently providing
navigator.mozHour12
that can take true/false/undefined values and that nicely fits into Intl API:When "use default" is used,
mozHour
is undefined and Intl uses the defaulthour12
value for the given locale. IfmozHour
is specified to eithertrue
orfalse
, Intl API follows that.There's also an event associated with it:
timeformatchange
that is dipatched onwindow
.