Esempio n. 1
0
 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
Esempio n. 2
0
 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
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 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
Esempio n. 9
0
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
Esempio n. 10
0
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
Esempio n. 11
0
    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')))
Esempio n. 12
0
    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')))
Esempio n. 13
0
    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"),
            ))