def test_format_outside_max_date(self): date = datetime(2800, 1, 1, 1, 45, 34, 987000, tzinfo=pytz.utc) date_unzoned = datetime(2800, 1, 1, 1, 45, 34, 987000) check_fmt = '2050-01-01T00:00:00.000Z' fmt_date = dates.format_iso_datetime(date) fmt_date_unzoned = dates.format_iso_datetime(date_unzoned) assert fmt_date == check_fmt assert fmt_date_unzoned == check_fmt
def test_format_far_past_date_invalid(self): date = datetime(1, 1, 1, 0, 2, 34, 987000, tzinfo=pytz.timezone("Asia/Tokyo")) check_fmt = "0001-01-01T00:00:00.000Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_far_future_date_invalid(self): date = datetime(9999, 12, 31, 23, 59, 58, 987000, tzinfo=pytz.timezone("America/Toronto")) check_fmt = "9999-12-31T23:59:59.999Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_far_past_date_utc(self): date = datetime(1, 1, 1, 0, 2, 34, 987000, tzinfo=pytz.utc) check_fmt = "0001-01-01T00:02:34.987Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_local_datetime(self): est = pytz.timezone("US/Eastern") date = est.localize(datetime(2015, 3, 12, 2, 45, 34, 987000)) check_fmt = "2015-03-12T06:45:34.987Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_utc_datetime(self): date = pytz.utc.localize(datetime(2015, 3, 12, 2, 45, 34)) check_fmt = "2015-03-12T02:45:34.000Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_naive_datetime(self): date = datetime(2015, 3, 12, 2, 45, 34) check_fmt = "2015-03-12T02:45:34.000Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_far_future_date_utc(self): date = datetime(9999, 12, 31, 23, 59, 58, 987000, tzinfo=pytz.utc) check_fmt = "9999-12-31T23:59:58.987Z" fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def object_serializer(obj): """Helper to serialize a field into a compatible MyGeotab object. :param obj: The object. """ return dates.format_iso_datetime(obj) if hasattr(obj, 'isoformat') else obj
def test_format_local_datetime(self): est = pytz.timezone('US/Eastern') date = est.localize(datetime(2015, 3, 12, 2, 45, 34, 987000)) check_fmt = '2015-03-12T06:45:34.987Z' fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_utc_datetime(self): date = pytz.utc.localize(datetime(2015, 3, 12, 2, 45, 34)) check_fmt = '2015-03-12T02:45:34.000Z' fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt
def test_format_naive_datetime(self): date = datetime(2015, 3, 12, 2, 45, 34) check_fmt = '2015-03-12T02:45:34.000Z' fmt_date = dates.format_iso_datetime(date) assert fmt_date == check_fmt