Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly support utc timeunits. #5780

Merged
merged 3 commits into from
Jan 29, 2020
Merged

fix: properly support utc timeunits. #5780

merged 3 commits into from
Jan 29, 2020

Conversation

haldenl
Copy link
Contributor

@haldenl haldenl commented Jan 21, 2020

Fixes #5777

@haldenl haldenl force-pushed the hl/5777 branch 2 times, most recently from ef5df5c to cf7c6d0 Compare January 21, 2020 05:26
Copy link
Member

@kanitw kanitw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you test with data to avoid double shifts?

Some of the code changes here look suspicious.

@domoritz
Copy link
Member

domoritz commented Jan 23, 2020

The docs say "Do not use UTC time unit and the UTC scale type at the same time since that will cause Vega-Lite to shift the output time twice."

But that doesn't seem to happen

{
  "data": {
    "values": [
      {"date": "Sun, 01 Jan 2012 23:00:00", "price": 150},
      {"date": "Sun, 02 Jan 2012 00:00:00", "price": 100},
      {"date": "Sun, 02 Jan 2012 01:00:00", "price": 170},
      {"date": "Sun, 02 Jan 2012 02:00:00", "price": 165},
      {"date": "Sun, 02 Jan 2012 03:00:00", "price": 200}
    ]
  },
  "mark": "line",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "timeUnit": "utcyearmonthdatehoursminutes",
      "scale": {"type": "utc"}
    },
    "y": {"field": "price", "type": "quantitative"}
  }
}

image

It doesn't seem to matter whether I set the scale type to utc or not

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {
    "values": [
      {"date": "2011-01-01T23:00:00.000+00:00"},
      {"date": "2011-01-02T00:00:00.000+00:00"},
      {"date": "2011-01-02T01:00:00.000+00:00"},
      {"date": "2011-01-02T02:00:00.000+00:00"},
      {"date": "2011-01-02T03:00:00.000+00:00"}
    ]
  },
  "mark": "line",
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "timeUnit": "utcyearmonthdatehoursminutes",
      "scale": {"type": "utc"},
      "title": null
    }
  }
}

I think that's nice but we should look into a) why this is different, b) change the docs, c) make sure that this is not a breaking change (we don't recommend using both scale type and time unit so this should be okay).

@domoritz
Copy link
Member

Here is a sanity check I did. Looks right.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {
    "values": [
      {"date": "2011-01-01T23:00:00.000+00:00"},
      {"date": "2011-01-02T00:00:00.000+00:00"},
      {"date": "2011-01-02T01:00:00.000+00:00"},
      {"date": "2011-01-02T02:00:00.000+00:00"},
      {"date": "2011-01-02T03:00:00.000+00:00"}
    ]
  },
  "mark": "point",
  "encoding": {
    "y": {
      "field": "date",
      "type": "ordinal",
      "timeUnit": "utcyearmonthdatehoursminutes",
      "title": null
    }
  }
}

image

@domoritz
Copy link
Member

Another experiment

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {
    "values": [
      {"t": "2011-01-02T00:00:00.000+00:00"},
      {"t": "2011-01-02T01:00:00.000+00:00"},
      {"t": "2011-01-02T02:00:00.000+00:00"},
      {"t": "2011-01-02T03:00:00.000+00:00"}
    ]
  },
  "mark": "point",
  "encoding": {
    "x": {
      "type": "temporal",
      "field": "t",
      "timeUnit": "hours",
      "title": "hours"
    },
    "y": {
      "type": "temporal",
      "field": "t",
      "timeUnit": "utchours",
      "title": "utchours"
    }
  }
}

image

@haldenl haldenl force-pushed the hl/5777 branch 4 times, most recently from 4cc5784 to f4671d1 Compare January 28, 2020 19:08
@haldenl
Copy link
Contributor Author

haldenl commented Jan 28, 2020

ready to merge

Copy link
Member

@kanitw kanitw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I exclude spec changes that are irrelevant to time unit.

I also made a bit updates to the examples to make it even easier to read.

Feel free to merge after all tests pass.

@haldenl
Copy link
Contributor Author

haldenl commented Jan 29, 2020

Thanks Ham!

@haldenl haldenl merged commit c0743d7 into master Jan 29, 2020
@haldenl haldenl deleted the hl/5777 branch January 29, 2020 18:28
@jakevdp
Copy link
Contributor

jakevdp commented Jan 29, 2020

Thanks for your work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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