[OPEN-ILS-DEV] Solidifying / Simplifying Angular date/time display
Bill Erickson
berickxx at gmail.com
Thu Aug 22 17:49:38 EDT 2019
Hi All,
This is an extension of my previous email "Native browser date / time
selectors in Angular".
Based on discussion from that thread, from bug #1834662, and me poking
around the JS Intl.DateTimeFormat API, I would like to propose a way to
streamline and simplify how we handle locale-friendly dates and times in
the Angular application.
Assumptions:
1. We need to support timezone database names as listed in
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones (e.g.
Europe/Prague, America/Vancouver,
etc.) since this is the documented basis for "lib.timezone" library setting.
2. It is reasonable to assume dates generated by the web browser (via
Intl.DateTimeFormat API) for a given locale are understandable by users in
said locale and that we don't need to allow users to specify custom date
formats. (See examples below)
3. Browsers will be configured to the user's desired locale.
4. Short / numeric dates and times are sufficient to convey the needed
information to users. In other words, for en-US, "10/24/2019" is as good
as (or better than) "Thursday, October 24 2019" (or similar variations).
For example, here's a list numeric date+time strings generated the
Intl.DateTimeFormat for a variety of locales:
cs-CZ ==> 22. 8. 2019 16:45
en-CA ==> 2019-08-22, 4:45 p.m.
fi-FI ==> 22.8.2019 klo 16.45
fr-CA ==> 2019-08-22 16 h 45
hy-AM ==> 2019-8-22 16:45
es-ES ==> 22/8/2019 16:45
ru-RU ==> 22.08.2019, 16:45
en-US ==> 8/22/2019, 4:45 PM
5. We need exactly 3 date/time flavors: date only, time only, and date +
time.
6. For time displays, we need hours and minutes, but not seconds.
Assuming the above, here's my proposal.
1. Migrate to native browser date and time inputs. With these, we get
exactly 1 type of value from each widget (YYYY-MM-DD, hh:mm:ss) so we never
have to parse locale-variant date strings. (No MomentJS dependency)
2. Avoid using Angular DatePipe. It does not support the long-form
timezone names we use (https://github.com/angular/angular/issues/20225).
3. Teach our FormatService to use Intl.DateTimeFormat when generating date
strings. It will support options to produce date, time, or date + time,
using the 'short' formats noted above, plus optional timezone and locale
parameters.
4. Remove the date / time format library settings once fully migrated to
Angular. All that's needed is locale and time zone.
As is often the case, I write code before I write emails, so I've mostly
implemented everything I've discussed here -- minus an <eg-time-select/>
widget -- in the code for https://bugs.launchpad.net/evergreen/+bug/1840782
It also includes a sandbox date/time generator tool where you can pick
locales and time zones and see what it produces.
I can say with confidence what I'm describing works in Chrome and Firefox,
so the question boils down to whether the assumptions I've laid out are
reasonable.
Thoughts appreciated,
Thanks
-b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libmail.georgialibraries.org/pipermail/open-ils-dev/attachments/20190822/6d8cfbab/attachment.html>
More information about the Open-ils-dev
mailing list