def test_timedelta_arithmetic(self): hour = timedelta(hours=1) d = tardis.parse("2014/06/02 10:00:00 -0700") hour_before = tardis.parse("2014/06/02 09:00:00 -0700") hour_after = tardis.parse("2014/06/02 11:00:00 -0700") self.assertEqual(d + hour, hour_after) self.assertEqual(d - hour, hour_before) self.assertEqual(hour_after - d, hour)
def test_parse_with_tzutc_timezone(self, mock_get_localzone): mock_get_localzone.return_value = pytz.utc dt = pytz.utc.localize(datetime(2015, 1, 1)) dt_str = dt.strftime('%Y-%m-%d %H:%M:%S %Z') do = tardis.parse(dt_str) self.assertEqual(do.datetime, dt) self.assertEqual(do.timezone, pytz.utc)
def test_parse_with_fixed_offset_timezone(self): tz = pytz.FixedOffset(-480) dt = tz.localize(datetime(2015, 1, 1)) dt_str = dt.strftime('%Y-%m-%d %H:%M:%S %z') do = tardis.parse(dt_str) self.assertEqual(do.datetime, dt) self.assertEqual(do.timezone, tz)
def test_parse_with_overriding_timezone_parameter(self): tz = pytz.timezone('US/Pacific') dt = tz.localize(datetime(2015, 1, 1)) tz = dt.tzinfo dt_str = dt.strftime('%Y-%m-%d %H:%M:%S -0500') do = tardis.parse(dt_str, timezone='US/Pacific') self.assertEqual(do.datetime, dt) self.assertEqual(do.timezone, tz)
def test_parse_with_tzlocal_timezone(self, mock_get_local_zone): tz = pytz.timezone('US/Eastern') mock_get_local_zone.return_value = tz dt = datetime(2015, 1, 1, tzinfo=tzlocal()) dt_str = dt.strftime('%Y-%m-%d %H:%M:%S %Z') dt = dt.replace(tzinfo=None) dt = tz.localize(dt) tz = dt.tzinfo do = tardis.parse(dt_str) self.assertEqual(do.datetime, dt) self.assertEqual(do.timezone, tz)
def test_parse_with_timezone_year_fill(self): do = tardis.parse('Thu Sep 25 10:36:28') dt1 = pytz.utc.localize(datetime(date.today().year, 9, 25, 10, 36, 28)) self.assertEqual(do.datetime, dt1) self.assertEqual(do.timezone.tzname(None), "UTC")
def test_parse_default(self): do = tardis.parse('2016-07-01T11:00:00+02:00', dayfirst=False) dt1 = tardis.Tardis(datetime=datetime(2016, 7, 1, 11, 0), timezone=pytz.FixedOffset(120)) self.assertEqual(do.datetime, dt1.datetime)
def test_parse(self): do = tardis.parse('Thu Sep 25 10:36:28 BRST 2003') dt1 = pytz.utc.localize(datetime(2003, 9, 25, 10, 36, 28)) self.assertEqual(do.datetime, dt1)