{"action":"created","issue":{"url":"https://api.github.com/repos/basho/riak-python-client/issues/483","repository_url":"https://api.github.com/repos/basho/riak-python-client","labels_url":"https://api.github.com/repos/basho/riak-python-client/issues/483/labels{/name}","comments_url":"https://api.github.com/repos/basho/riak-python-client/issues/483/comments","events_url":"https://api.github.com/repos/basho/riak-python-client/issues/483/events","html_url":"https://github.com/basho/riak-python-client/issues/483","id":160960046,"number":483,"title":"Timezone conversion ambiguity [JIRA: CLIENTS-897]","user":{"login":"korry8911","id":10292569,"avatar_url":"https://avatars.githubusercontent.com/u/10292569?v=3","gravatar_id":"","url":"https://api.github.com/users/korry8911","html_url":"https://github.com/korry8911","followers_url":"https://api.github.com/users/korry8911/followers","following_url":"https://api.github.com/users/korry8911/following{/other_user}","gists_url":"https://api.github.com/users/korry8911/gists{/gist_id}","starred_url":"https://api.github.com/users/korry8911/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/korry8911/subscriptions","organizations_url":"https://api.github.com/users/korry8911/orgs","repos_url":"https://api.github.com/users/korry8911/repos","events_url":"https://api.github.com/users/korry8911/events{/privacy}","received_events_url":"https://api.github.com/users/korry8911/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/basho/riak-python-client/labels/JIRA:%20To%20Do","name":"JIRA: To Do","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-17T19:36:03Z","updated_at":"2016-06-17T20:16:08Z","closed_at":null,"body":"I am writing the following to Riak TS:\r\n\r\n`['field1_val', 'field2_val', datetime.datetime(2015, 1, 1, 12, 0, 0), 0]`\r\n\r\nWhen reading this item from Riak TS I get back the following:\r\n\r\n`['field1_val', 'field2_val', 1420142400000, 0]`\r\n\r\nConverting 1420142400000 to datetime I get:\r\n\r\n`datetime.datetime.utcfromtimestamp(1420142400) `\r\n`datetime.datetime(2015, 1, 1, 20, 0)`\r\n\r\nNow if I try to see the unix epoch time in milliseconds for `datetime.datetime(2015, 1, 1, 12, 0, 0)`, I get:\r\n\r\n`1420113600000`\r\n\r\nI am using this function to convert to unix epoch milliseconds:\r\n```\r\ndef unix_time_millis(dt):\r\n    td = dt - datetime.datetime.utcfromtimestamp(0)\r\n    return int(td.total_seconds() * 1000.0)\r\n```\r\n\r\nSomewhere there is a timezone issue. Not sure where.\r\n\r\nFor completeness, this is my actually code snippet:\r\n\r\n```\r\ntest_row_in = ['field1_val', 'field2_val', datetime.datetime(2015, 1, 1, 12, 0, 0), 0]\r\n    test_rdd = spark_context.parallelize([test_row_in])\r\n    print(test_rdd.collect())\r\n    test_df = test_rdd.toDF(['field1', 'field2', 'datetime', 'data'])\r\n\r\n    one_second = datetime.timedelta(seconds=1)\r\n    one_day = datetime.timedelta(days=1)\r\n    start = datetime.datetime(2015, 1, 1, 12, 0, 0) - one_day\r\n    end = datetime.datetime(2015, 1, 1, 12, 0, 0) + one_day\r\n\r\n    fmt =   \"\"\"\r\n                select * from {table_name}\r\n                where datetime >= {start_date}\r\n                AND datetime <=  {end_date}\r\n                AND field1 = '{field1}'\r\n                AND field2 = '{field2}'          \r\n            \"\"\"\r\n    query = fmt.format(table_name=riak_ts_table_name, start_date=unix_time_millis(start), end_date=unix_time_millis(end), field1='field1_val', field2='field2_val')\r\n\r\n\r\n    assert retry_func_with_timeout(func=test_df.write.format('org.apache.spark.sql.riak').mode('Append').save,\r\n                                   times=10, \r\n                                   timeout=30, \r\n                                   signal=True, \r\n                                   args=[riak_ts_table_name], \r\n                                   use_condition=False, \r\n                                   condition_func=None, \r\n                                   condition_val=None,\r\n                                   test_func=None,\r\n                                   test_args=None\r\n                                   )[0] == True\r\n\r\n\r\n\r\n    assert retry_func_with_timeout(func=riak_ts_table.query, \r\n                                   times=10, \r\n                                   timeout=3, \r\n                                   signal=True, \r\n                                   args=[query], \r\n                                   use_condition=True, \r\n                                   condition_func=ts_query_condition, \r\n                                   condition_val=test_rdd.collect(),\r\n                                   test_func=None,\r\n                                   test_args=None\r\n                                   )[0] == True\r\n```\r\n\r\nI am running riak (2.5.3), on OSX El Capitan 10.11.3 (15D21)"},"comment":{"url":"https://api.github.com/repos/basho/riak-python-client/issues/comments/226870887","html_url":"https://github.com/basho/riak-python-client/issues/483#issuecomment-226870887","issue_url":"https://api.github.com/repos/basho/riak-python-client/issues/483","id":226870887,"user":{"login":"lukebakken","id":514926,"avatar_url":"https://avatars.githubusercontent.com/u/514926?v=3","gravatar_id":"","url":"https://api.github.com/users/lukebakken","html_url":"https://github.com/lukebakken","followers_url":"https://api.github.com/users/lukebakken/followers","following_url":"https://api.github.com/users/lukebakken/following{/other_user}","gists_url":"https://api.github.com/users/lukebakken/gists{/gist_id}","starred_url":"https://api.github.com/users/lukebakken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukebakken/subscriptions","organizations_url":"https://api.github.com/users/lukebakken/orgs","repos_url":"https://api.github.com/users/lukebakken/repos","events_url":"https://api.github.com/users/lukebakken/events{/privacy}","received_events_url":"https://api.github.com/users/lukebakken/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T20:16:08Z","updated_at":"2016-06-17T20:16:08Z","body":"* \"when reading this item\" - how are you reading that particular row back?\r\n\r\n* Try using the function in `riak.util` instead of your own:\r\n\r\n```python\r\nfrom riak.util import unix_time_millis\r\n```\r\n\r\n"}}
{"actor":{"display_login":"lukebakken"}}