Skip to content

Commit

Permalink
Stop auto-converting timezones to UTC and stripping timezone info (#1581
Browse files Browse the repository at this point in the history
)

* Added timezones future flag
* Don't convert datetimes to UTC or strip timezone info during JSON
encoding
  • Loading branch information
jonmmease authored May 27, 2019
1 parent 870de12 commit 106269e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions _plotly_future_/timezones.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('timezones')
1 change: 1 addition & 0 deletions _plotly_future_/v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
remove_deprecations,
v4_subplots,
orca_defaults,
timezones,
trace_uids,
)

14 changes: 12 additions & 2 deletions _plotly_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import json as _json
import sys
import re

import pytz
from _plotly_future_ import _future_flags

from _plotly_utils.optional_imports import get_module

Expand Down Expand Up @@ -104,7 +104,9 @@ def default(self, obj):
self.encode_as_sage,
self.encode_as_numpy,
self.encode_as_pandas,
self.encode_as_datetime,
(self.encode_as_datetime_v4
if 'timezones' in _future_flags
else self.encode_as_datetime),
self.encode_as_date,
self.encode_as_list, # because some values have `tolist` do last.
self.encode_as_decimal
Expand Down Expand Up @@ -170,6 +172,14 @@ def encode_as_numpy(obj):
else:
raise NotEncodable

@staticmethod
def encode_as_datetime_v4(obj):
"""Convert datetime objects to iso-format strings"""
try:
return obj.isoformat()
except AttributeError:
raise NotEncodable

@staticmethod
def encode_as_datetime(obj):
"""Attempt to convert to utc-iso time string using datetime methods."""
Expand Down

0 comments on commit 106269e

Please sign in to comment.