[PYTHON] The specifications of pytz have changed

The Japanese timezone format has changed in pytz version 2017.2 released on 2017-03-30 (bug ??)

The latest version (version 2017.2) of the python timezone-related library managed by Stuart Bishop has strange behavior, so I will share it. http://pythonhosted.org/pytz/#localized-times-and-date-arithmetic

What has changed

until now

In [1]: import pytz

In [2]: pytz.__version__
Out[2]: '2016.10'

In [3]: pytz.timezone('Asia/Tokyo')
Out[3]: <DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>

newest version

In [1]: import pytz

In [2]: pytz.__version__
Out[2]: '2017.2'

In [3]: pytz.timezone('Asia/Tokyo')
Out[3]: <DstTzInfo 'Asia/Tokyo' LMT+9:19:00 STD>

I couldn't find any comments from the author, so there is a possibility of a bug.

Impact of this

Due to this, if UTC-> JST is converted by reading from DB, it may be off by 19 minutes. It's buggy because there are some processes that just shift and don't shift. The processing that shifts and the processing that does not shift are summarized below.

Processing to which JST is granted as before

In [8]: tz = pytz.timezone('Asia/Tokyo')

In [10]: tz.localize(datetime.datetime.now())
Out[10]: datetime.datetime(2017, 4, 5, 9, 24, 56, 215625, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)

In [11]: datetime.datetime.now(tz=pytz.utc).astimezone(tz)
Out[11]: datetime.datetime(2017, 4, 5, 18, 27, 33, 912014, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)

Processing that gives the time shifted by 19 minutes of LMT as displayed by tzinfo

In [9]: datetime.datetime.now().replace(tzinfo=tz)
Out[9]: datetime.datetime(2017, 4, 5, 9, 24, 45, 694185, tzinfo=<DstTzInfo 'Asia/Tokyo' LMT+9:19:00 STD>)

When I tried it at hand, JST is properly assigned in non-destructive processing such as tz.localize, datetime.astimezone (tz). It is known that JST does not work and it shifts by 19 minutes when using the code that forcibly assigns timezone with datetime.replace (tz).

Other

Finally (main subject)

  1. Those who know how to get the JST timezone as before ――Please help !! I would appreciate it if you could let me know in the comments !!
  2. Also, if you are using datetime.replace (tzinfo = tz) without knowing this ――It's dangerous, so please fix it !! Your clock is off by 19 minutes !!
  3. (Since the time zone is critical, I would like you to publish it in Python official, not in a library like pytz that you manage individually.) --In Python3, there seems to be datetime.timezone, so I wonder if it is better to move to it ...

Recommended Posts

The specifications of pytz have changed
Note that the Pandas loc specifications have changed
The usage of TensorBoard has changed slightly
The beginning of cif2cell
The meaning of self
the zen of Python
The story of sys.path.append ()
I checked the output specifications of PyTorch's Bidirectional LSTM
Note that the latest link of ius has changed
The attitude that programmers should have (The Zen of Python)
Revenge of the Types: Revenge of types
I just changed the sample source of Python a little.
Have the equation graph of the linear function drawn in Python
Align the version of chromedriver_binary
Scraping the result of "Schedule-kun"
10. Counting the number of lines
The story of building Zabbix 4.4
Towards the retirement of Python2
[Apache] The story of prefork
Compare the fonts of jupyter-themes
About the ease of Python
Get the number of digits
Explain the code of Tensorflow_in_ROS
Reuse the results of clustering
GoPiGo3 of the old man
Calculate the number of changes
Change the theme of Jupyter
The popularity of programming languages
Change the style of matplotlib
Visualize the orbit of Hayabusa2
About the components of Luigi
Connected components of the graph
Filter the output of tracemalloc
About the features of Python
Simulation of the contents of the wallet
The Power of Pandas: Python