def test_times_with_minutes(self): ts = wtftz.convert("10:15pm", 'pst') self.assertEqual(ts.hour, 14) self.assertEqual(ts.minute, 15) self.assertEqual( wtftz.convert(_epoch(ts), from_tz="pst", to_tz="utc"), wtftz.convert(ts, from_tz="pdt", to_tz="utc"))
def test_sys_date(self): #TODO: Make this test pass s = "Mon Dec 10 23:31:50 EST 2012" ts_pst = datetime(2012, 12, 10, 20, 31, 50) self.assertEqual(ts_pst, wtftz.convert(s, 'pst')) ts_utc = datetime(2012, 12, 11, 4, 31, 50) self.assertEqual(ts_utc, wtftz.convert(s, 'utc'))
def _test_slang_tz(self, timestamp, slang_tz, actual_tz): """Test the slang timezone converter. Args: timestamp: The source timestamp, as UTC slang_tz: The common name for a timezone actual_tz: A proper pytz timezone """ timezoned = _convert(timestamp, to_tz=actual_tz) epoch = _epoch(timestamp) self.assertEqual(_truncate_time(timezoned), wtftz.convert(epoch, to_tz=slang_tz)) self.assertEqual( timezoned, wtftz.convert(timestamp.isoformat(), to_tz=slang_tz))
def test_simple_bare_times(self): ts = wtftz.convert("10am", 'utc') self.assertEqual(ts.hour, 10) self.assertEqual(ts.minute, 0) ts = wtftz.convert("10pm", 'utc') self.assertEqual(ts.hour, 22) self.assertEqual(ts.minute, 0) day = ts.day ts = wtftz.convert("10pm", 'pst') self.assertEqual(ts.hour, 14) self.assertEqual(ts.day, day) self.assertEqual(ts.minute, 0) ts = wtftz.convert("10am", 'pst') self.assertEqual(ts.hour, 2) self.assertEqual(ts.day, day) self.assertEqual(ts.minute, 0)
def _test_times(self, val, ts): self.assertEqual(wtftz.convert(val, to_tz="pacific"), _convert(ts)) self.assertEqual(wtftz.convert(val, to_tz="pst"), _convert(ts)) self.assertEqual(wtftz.convert(val, to_tz="pdt"), _convert(ts)) self.assertEqual(wtftz.convert(val, to_tz="utc"), ts) self.assertEqual(wtftz.convert(val, to_tz="gmt"), ts)
def test_isoformat_tz(self): ts = datetime.now(pytz.timezone("US/Pacific")) self.assertEqual(wtftz.convert(ts.isoformat(), 'pst', naive=False), ts) # Lie about the source timezone self.assertEqual(wtftz.convert( ts.isoformat(), from_tz='utc', to_tz='pst', naive=False), ts)
def test_isoformat_utc(self): ts = datetime.utcnow() self.assertEqual(wtftz.convert(ts.isoformat(), 'utc'), ts)
def test_naive(self): ts = datetime.utcnow() converted = wtftz.convert(ts, 'pst', naive=False) self.assertFalse(converted.tzinfo is None) self.assertEqual(converted.tzinfo, pytz.timezone("US/Pacific"))
def test_from_local_time(self): ts = datetime.now(pytz.timezone("US/Pacific")) self.assertEqual( wtftz.convert(ts, 'utc'), pytz.utc.normalize(ts).replace(tzinfo=None))