def test_localize_local_time(): now = datetime.now() assert now.tzinfo is None local_date = utils.localize_local_time(now, 'America/Los_Angeles') assert local_date is not None assert local_date.hour == now.hour assert local_date.minute == now.minute assert local_date.tzinfo is not None
def set_local_time(self, local_time=None, tz='UTC'): """ sets the local time and the iso timestamp of this activity :param local_time: the activity time according to the user's location :type local_time: string :param tz: the timezone of the user :type tz: string :return: :rtype: """ if local_time: self.local_timestamp = utils.localize_local_time(local_time, tz) else: self.local_timestamp = utils.get_local_time_from_utc(self.timestamp, tz) print("self.local_timestamp", self.local_timestamp) self.iso_timestamp = utils.get_iso_from_local_time(self.local_timestamp)
def test_get_utc_from_local_time_badtz(): my_date_utc = utils.localize_local_time(datetime.now(), 'fgfgfggf') assert my_date_utc is not None assert my_date_utc.tzinfo == pytz.utc
def test_localize_local_time_badtz(): local_date = utils.localize_local_time(datetime.now(), 'fgfgfggf') assert local_date is not None assert local_date.tzinfo == pytz.utc