Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

<input type="time" ng-bind-type="date"> too hard to use #1223

Open
@trinarytree

Description

@trinarytree

suppose you want a time picker:

<input type="time" id="t">

javascript exposes the value as follows

var t = document.getElementById('t');
t.value;       // a string
t.valueAsDate; // a Date, provided the user gave valid input, otherwise null

this Date object is actually a bit corrupt because it will have a
local timezone offset, yet the moment it represents is what the user picked,
if he were in UTC on the day of the epoch. e.g.
if the user enters 1:00, then
t.valueAsDate.getUTCHours() will be 1,
t.valueAsDate.getUTCMinutes() will be 0,
t.valueAsDate.getTime() will be 3600000.
t.valueAsDate.getTimezoneOffset() will be 480 (i'm in PDT).
i believe that the way this api is supposed to be used is that
you're supposed to pay attention to getUTCHours(), getUTCMinutes(), and getTime()
and ignore the rest.
i.e. i believe you are supposed to take this Date object and pretend
that it's really a time interval.

here's where angular comes in: suppose you use

<input type="time" id="t" ng-model="ctrl.t" ng-bind-type="date">

then ctrl.t will be bound to a UTC DateTime object, which is unwieldy
if your goal is to combine this time with some date, especially a local date. e.g.

dt = new DateTime(d.year, d.month, d.day, t.hour, t.minute, t.second, t.millisecond)

formatting t for display also requires pointless care.

since the javascript API seems to have been striving toward providing
a duration, but was limited, as javascript does not have a Duration class,
and since dart does have a Duration class, maybe it would be reasonable
to have a ng-bind-type of "duration" which would bind the ng-model to a Duration.
then your date-time picker code would look like this:

dt = d + t;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions