Skip to content

Commit

Permalink
Default to UTC for arrow.fromtimestamp() (arrow-py#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisfremen committed Sep 5, 2021
1 parent 246c55d commit 8ad64d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ def fromtimestamp(
the given timezone.
:param timestamp: an ``int`` or ``float`` timestamp, or a ``str`` that converts to either.
:param tzinfo: (optional) a ``tzinfo`` object. Defaults to local time.
:param tzinfo: (optional) a ``tzinfo`` object. Defaults to UTC time.
"""

if tzinfo is None:
tzinfo = dateutil_tz.tzlocal()
tzinfo = dateutil_tz.tzutc()
elif isinstance(tzinfo, str):
tzinfo = parser.TzinfoParser.parse(tzinfo)

Expand Down
7 changes: 3 additions & 4 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ def test_utcnow(self):

def test_fromtimestamp(self):

timestamp = time.time()

result = arrow.Arrow.fromtimestamp(timestamp)
timestamp = datetime.utcnow().timestamp()
result = arrow.Arrow.fromtimestamp(timestamp, tzinfo=tz.tzutc())
assert_datetime_equality(
result._datetime, datetime.now().replace(tzinfo=tz.tzlocal())
result._datetime, datetime.fromtimestamp(timestamp, tz=tz.tzutc())
)

result = arrow.Arrow.fromtimestamp(timestamp, tzinfo=tz.gettz("Europe/Paris"))
Expand Down

0 comments on commit 8ad64d0

Please sign in to comment.