def test_utc_datetime_to_utc(self): date = pytz.utc.localize(datetime(2015, 3, 12, 2, 45, 34)) utc_date = dates.localize_datetime(date, pytz.utc) assert utc_date.tzinfo is not None assert utc_date.tzinfo is pytz.utc assert utc_date.year == date.year assert utc_date.month == date.month assert utc_date.day == date.day assert utc_date.hour == date.hour
def test_utc_datetime_to_utc(self): date = pytz.utc.localize(datetime(2015, 3, 12, 2, 45, 34)) utc_date = dates.localize_datetime(date, pytz.utc) assert utc_date.tzinfo is not None assert utc_date.tzinfo is pytz.utc assert utc_date.year == date.year assert utc_date.month == date.month assert utc_date.day == date.day assert utc_date.hour == date.hour
def test_zoned_max_datetime(self): tz_aus = pytz.timezone("Australia/Sydney") tz_est = pytz.timezone("America/Toronto") date = datetime(9999, 12, 31, 23, 59, 59, 999, tzinfo=tz_est) aus_date = dates.localize_datetime(date, tz_aus) check_date = dates.MAX_DATE assert aus_date.tzinfo is not None assert aus_date.year == check_date.year assert aus_date.month == check_date.month assert aus_date.day == check_date.day assert aus_date.hour == check_date.hour
def test_zoned_min_datetime(self): tz_aus = pytz.timezone("Australia/Sydney") tz_est = pytz.timezone("America/Toronto") date = datetime(1, 1, 1, tzinfo=tz_aus) est_date = dates.localize_datetime(date, tz_est) check_date = dates.MIN_DATE assert est_date.tzinfo is not None assert est_date.year == check_date.year assert est_date.month == check_date.month assert est_date.day == check_date.day assert est_date.hour == check_date.hour
def test_zoned_datetime_to_utc(self): tz = pytz.timezone("US/Eastern") date = tz.localize(datetime(2015, 3, 12, 2, 45, 34)) utc_date = dates.localize_datetime(date, pytz.utc) check_date = date.astimezone(pytz.utc) assert utc_date.tzinfo is not None assert utc_date.tzinfo is pytz.utc assert utc_date.year == check_date.year assert utc_date.month == check_date.month assert utc_date.day == check_date.day assert utc_date.hour == check_date.hour
def test_zoned_max_datetime(self): tz_aus = pytz.timezone('Australia/Sydney') tz_est = pytz.timezone('America/Toronto') date = datetime(9999, 12, 31, 23, 59,59, 999, tzinfo=tz_est) est_date = dates.localize_datetime(date, tz_aus) check_date = dates.MAX_DATE.astimezone(tz_aus) assert est_date.tzinfo is not None assert est_date.year == check_date.year assert est_date.month == check_date.month assert est_date.day == check_date.day assert est_date.hour == check_date.hour
def test_zoned_min_datetime(self): tz_aus = pytz.timezone('Australia/Sydney') tz_est = pytz.timezone('America/Toronto') date = datetime(1, 1, 1, tzinfo=tz_aus) est_date = dates.localize_datetime(date, tz_est) check_date = dates.MIN_DATE.astimezone(tz_est) assert est_date.tzinfo is not None assert est_date.year == check_date.year assert est_date.month == check_date.month assert est_date.day == check_date.day assert est_date.hour == check_date.hour
def test_zoned_datetime_to_utc(self): tz = pytz.timezone('US/Eastern') date = tz.localize(datetime(2015, 3, 12, 2, 45, 34)) utc_date = dates.localize_datetime(date, pytz.utc) check_date = date.astimezone(pytz.utc) assert utc_date.tzinfo is not None assert utc_date.tzinfo is pytz.utc assert utc_date.year == check_date.year assert utc_date.month == check_date.month assert utc_date.day == check_date.day assert utc_date.hour == check_date.hour
def object_deserializer(obj): """Helper to deserialize a raw result dict into a proper dict. :param obj: The dict. """ for key, val in obj.items(): if isinstance(val, six.string_types) and DATETIME_REGEX.search(val): try: obj[key] = dates.localize_datetime(parser.parse(val)) except ValueError: obj[key] = val return obj
def object_deserializer(obj): """Helper to deserialize a raw result dict into a proper dict. :param obj: The dict. """ for key, val in obj.items(): if isinstance(val, six.string_types) and DATETIME_REGEX.search(val): try: obj[key] = dates.localize_datetime(parser.parse(val)) except ValueError: obj[key] = val return obj
def on_data(self, data): """ The function called when new data has arrived. :param data: The list of data records received. """ for d in data: self._populate_sub_entity(d, 'Device') self._populate_sub_entity(d, 'Rule') date = dates.localize_datetime(d['activeFrom']) click.echo( '[{date}] {device} ({rule})'.format(date=date, device=d['device'].get('name', '**Unknown Vehicle'), rule=d['rule'].get('name', '**Unknown Rule')))
def on_data(self, data): """ The function called when new data has arrived. :param data: The list of data records received. """ for d in data: self._populate_sub_entity(d, 'Device') self._populate_sub_entity(d, 'Rule') date = dates.localize_datetime(d['activeFrom']) click.echo('[{date}] {device} ({rule})'.format( date=date, device=d['device'].get('name', '**Unknown Vehicle'), rule=d['rule'].get('name', '**Unknown Rule')))
def on_data(self, data): """ The function called when new data has arrived. :param data: The list of data records received. """ for d in data: self._populate_sub_entity(d, "Device") self._populate_sub_entity(d, "Rule") date = dates.localize_datetime(d["activeFrom"]) click.echo("[{date}] {device} ({rule})".format( date=date, device=d["device"].get("name", "**Unknown Vehicle"), rule=d["rule"].get("name", "**Unknown Rule"), ))