def test_farthest_with_datetime(self):
     instance = Pendulum.create(2015, 5, 28, 12, 0, 0)
     dt1 = datetime(2015, 5, 28, 11, 0, 0)
     dt2 = datetime(2015, 5, 28, 14, 0, 0)
     closest = instance.farthest(dt1, dt2)
     self.assertIsInstanceOfPendulum(closest)
     self.assertPendulum(closest, 2015, 5, 28, 14, 0, 0)
Beispiel #2
0
    def test_sub_timedelta(self):
        delta = timedelta(days=6, seconds=16, microseconds=654321)
        d = Pendulum.create(2015, 3, 14, 3, 12, 15, 777777)

        d = d.sub_timedelta(delta)
        self.assertEqual(8, d.day)
        self.assertEqual(11, d.minute)
        self.assertEqual(59, d.second)
        self.assertEqual(123456, d.microsecond)

        d = Pendulum.create(2015, 3, 14, 3, 12, 15, 777777)

        d = d - delta
        self.assertEqual(8, d.day)
        self.assertEqual(11, d.minute)
        self.assertEqual(59, d.second)
        self.assertEqual(123456, d.microsecond)
Beispiel #3
0
    def test_add_timedelta(self):
        delta = timedelta(days=6, seconds=45, microseconds=123456)
        d = Pendulum.create(2015, 3, 14, 3, 12, 15, 654321)

        d.add_timedelta(delta)
        self.assertEqual(20, d.day)
        self.assertEqual(13, d.minute)
        self.assertEqual(0, d.second)
        self.assertEqual(777777, d.microsecond)

        d = Pendulum.create(2015, 3, 14, 3, 12, 15, 654321)

        d = d + delta
        self.assertEqual(20, d.day)
        self.assertEqual(13, d.minute)
        self.assertEqual(0, d.second)
        self.assertEqual(777777, d.microsecond)
Beispiel #4
0
    def wrap_with_test_now(self, dt=None):
        if dt is None:
            dt = Pendulum.create(2012, 1, 1, 1, 2, 3)

        Pendulum.set_test_now(dt)

        yield

        Pendulum.set_test_now()
 def test_with_time_from_string(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.with_time_from_string("05:32:49")
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(5, new.hour)
     self.assertEqual(32, new.minute)
     self.assertEqual(49, new.second)
     self.assertEqual(0, d.hour)
     self.assertEqual(41, d.minute)
     self.assertEqual(20, d.second)
 def test_fluid_with_date(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.with_date(1995, 11, 9)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(1995, new.year)
     self.assertEqual(11, new.month)
     self.assertEqual(9, new.day)
     self.assertEqual(2016, d.year)
     self.assertEqual(7, d.month)
     self.assertEqual(2, d.day)
 def test_fluid_set_time(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.with_time(5, 32, 49)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(5, new.hour)
     self.assertEqual(32, new.minute)
     self.assertEqual(49, new.second)
     self.assertEqual(0, d.hour)
     self.assertEqual(41, d.minute)
     self.assertEqual(20, d.second)
 def test_fluid_set_timestamp(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.timestamp_(0)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(1970, new.year)
     self.assertEqual(1, new.month)
     self.assertEqual(1, new.day)
     self.assertEqual(0, new.hour)
     self.assertEqual(0, new.minute)
     self.assertEqual(0, new.second)
     self.assertEqual(2016, d.year)
     self.assertEqual(7, d.month)
     self.assertEqual(2, d.day)
     self.assertEqual(0, d.hour)
     self.assertEqual(41, d.minute)
     self.assertEqual(20, d.second)
 def test_fluid_day_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.day_(9)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(9, new.day)
     self.assertEqual(2, d.day)
Beispiel #10
0
 def test_diff_in_hours_positive(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(
         26,
         dt.diff(dt.copy().add(days=1).add(hours=2)).in_hours())
Beispiel #11
0
 def test_diff_in_days_ensure_is_truncated(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(
         1,
         dt.diff(dt.copy().add(days=1).add(hours=13)).in_days())
Beispiel #12
0
 def test_diff_in_weekend_days_negative_with_sign(self):
     dt = Pendulum.create(2000, 1, 31)
     self.assertEqual(
         -10,
         dt.diff(dt.start_of('month'), False).in_weekend_days())
Beispiel #13
0
 def test_diff_in_weeks_negative_no_sign(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(52, dt.diff(dt.copy().subtract(years=1)).in_weeks())
Beispiel #14
0
 def test_sub_month(self):
     self.assertEqual(11, Pendulum.create(1975, 12).sub_month().month)
    def test_nth_of_invalid_unit(self):
        d = Pendulum.create(1975, 8, 5)

        self.assertRaises(ValueError, d.nth_of, 'invalid', 3, pendulum.MONDAY)
Beispiel #16
0
 def test_fluid_microsecond_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20, 123456)
     new = d.microsecond_(987654)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(987654, new.microsecond)
     self.assertEqual(123456, d.microsecond)
Beispiel #17
0
 def test_sub_months_negative(self):
     self.assertEqual(1, Pendulum.create(1975, 12).sub_months(-1).month)
Beispiel #18
0
 def test_fluid_minute_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.minute_(32)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(32, new.minute)
     self.assertEqual(41, d.minute)
Beispiel #19
0
 def test_fluid_second_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.second_(49)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(49, new.second)
     self.assertEqual(20, d.second)
Beispiel #20
0
 def test_fluid_hour_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.hour_(5)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(5, new.hour)
     self.assertEqual(0, d.hour)
Beispiel #21
0
 def test_fluid_day_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.day_(9)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(9, new.day)
     self.assertEqual(2, d.day)
Beispiel #22
0
 def test_fluid_month_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.month_(11)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(11, new.month)
     self.assertEqual(7, d.month)
 def test_fluid_minute_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.minute_(32)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(32, new.minute)
     self.assertEqual(41, d.minute)
Beispiel #24
0
 def test_sub_years_negative(self):
     self.assertEqual(1976, Pendulum.create(1975).sub_years(-1).year)
 def test_fluid_microsecond_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20, 123456)
     new = d.microsecond_(987654)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(987654, new.microsecond)
     self.assertEqual(123456, d.microsecond)
Beispiel #26
0
 def test_diff_in_weekdays_negative_no_sign(self):
     dt = Pendulum.create(2000, 1, 31)
     self.assertEqual(21, dt.diff(dt.start_of('month')).in_weekdays())
Beispiel #27
0
 def test_fluid_tz_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.tz_('Europe/Paris')
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual('Europe/Paris', new.timezone_name)
    def test_last_of_invalid_unit(self):
        d = Pendulum.create(1975, 8, 5)

        self.assertRaises(ValueError, d.last_of, 'invalid')
 def test_average_from_lower(self):
     d1 = Pendulum.create(2009, 12, 31, 23, 59, 59, tz='local')
     d2 = Pendulum.create(2000, 1, 1, 1, 1, 1, tz='local').average(d1)
     self.assertPendulum(d2, 2004, 12, 31, 12, 30, 30)
 def test_closest(self):
     instance = Pendulum.create(2015, 5, 28, 12, 0, 0)
     dt1 = Pendulum.create(2015, 5, 28, 11, 0, 0)
     dt2 = Pendulum.create(2015, 5, 28, 14, 0, 0)
     closest = instance.closest(dt1, dt2)
     self.assertEqual(dt1, closest)
Beispiel #31
0
 def test_local(self):
     self.assertTrue(Pendulum.create(2012, 1, 1, tz='America/Toronto').local)
     self.assertTrue(Pendulum.create(2012, 1, 1, tz='America/New_York').local)
     self.assertFalse(Pendulum.create(2012, 1, 1, tz='UTC').local)
     self.assertFalse(Pendulum.create(2012, 1, 1, tz='Europe/London').local)
Beispiel #32
0
 def test_sub_months_positive(self):
     self.assertEqual(11, Pendulum.create(1975, 12).sub_months(1).month)
Beispiel #33
0
 def test_diff_in_weekend_days_positive(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(10, dt.diff(dt.end_of('month')).in_weekend_days())
 def test_farthest_with_equals(self):
     instance = Pendulum.create(2015, 5, 28, 12, 0, 0)
     dt1 = Pendulum.create(2015, 5, 28, 12, 0, 0)
     dt2 = Pendulum.create(2015, 5, 28, 14, 0, 0)
     closest = instance.farthest(dt1, dt2)
     self.assertEqual(dt2, closest)
Beispiel #35
0
 def test_diff_in_weeks_positive(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(52, dt.diff(dt.copy().add(years=1)).in_weeks())
Beispiel #36
0
 def test_is_dst(self):
     self.assertFalse(Pendulum.create(2012, 1, 1, tz='America/Toronto').is_dst)
     self.assertTrue(Pendulum.create(2012, 7, 1, tz='America/Toronto').is_dst)
Beispiel #37
0
 def test_diff_in_weeks_ensure_is_truncated(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(
         0,
         dt.diff(dt.copy().add(weeks=1).subtract(days=1)).in_weeks())
Beispiel #38
0
 def test_offset_with_dst(self):
     self.assertEqual(-18000, Pendulum.create(2012, 1, 1, tz='America/Toronto').offset)
Beispiel #39
0
 def test_diff_in_hours_negative_with_sign(self):
     dt = Pendulum.create(2000, 1, 1)
     self.assertEqual(
         -22,
         dt.diff(dt.copy().subtract(days=1).add(hours=2), False).in_hours())
Beispiel #40
0
 def test_offset_hours_no_dst(self):
     self.assertEqual(-4, Pendulum.create(2012, 6, 1, tz='America/Toronto').offset_hours)
 def test_fluid_month_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.month_(11)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(11, new.month)
     self.assertEqual(7, d.month)
Beispiel #42
0
 def test_offset_hours_for_gmt(self):
     self.assertEqual(0, Pendulum.create(2012, 6, 1, tz='GMT').offset_hours)
 def test_fluid_hour_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.hour_(5)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(5, new.hour)
     self.assertEqual(0, d.hour)
Beispiel #44
0
 def test_offset_hours_float(self):
     self.assertEqual(9.5, Pendulum.create(2012, 6, 1, tz=9.5).offset_hours)
 def test_fluid_second_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.second_(49)
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual(49, new.second)
     self.assertEqual(20, d.second)
Beispiel #46
0
 def test_is_leap_year(self):
     self.assertTrue(Pendulum.create(2012, 1, 1).is_leap_year())
     self.assertFalse(Pendulum.create(2011, 1, 1).is_leap_year())
 def test_fluid_tz_setter(self):
     d = Pendulum.create(2016, 7, 2, 0, 41, 20)
     new = d.tz_("Europe/Paris")
     self.assertIsInstanceOfPendulum(new)
     self.assertEqual("Europe/Paris", new.timezone_name)
Beispiel #48
0
 def test_seconds_since_midnight(self):
     d = Pendulum.create(2016, 7, 5, 12, 32, 25, 0)
     self.assertEqual(25 + 32 * 60 + 12 * 3600, d.seconds_since_midnight())
Beispiel #49
0
 def test_reset_to_string_format(self):
     d = Pendulum.create(microsecond=0)
     Pendulum.set_to_string_format('123')
     Pendulum.reset_to_string_format()
     self.assertEqual(d.to_iso8601_string(), str(d))
Beispiel #50
0
 def test_sub_year(self):
     self.assertEqual(1974, Pendulum.create(1975).sub_year().year)
Beispiel #51
0
 def test_is_long_year(self):
     self.assertTrue(Pendulum.create(2015, 1, 1).is_long_year())
     self.assertFalse(Pendulum.create(2016, 1, 1).is_long_year())
Beispiel #52
0
 def test_sub_months_zero(self):
     self.assertEqual(12, Pendulum.create(1975, 12).sub_months(0).month)
Beispiel #53
0
 def test_seconds_until_end_of_day(self):
     d = Pendulum.create(2016, 7, 5, 12, 32, 25, 0)
     self.assertEqual(34 + 27 * 60 + 11 * 3600, d.seconds_until_end_of_day())
Beispiel #54
0
 def test_week_of_month(self):
     self.assertEqual(5, Pendulum.create(2012, 9, 30).week_of_month)
     self.assertEqual(4, Pendulum.create(2012, 9, 28).week_of_month)
     self.assertEqual(3, Pendulum.create(2012, 9, 20).week_of_month)
     self.assertEqual(2, Pendulum.create(2012, 9, 8).week_of_month)
     self.assertEqual(1, Pendulum.create(2012, 9, 1).week_of_month)
Beispiel #55
0
 def test_to_string(self):
     d = Pendulum.create(microsecond=0)
     self.assertEqual(Pendulum.create(microsecond=0).to_iso8601_string(), str(d))
     d = Pendulum.create(microsecond=123456)
     self.assertEqual(Pendulum.create(microsecond=123456).to_iso8601_string(True), str(d))
Beispiel #56
0
 def test_week_of_year_first_week(self):
     self.assertEqual(52, Pendulum.create(2012, 1, 1).week_of_year)
     self.assertEqual(1, Pendulum.create(2012, 1, 2).week_of_year)
 def test_average_from_same(self):
     d1 = Pendulum.create(2000, 1, 31, 2, 3, 4)
     d2 = Pendulum.create(2000, 1, 31, 2, 3, 4).average(d1)
     self.assertPendulum(d2, 2000, 1, 31, 2, 3, 4)
Beispiel #58
0
 def test_week_of_year_last_week(self):
     self.assertEqual(52, Pendulum.create(2012, 12, 30).week_of_year)
     self.assertEqual(1, Pendulum.create(2012, 12, 31).week_of_year)
Beispiel #59
0
    def test_timezone_name(self):
        d = Pendulum.create(2000, 1, 1, tz='America/Toronto')
        self.assertEqual('America/Toronto', d.timezone_name)

        d = Pendulum.create(2000, 1, 1, tz=-5)
        self.assertEqual('-05:00', d.timezone_name)
Beispiel #60
0
 def test_sub_years_zero(self):
     self.assertEqual(1975, Pendulum.create(1975).sub_years(0).year)