Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

input[time] Needs default date option. #9603

Open
SimeonC opened this issue Oct 14, 2014 · 4 comments
Open

input[time] Needs default date option. #9603

SimeonC opened this issue Oct 14, 2014 · 4 comments

Comments

@SimeonC
Copy link

SimeonC commented Oct 14, 2014

Currently the date value of an input[time] field defaults to 1970, which isn't terribly useful.
Would it be possible to have an optional attribute or ng-model-options value to allow us to set the date of the new time?

Example: Enter in 12:12 am in an input[time] directive, the date is set to 1970-01-01 00:12:00 +1300

Desired Functionality: Enter in 12:12 am in an input[time] with default date set to today, date is set to 2014-10-14 00:12:00 +1300

@btford
Copy link
Contributor

btford commented Oct 14, 2014

Seems more appropriate to set the "default" from the model-side (in the controller)

@btford btford added this to the Backlog milestone Oct 14, 2014
@SimeonC
Copy link
Author

SimeonC commented Oct 14, 2014

The problem with that is that the required flags won't work, also it's misleading in terms of UX as the field won't show up blank meaning it's difficult to display that there is no input and they should fill something in. Currently I'm working around this with a custom $parser on the model.

@jimmywarting
Copy link
Contributor

Have also thought about this...
Say you would have this:

// The day baby was born
$scope.babyBorn = new Date("2014-07-20T23:11:44");

<input type="datetime-local" ng-model="babyBorn">
<input type="time" ng-model="babyBorn">

The date may be accurate most of the time but the time isn't. So you would only show the time input.
User clears the time field because it's inaccurate (this will also make the model invalid and won't show the day any longer)

This issue was something that I had in mind when i created #6666 (Change datetime individual) but this wasn't specified in my description. Guessing I didn't know how I wanted it to behave then

My guessing is that there is a variant of desirable behavior for this those making it more suitable for the controller or a custom parser. but doing something about this would perhaps be desirable.

When the model is null or undefined

  • Setting a empty time field would make the default day to now
  • Setting a empty time field would make the default day to 1970-01-01 (best for working with timestamp, cron jobs & setTimeout)

When the model has a Date Object:

  • Clearing the time field would make the model invalid and start from 1970-01-01 when entering new numbers
  • Clearing the time field would only set it to midnight and not change the day

and possible some other use cases i forgot about when i created #6666

@jpuffer
Copy link

jpuffer commented Aug 22, 2016

Blindly assigning the date of Jan 1 1970 screws up and time zone offset, especially in zones that use Daylight Savings Time.

In my scenario, the user enters a time and there is helper text to show that time in UTC. It calculates that via the browser's native getTimezoneOffset() method - which is wrong half of the year if Jan 1 is used, because of the DST offset.

A flag to use the current date (instead of Jan 1 1970) for model binding seems to be the most reasonable, so there isn't a need to set a default value in the model. In many cases there ought to be no value in the model until the user inputs text in the form.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants