def test_shift_aware(self): central = pytz.timezone('America/Chicago') now_aware = central.localize(self.now) # Make sure the datetime's time zone is the respected first = when.shift(now_aware, to_tz='America/New_York') second = when.shift(self.now, from_tz='America/Chicago', to_tz='America/New_York') self.assertEqual(first, second) # Also make sure the from_tz parameter is ignored first = when.shift(now_aware, from_tz='UTC', to_tz='America/New_York') self.assertEqual(first, second) # Also make sure the utc parameter is ignored first = when.shift(now_aware, to_tz='America/New_York', utc=True) self.assertEqual(first, second)
def test_shift_aware(self): """Test when.shift() for time zone aware datetimes""" central = pytz.timezone("America/Chicago") now_aware = central.localize(self.now) # Make sure the datetime's time zone is the respected first = when.shift(now_aware, to_tz="America/New_York") second = when.shift(self.now, from_tz="America/Chicago", to_tz="America/New_York") self.assertEqual(first, second) # Also make sure the from_tz parameter is ignored first = when.shift(now_aware, from_tz="UTC", to_tz="America/New_York") self.assertEqual(first, second) # Also make sure the utc parameter is ignored first = when.shift(now_aware, to_tz="America/New_York", utc=True) self.assertEqual(first, second)
def test_shift(self): """Test when.shift()""" first = when.shift(self.utc, from_tz='UTC', to_tz='America/New_York') second = when.shift(first, from_tz='America/New_York', to_tz='UTC') self.assertNotEqual(first, second) self.assertNotEqual(first, self.utc) self.assertEqual(second, self.utc) # Local time if self.timezone == 'UTC': # This block is needed for tests run in an environment set to UTC. first = when.shift(self.now, to_tz='America/New_York') second = when.shift(first, from_tz='America/New_York') else: first = when.shift(self.now, to_tz='UTC') second = when.shift(first, from_tz='UTC') self.assertNotEqual(first, second) self.assertNotEqual(first, self.now) self.assertEqual(second, self.now) # Set utc parameter to true first = when.shift(self.utc, to_tz='America/New_York', utc=True) second = when.shift(first, from_tz='America/New_York', utc=True) self.assertNotEqual(first, second) self.assertNotEqual(first, self.utc) self.assertEqual(second, self.utc) # Force UTC when.set_utc() first = when.shift(self.utc, to_tz='America/New_York') second = when.shift(first, from_tz='America/New_York') self.assertNotEqual(first, second) self.assertNotEqual(first, self.utc) self.assertEqual(second, self.utc)
def test_shift_aware(self): """Test when.shift() for time zone aware datetimes""" central = pytz.timezone('America/Chicago') now_aware = central.localize(self.now) # Make sure the datetime's time zone is the respected first = when.shift(now_aware, to_tz='America/New_York') second = when.shift(self.now, from_tz='America/Chicago', to_tz='America/New_York') self.assertEqual(first, second) # Also make sure the from_tz parameter is ignored first = when.shift(now_aware, from_tz='UTC', to_tz='America/New_York') self.assertEqual(first, second) # Also make sure the utc parameter is ignored first = when.shift(now_aware, to_tz='America/New_York', utc=True) self.assertEqual(first, second)