arrow-py / arrow

🏹 Better dates & times for Python
https://arrow.readthedocs.io
Apache License 2.0
8.68k stars 670 forks source link

Migration guide for v1.0.0 #832

Open jadchaar opened 4 years ago

jadchaar commented 4 years ago

The v1.0.0 release of Arrow contains breaking changes, this migration guide outlines the changed APIs and functionality. Please visit #923 to discuss the changes and ask any questions.

  1. Python 2.7 and 3.5 are no longer supported.

  2. The .timestamp property has been removed to improve compatibility with datetime. Use .int_timestamp for the same results.

>>> arrow.utcnow().int_timestamp
1608640233
  1. Arrow has a new method timestamp() which wraps the datetime method of the same name.
>>> arrow.utcnow().timestamp()
1608641039.22176
  1. It's no longer possible to set the tzinfo property directly, instead use replace().
>>> dt=arrow.utcnow()
>>> dt.tzinfo=tz.gettz("US/Pacific")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> dt.replace(tzinfo=tz.gettz("US/Pacific"))
<Arrow [2020-12-22T16:03:29.630250-08:00]>
  1. arrow.get(None) now returns an error rather than current UTC.
>>> arrow.get(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chris/arrow/arrow/api.py", line 80, in get
    return _factory.get(*args, **kwargs)
  File "/home/chris/arrow/arrow/factory.py", line 228, in get
    raise TypeError("Cannot parse argument of type None.")
TypeError: Cannot parse argument of type None.
  1. The "X" token now returns a float rather than an int.
>>> arrow.utcnow().format("X")
'1614719652.85991'
Kaju-Bubanja commented 2 years ago

Also microseconds was renamed to microsecond in the arrow_object.replace() function. Probably also in other places