PSA: Better Time types available in Blink

57 views
Skip to first unread message

Majid Valipour

unread,
Dec 15, 2016, 10:47:20 AM12/15/16
to blink-dev
We have now access to base time types* in Blink. These types can replace most, if not all, existing usage of double/uint64_t to represent time values and duration in Blink. I strongly recommend doing so and leverage type system to help prevent easy to make but hard to detect bugs due to incorrect conversion and information loss issues. This also improves documentation of clock type and resolution for time values everywhere. 

I have written a document to help you with such a conversion. Feel free to reach out if you have any question or concerns.

* There are in WTF namespace with a slightly more limited API compared to base/time. 

Thanks
Majid

TAMURA, Kent

unread,
Dec 16, 2016, 2:32:04 AM12/16/16
to Majid Valipour, blink-dev
base::Time can't represent 1601-01-01 00:00:00 UTC because it's the null value, right?  I confirmed Time::ToJsTime() didn't work for this specific time.
Date/time input types need to handle it correctly.

--
TAMURA Kent
Software Engineer, Google


Elliott Sprehn

unread,
Dec 16, 2016, 2:33:50 AM12/16/16
to TAMURA, Kent, blink-dev, Majid Valipour
How did we represent that when using doubles? Can we add a bit to the blink time type for it or add it to base?

TAMURA, Kent

unread,
Dec 16, 2016, 4:25:32 AM12/16/16
to Elliott Sprehn, blink-dev, Majid Valipour
It's just -11,644,473,600,000.0 in double.  It is converted to 0 when it's stored in base::TimeBase::us_, and TimeBase::is_null() returns true.

Only conversion functions use TimeBase::is_null() in base/time/*.  It might be possible to add Time::ToEcmaTime() and FromEcmaTime() so that they don't check is_null(), and add comments that "Do not use is_null() for this!"

Note: ECMAScript asks to support year -271,821 to year 275,760 in Date object, and Date also has invalid state. V8 represents a Date object by a single double, and invalid state is NaN in double.  Date/time input types use the same representation, however the lower limit is 0001-01-01.

Majid Valipour

unread,
Dec 16, 2016, 8:41:10 AM12/16/16
to TAMURA, Kent, Elliott Sprehn, blink-dev, Majid Valipour

Only conversion functions use TimeBase::is_null() in base/time/*.  It might be possible to add Time::ToEcmaTime() and FromEcmaTime() so that they don't check is_null(), and add comments that "Do not use is_null() for this!"
 
The |is_null()| check in that conversion function seems sketchy. I will send a patch to fix it in base. Note that To/FromJsTime are not yet exposed in WTF interface anyways.

Majid

Yutaka Hirano

unread,
Apr 27, 2017, 5:50:03 AM4/27/17
to Majid Valipour, TAMURA, Kent, Elliott Sprehn, blink-dev
I found that I could use base::Time in platform/ but I couldn't use it in public/platform. Is it OK to add +base/time in public/platform/DEPS?

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

Jeremy Roman

unread,
Apr 27, 2017, 10:37:26 AM4/27/17
to Yutaka Hirano, Majid Valipour, TAMURA, Kent, Elliott Sprehn, blink-dev
Personally, I'd be okay with adding base/time/time.h to public/platform/DEPS. It's rather self-contained. We'd probably want to also extend wtf/Time.h to allow the WTF types to be more easily converted to/from the base types for passing between Chromium and Blink.

Other people might disagree; I know there has been reticence to pass base types across the Blink API.
Reply all
Reply to author
Forward
0 new messages