user2879041
user2879041

Reputation: 1095

HTML5 input type time, when 00:00:00 value isn't completely there (Chrome)

So I have the following html input like so

<input id="time_in" type="time" step="1" name="duration">

And when I set the value in browser to "00:00:00" all seems good.

But then you jump into the console (or submit the form, etc.) the value is truncated to "00:00"

i.e. jquery

$("#time_in")[0].value == "00:00"

or plain js

document.getElementById("time_in").value == "00:00"

My question is what gives? Is this supposed to be the behavior? This doesn't seem correct to me, does anyone know if I'm not setting an attribute or doing something non-standard?

edit:

if it makes any difference this is only with "00:00:00", when you set it to "00:00:01" it's correctly set and you can

document.getElementById("time_in").value == "00:00:01"

Upvotes: 2

Views: 4221

Answers (1)

rink.attendant.6
rink.attendant.6

Reputation: 46208

This is standard-compliant behaviour, but so is 00:00:00.

In the HTML5 specification:

The value attribute, if specified and not empty, must have a value that is a valid time string.

Where a "valid time string" is:

A string is a valid time string representing an hour hour, a minute minute, and a second second if it consists of the following components in the given order:

  1. Two ASCII digits, representing hour, in the range 0 ≤ hour ≤ 23
  2. A ":" (U+003A) character
  3. Two ASCII digits, representing minute, in the range 0 ≤ minute ≤ 59
  4. Optionally (required if second is non-zero):
    1. A ":" (U+003A) character
    2. Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59
    3. Optionally (required if second is not an integer):
      1. A 002E FULL STOP character (.)
      2. One, two, or three ASCII digits, representing the fractional part of second

Note: The second component cannot be 60 or 61; leap seconds cannot be represented.

Therefore, the last bit after the minute (including the colon) is optional if the second is zero, but not prohibited.

Upvotes: 3

Related Questions