Vega-lite: Support UTC Time

Created on 23 May 2015  ·  12Comments  ·  Source: vega/vega-lite

  • [ ] UTC TimeUnit
  • [ ] UTC Scale

    • Add utc to the schema and the docs

  • [ ] UTC DateTime Object

    • Simply add utc: boolean property

  • [ ] Add an example in scale.md that uses utc scale.
Enhancement

Most helpful comment

From the discussion with @kanitw, we try to analyze the design space related to UTC, which involves both input and output.

INPUT

There are two cases:
1) format:"auto". Normally it parses date in local time, but if the data follows ISO format, it parses data in UTC (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).

2) custom format:

  • local time use "date:format"
    utc time use "utc:format"

OUTPUT

From preliminary exploration, Zoe thinks that:

1) If the input is already read as UTC, using normal time scale and normal time expression for timeUnit, would show UTC values.

  • [x] verify with date that you know timestamp

2) If the input is read as local time, users may wanna use utc scale and utc time expression for timeUnit to show UTC values.

TODO

  • [x] test how Vega stores date (Date object or just timestamp)

    • [ ] If it's a timestamp, you might want to construct a dataset that contains data at a particular timestamp (e.g., 0)
  • [ ] Create an example data where time/utc scale type matters

  • [ ] Verify that when we use utc prefix for timeUnit expression, we should always use scaleType=“utc"

SYNTAX

A few alternatives to let VL correctly add “utc” prefix to timeUnit:

  • [ ] add utc prefix to timeUnit e.g., “yearmonth” => “utcyearmonth” for not timeUnit => “utc"
  • [x] scaleType==‘utc’ - then add utc prefix to everything

We definitely need the latter. Then should the former be automatically inferred from the scale type or do we include it as a part of timeUnit but throw an error for inconsistent state (if it needs to be consistent.)

All 12 comments

We should not use UTC for the output because dates are parsed using the current time zone. When we add a way to parse dates as UTC, then we should also output them as UTC.

Right now, nothing is parsed or shown in UTC.

We should add an option to parse and view in UTC but it's not urgent so I'll leave this.

Yes. Modulo some weird js behavior. See https://github.com/vega/datalib/issues/63

Seems like a major usability issue. Could this be as simple as offering the user a switch and using the .utc time scales in d3?

Actually I just checked, you can use utc as a scale type too, we just haven't updated the docs.

Actually I just checked, you can use utc as a scale type too, we just haven't updated the docs.

It's more than that. We also have to make sure that all the timeUnit stuff works with utc.

Actually I just checked, you can use utc as a scale type too, we just haven't updated the docs.

Like this? I'm getting strange results for the X axis. Not sure if this is what @domoritz meant.

Yeah, like that. We simply haven't tested it properly. UTC is a new feature that is currently not supported but implementing it should only require a few adjustments.

Yeah, that's mainly why we haven't added it in http://vega.github.io/vega-lite/docs/scale.html#type yet

We should add an option to parse and view in UTC but it's not urgent so I'll leave this.

Is there really an easy way to parse things in UTC? AFAIK the parse behavior depends on the input data and the specified parse format.

In any case, I think the option to output UTC correctly is extremely crucial.

This issue seems relevant: https://github.com/vega/vega/issues/741

From the discussion with @kanitw, we try to analyze the design space related to UTC, which involves both input and output.

INPUT

There are two cases:
1) format:"auto". Normally it parses date in local time, but if the data follows ISO format, it parses data in UTC (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).

2) custom format:

  • local time use "date:format"
    utc time use "utc:format"

OUTPUT

From preliminary exploration, Zoe thinks that:

1) If the input is already read as UTC, using normal time scale and normal time expression for timeUnit, would show UTC values.

  • [x] verify with date that you know timestamp

2) If the input is read as local time, users may wanna use utc scale and utc time expression for timeUnit to show UTC values.

TODO

  • [x] test how Vega stores date (Date object or just timestamp)

    • [ ] If it's a timestamp, you might want to construct a dataset that contains data at a particular timestamp (e.g., 0)
  • [ ] Create an example data where time/utc scale type matters

  • [ ] Verify that when we use utc prefix for timeUnit expression, we should always use scaleType=“utc"

SYNTAX

A few alternatives to let VL correctly add “utc” prefix to timeUnit:

  • [ ] add utc prefix to timeUnit e.g., “yearmonth” => “utcyearmonth” for not timeUnit => “utc"
  • [x] scaleType==‘utc’ - then add utc prefix to everything

We definitely need the latter. Then should the former be automatically inferred from the scale type or do we include it as a part of timeUnit but throw an error for inconsistent state (if it needs to be consistent.)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kanitw picture kanitw  ·  3Comments

ijlyttle picture ijlyttle  ·  3Comments

paintdog picture paintdog  ·  4Comments

iliatimofeev picture iliatimofeev  ·  3Comments

ijlyttle picture ijlyttle  ·  4Comments