Dieterbe / anthracite

an event / change logging/managament app
Apache License 2.0
295 stars 33 forks source link

Date field and UTC #16

Closed torkelo closed 10 years ago

torkelo commented 10 years ago

I am having issues creating events from the UI. The date filed is not converted to UTC before it is being saved to elasticsearch. Makes it tricky to query elasticsearch with date ranges from different timezones when the date in elasticsearch is not in UTC.

Or am I missing something?

Dieterbe commented 10 years ago

I can't reproduce this. when i create an event for 5PM today, it gets stored in ES with date": "2014-08-06T21:00:00", i'm currently on EDT, i.e. UTC - 4, so 9PM - 4 = 5PM, the math works out. node that i'm using the vimeo_add plugin, we have the standard /events/add disabled, but it's practically the same handler, it also calls add_post_handler_default() .

also, looking at anthracite_web.py, the events_add_post /events/add POST http handler, calls add_post_handler_default() which calls add_post_validate_and_parse_base_attributes() which calls local_datepick_to_unix_timestamp().

torkelo commented 10 years ago

Strange.

When I enter a event in the ui: image

Then query elasticsearch it looks like it is stored in local time.

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "anthracite",
        "_type": "event",
        "_id": "7Xe4mADCRfi58PAQBDrG2A",
        "_score": 1,
        "_source": {
          "date": "2014-08-07T08:11:07",
          "desc": "test",
          "tags": [
            "prod"
          ]
        }
      }
    ]
  }
}

I would have expected a date like: "2014-08-07T06:11:07.304Z" since the date I enter in the date field is local UTC + 2 (as is anthracite server)

Dieterbe commented 10 years ago

can you open a python2 session on your terminal, and see how the local_datepick_to_unix_timestamp function behaves? i.e. the one at https://github.com/Dieterbe/anthracite/blob/master/anthracite-web.py#L187

looks like somehow python is not aware of your TZ, and assumes you're in UTC or something

torkelo commented 10 years ago

Hm... sorry. My docker image was somehow set to UTC timezone. Sorry for wasting your time.