Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_from_time_with_hour():
with pendulum.test(pendulum.datetime(2016, 8, 11, 12, 34, 56, 123456)):
d = pendulum.create(hour=23)
assert d.hour == 23
assert d.minute == 0
assert d.second == 0
assert d.microsecond == 0
def test_diff_for_humans_other_and_nearly_week():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "6 days before" == pendulum.now().diff_for_humans(
pendulum.now().add(days=6)
)
def test_date_formats_missing():
f = Formatter()
d = pendulum.datetime(2016, 8, 28, 7, 3, 6, 123456)
assert f.format(d, "LT", locale="dummy") == "7:03 AM"
assert f.format(d, "LTS", locale="dummy") == "7:03:06 AM"
assert f.format(d, "L", locale="dummy") == "08/28/2016"
assert f.format(d, "LL", locale="dummy") == "August 28, 2016"
assert f.format(d, "LLL", locale="dummy") == "August 28, 2016 7:03 AM"
assert f.format(d, "LLLL", locale="dummy") == "Sunday, August 28, 2016 7:03 AM"
def test_farthest():
instance = pendulum.datetime(2015, 5, 28, 12, 0, 0)
dt1 = pendulum.datetime(2015, 5, 28, 11, 0, 0)
dt2 = pendulum.datetime(2015, 5, 28, 14, 0, 0)
farthest = instance.farthest(dt1, dt2)
assert farthest == dt2
farthest = instance.farthest(dt2, dt1)
assert farthest == dt2
dts = [
pendulum.datetime(2015, 5, 28, 16, 0, 0) + pendulum.duration(hours=x)
for x in range(4)
]
farthest = instance.farthest(*dts)
assert farthest == dts[-1]
farthest = instance.farthest(*(dts[::-1]))
assert farthest == dts[-1]
def test_on_datetime_2():
filter_fn = filters.on_datetime(pendulum.datetime(2019, 1, 2, 3, 4))
assert not filter_fn(pendulum.datetime(2019, 1, 2, 3, 4, 5))
def test_diff_in_minutes_negative_no_sign():
dt = pendulum.datetime(2000, 1, 1)
assert 58 == dt.diff(dt.subtract(hours=1).add(minutes=2)).in_minutes()
def test_diff_in_minutes_ensure_is_truncated():
dt = pendulum.datetime(2000, 1, 1)
assert 1 == dt.diff(dt.add(minutes=1).add(seconds=59)).in_minutes()
def test_start_of_with_transition():
d = pendulum.datetime(2013, 10, 27, 23, 59, 59, tz="Europe/Paris")
assert d.offset == 3600
assert d.start_of("month").offset == 7200
assert d.start_of("day").offset == 7200
assert d.start_of("year").offset == 3600
def test_greater_than_or_equal_with_timezone_true():
d1 = pendulum.datetime(2000, 1, 1, 12, 0, 0, tz="America/Toronto")
d2 = pendulum.datetime(2000, 1, 1, 8, 59, 59, tz="America/Vancouver")
d3 = pytz.timezone("America/Vancouver").localize(datetime(2000, 1, 1, 8, 59, 59))
assert d1 >= d2
assert d1 >= d3
def test_add_years_positive():
assert pendulum.datetime(1975, 1, 1).add(years=1).year == 1976