def date_range(date_from, date_to): date_from = Pendulum.create_from_format(date_from, "%Y-%m-%d") date_to = Pendulum.create_from_format(date_to, "%Y-%m-%d") period = date_to - date_from for date in period: yield date, date.add(days=1).to_date_string()
def test_create_from_format_and_tz(self): """Test a use case""" d_utc = Pendulum.create_from_format('2016-11-06', '%Y-%m-%d', 'UTC') self.assertEqual('UTC', d_utc.timezone_name) self.assertPendulum(d_utc, 2016, 11, 6, 0, 0, 0) d_colombia = d_utc.in_tz('America/Bogota') self.assertEqual('America/Bogota', d_colombia.timezone_name) self.assertPendulum(d_colombia, d_utc.year, d_utc.month, 5, 19, 0, 0) d_israel = d_utc.in_tz('Asia/Jerusalem') self.assertPendulum(d_israel, d_utc.year, d_utc.month, d_utc.day, d_utc.hour + 2, 0, 0)
def test_create_from_format_returns_pendulum(self): d = Pendulum.create_from_format('1975-05-21 22:32:11', '%Y-%m-%d %H:%M:%S') self.assertPendulum(d, 1975, 5, 21, 22, 32, 11) self.assertIsInstanceOfPendulum(d) self.assertEqual('UTC', d.timezone_name)
def test_create_from_format_with_millis(self): d = Pendulum.create_from_format('1975-05-21 22:32:11.123456', '%Y-%m-%d %H:%M:%S.%f') self.assertPendulum(d, 1975, 5, 21, 22, 32, 11) self.assertEqual(123456, d.microsecond)
def test_create_from_format_with_timezone(self): d = Pendulum.create_from_format('1975-05-21 22:32:11', '%Y-%m-%d %H:%M:%S', timezone('Europe/London')) self.assertPendulum(d, 1975, 5, 21, 22, 32, 11) self.assertEqual('Europe/London', d.timezone_name)
def test_create_from_format_returns_pendulum(self): d = Pendulum.create_from_format('1975-05-21 22:32:11', '%Y-%m-%d %H:%M:%S') self.assertPendulum(d, 1975, 5, 21, 22, 32, 11) self.assertIsInstanceOfPendulum(d) self.assertEqual('UTC', d.timezone_name)
def test_create_from_format_with_millis(self): d = Pendulum.create_from_format( '1975-05-21 22:32:11.123456', '%Y-%m-%d %H:%M:%S.%f' ) self.assertPendulum(d, 1975, 5, 21, 22, 32, 11) self.assertEqual(123456, d.microsecond)
def test_create_from_format_with_timezone(self): d = Pendulum.create_from_format( '1975-05-21 22:32:11', '%Y-%m-%d %H:%M:%S', pytz.timezone('Europe/London') ) self.assertPendulum(d, 1975, 5, 21, 22, 32, 11) self.assertEqual('Europe/London', d.timezone_name)
def test_create_from_format_YYYY_MM_DD(self): """Test a use case""" d_utc = Pendulum.create_from_format('2016-11-06', '%Y-%m-%d', 'UTC') self.assertEqual('UTC', d_utc.timezone_name) self.assertPendulum(d_utc, 2016, 11, 6, 0, 0, 0)