[whatwg] Time Parsing
Lachlan Hunt
lachlan.hunt at lachy.id.au
Mon Mar 28 08:06:57 PDT 2011
Hi,
The algorithm to parse a time component contains a bug.
When parsing the seconds, the spec states:
"Collect a sequence of characters that are either characters in the
range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) or U+002E FULL
STOP characters. If the collected sequence has more than one U+002E
FULL STOP characters, or if the last character in the sequence is a
U+002E FULL STOP character, then fail. Otherwise, let the collected
string be second instead of its previous value."
This is incorrect because it allows the second component to contain more
than 2 digits before the decimal point. i.e. "00:00:012.345" would
parsed without error.
The algorithm should instead state to look for 2 digits representing the
seconds, then check if there's a decimal point, and then check for the
fractional part of the second.
This should also only allow up to 3 digits representing milliseconds.
If there are 4 or more digits (microseconds or beyond), the spec should
state that the remaining digits should be truncated.
e.g. "00:00:00.9999"
Technically, that would be 999,900µs, but it needs to be rounded down to
999ms, not rounded up to 1s.
http://whatwg.org/C#parse-a-time-component
--
Lachlan Hunt - Opera Software
http://lachy.id.au/
http://www.opera.com/
More information about the whatwg
mailing list