Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def assertDtEqual(dt1, dt2, within=10):
assertEqual(dt1.tzinfo, dt2.tzinfo) # noqa: F821
assertTrue(abs(util.total_seconds(dt1 - dt2)) < within) # noqa: F821
utc = datetime.utcnow().replace(tzinfo=dateutil_tz.tzutc())
dt = utc.astimezone(self._datetime.tzinfo)
elif isinstance(other, Arrow):
dt = other._datetime
elif isinstance(other, datetime):
if other.tzinfo is None:
dt = other.replace(tzinfo=self._datetime.tzinfo)
else:
dt = other.astimezone(self._datetime.tzinfo)
else:
raise TypeError()
delta = int(util.total_seconds(self._datetime - dt))
sign = -1 if delta < 0 else 1
diff = abs(delta)
delta = diff
if diff < 10:
return locale.describe('now', only_distance=only_distance)
if diff < 45:
return locale.describe('seconds', sign, only_distance=only_distance)
elif diff < 90:
return locale.describe('minute', sign, only_distance=only_distance)
elif diff < 2700:
minutes = sign * int(max(delta / 60, 2))
return locale.describe('minutes', minutes, only_distance=only_distance)
utc = datetime.utcnow().replace(tzinfo=dateutil_tz.tzutc())
dt = utc.astimezone(self._datetime.tzinfo)
elif isinstance(other, Arrow):
dt = other._datetime
elif isinstance(other, datetime):
if other.tzinfo is None:
dt = other.replace(tzinfo=self._datetime.tzinfo)
else:
dt = other.astimezone(self._datetime.tzinfo)
else:
raise TypeError()
delta = int(util.total_seconds(self._datetime - dt))
sign = -1 if delta < 0 else 1
diff = abs(delta)
delta = diff
if granularity=='auto':
if diff < 10:
return locale.describe('now', only_distance=only_distance)
if diff < 45:
seconds = sign * delta
return locale.describe('seconds', seconds, only_distance=only_distance)
elif diff < 90:
return locale.describe('minute', sign, only_distance=only_distance)
elif diff < 2700:
minutes = sign * int(max(delta / 60, 2))
utc = datetime.utcnow().replace(tzinfo=dateutil_tz.tzutc())
dt = utc.astimezone(self._datetime.tzinfo)
elif isinstance(other, Arrow):
dt = other._datetime
elif isinstance(other, datetime):
if other.tzinfo is None:
dt = other.replace(tzinfo=self._datetime.tzinfo)
else:
dt = other.astimezone(self._datetime.tzinfo)
else:
raise TypeError()
delta = int(util.total_seconds(self._datetime - dt))
sign = -1 if delta < 0 else 1
diff = abs(delta)
delta = diff
if diff < 10:
return locale.describe('now', only_distance=only_distance)
if diff < 45:
return locale.describe('seconds', sign, only_distance=only_distance)
elif diff < 90:
return locale.describe('minute', sign, only_distance=only_distance)
elif diff < 2700:
minutes = sign * int(max(delta / 60, 2))
return locale.describe('minutes', minutes, only_distance=only_distance)
past = _arrow(d)
locale = arrow.locales.get_locale(locale)
if other is None:
utc = datetime.utcnow().replace(tzinfo=dateutil_tz.tzutc())
dt = utc.astimezone(past._datetime.tzinfo)
elif isinstance(other, arrow.Arrow):
dt = d._datetime
elif isinstance(other, datetime):
if d.tzinfo is None:
dt = d.replace(tzinfo=past._datetime.tzinfo)
else:
dt = d.astimezone(past._datetime.tzinfo)
else:
raise TypeError()
delta = int(arrow.util.total_seconds(past._datetime - dt))
sign = 1 if delta < 0 else -1
diff = abs(delta)
delta = diff
if diff < 10:
return 'now'
elif diff < 45:
return _format('s', sign)
elif diff < 90:
return _format('m', sign)
elif diff < 2700:
minutes = sign * int(max(delta / 60, 2))
return _format('m', minutes)
elif diff < 5400:
return _format('h', sign)
elif diff < 79200:
elif isinstance(other, Arrow):
dt = other._datetime
elif isinstance(other, datetime):
if other.tzinfo is None:
dt = other.replace(tzinfo=self._datetime.tzinfo)
else:
dt = other.astimezone(self._datetime.tzinfo)
else:
raise TypeError()
if isinstance(granularity, list) and len(granularity) == 1:
granularity = granularity[0]
delta = int(round(util.total_seconds(self._datetime - dt)))
sign = -1 if delta < 0 else 1
diff = abs(delta)
delta = diff
try:
if granularity == "auto":
if diff < 10:
return locale.describe("now", only_distance=only_distance)
if diff < 45:
seconds = sign * delta
return locale.describe(
"seconds", seconds, only_distance=only_distance
)
elif diff < 90: