question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UTC timeunits do not return UTC times in Vega-Lite 4.0

See original GitHub issue

In Vega-Lite 4.0, UTC timeunits return the same value as their non-UTC counterparts. This was not the case in Vega-Lite 3.X

Here is a simple spec that demonstrates this:

{
  "data": {"values": [{"t": "2020-01-01T12:00:00-08:00"}]},
  "mark": "point",
  "encoding": {
    "x": {"type": "temporal", "field": "t", "timeUnit": "hours", "title": "hours"},
    "y": {"type": "temporal", "field": "t", "timeUnit": "utchours", "title": "utchours"}
  }
}

I viewed this on a computer set to the US/Pacific timezone.

With Vega-Lite 3.4.0 & Vega 5.9.1, I see the expected result: the local hour is 12, and the UTC hour is 20. visualization - 2020-01-20T062720 626

With Vega-Lite 4.0.2 & Vega 5.9.1, the result has changed: the UTC timeUnit is the same as the local timeUnit: visualization - 2020-01-20T062714 928

This seems to be the case not just for utchours but for every UTC timeUnit Vega-Lite supports: each UTC timeUnit returns identical timestamps as its non-UTC counterpart.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
haldenlcommented, Jan 25, 2020

@SyntaxRules It looks like the issue has to do with the inconsistent parsing of the Date object (see here). In the spec, data is given in year-month-day format, which is interpreted in UTC. The datetime objects provided as tick values are interpreted in local time. If we switch to the same formatting:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {
    "values": [
      {"d": "2020-01-01"},
      {"d": "2020-01-15"},
      {"d": "2020-02-01"},
      {"d": "2020-02-15"},
      {"d": "2020-03-01"}
    ]
  },
  "mark": "rule",
  "width": 600,
  "height": 100,
  "encoding": {
    "x": {
      "scale": {"domain": ["2019-12-15", "2020-04-01"]},
      "axis": {
        "format": "%Y-%m-%d",
        "orient": "bottom",
        "title": "CY",
        "values": ["2019-12-01", "2020-01-01", "2020-02-01", "2020-03-01"]
      },
      "field": "d",
      "type": "temporal",
      "timeUnit": "utcyearmonthdate"
    }
  }
}

The output is as expected (on the fix branch). I wonder if something changed with datetime usage between 3.2.1 and 4.0. Will investigate.

image

1reaction
domoritzcommented, Jan 23, 2020

@SyntaxRules After the fix

image

This seems right since the dates are parsed as local, right?

Screen Shot 2020-01-22 at 20 54 24
Read more comments on GitHub >

github_iconTop Results From Across the Web

UTC timeunits do not return UTC times in Vega-Lite 4.0 -
In Vega-Lite 4.0, UTC timeunits return the same value as their non-UTC counterparts. This was not the case in Vega-Lite 3.X.
Read more >
Time Unit | Vega-Lite
To output data in UTC time, we can specify either a UTC time unit or scale: UTC time unit when input data is...
Read more >
Date parsing and when to use utc/TimeUnits in Vega Lite?
Dates are always displayed in local time, unless otherwise specified (e.g. by passing "utc": true to a timeUnit); Dates are parsed using ...
Read more >
Graphics.Vega.VegaLite - Hackage
It was originally based on version 2.2.1 but it has been updated to match later versions. This module allows users to create a...
Read more >
Interaction / UW Interactive Data Lab - Observable
CC BY 4.0 ... If no interval is defined (the selection is empty), Vega-Lite ... as time 0 , and thus map to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found