Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,33 @@ def to(self, tz: TZ_EXPR) -> "Arrow":
fold=getattr(dt, "fold", 0),
)

def time_diff(self, tz: TZ_EXPR) -> int:
"""Returns a integer represent the time difference between two timezone. Early is positive, otherwise, negative

:param tz: A :ref:int.

Usage::

>>> utc.timeDef('US/Pacific')
8

"""

if not isinstance(tz, dt_tzinfo):
tz = parser.TzinfoParser.parse(tz)

dt = self._datetime.astimezone(tz)

if dt.date == self._datetime.date:
return self._datetime.hour - dt.hour
elif dt.date > self._datetime.date:
return self._datetime.hour - dt.hour + 24
else:
return self._datetime.hour - dt.hour - 24


return self.datetime.hour - dt.hour

# string output and formatting

def format(
Expand Down