def __init__(self, id, created_at, updated_at, external_id, name, lon, lat, alt, rank): assert id is not None assert external_id is not None assert lon is not None assert lat is not None if lon < -180.0 or lon > 180.0: raise ValueError("'lon' value must be between -180 and 180") self._lon = float(lon) if lat < -90.0 or lat > 90.0: raise ValueError("'lat' value must be between -90 and 90") if alt is not None: if alt < 0.0: raise ValueError("'alt' value must not be negative") self.id = id self.created_at = created_at if self.created_at is not None: padded_created_at = self._format_micros(created_at) t = dt.strptime( padded_created_at, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=formatting.UTC()) self.created_at = formatting.timeformat(t, 'unix') self.updated_at = updated_at if self.updated_at is not None: padded_updated_at = self._format_micros(updated_at) t = dt.strptime( padded_updated_at, '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=formatting.UTC()) self.updated_at = formatting.timeformat(t, 'unix') self.external_id = external_id self.name = name self.lon = lon self.lat = lat self.alt = alt self.rank = rank
def test_to_UNIXtime(self): unix = 1378459200 iso = "2013-09-06 09:20:00+00" date = datetime(2013, 9, 6, 9, 20, 0, tzinfo=formatting.UTC()) self.assertEqual(unix, formatting.to_UNIXtime(unix)) self.assertEqual(unix, formatting.to_UNIXtime(iso)) self.assertEqual(unix, formatting.to_UNIXtime(date))
def test_to_ISO8601(self): unixtime = 1378459200 iso = "2013-09-06 09:20:00+00" date = datetime(2013, 9, 6, 9, 20, 0, tzinfo=formatting.UTC()) self.assertEqual(iso, formatting.to_ISO8601(unixtime)) self.assertEqual(iso, formatting.to_ISO8601(iso)) self.assertEqual(iso, formatting.to_ISO8601(date))
def test_timeformat(self): unixtime = 1378459200 iso = "2013-09-06 09:20:00+00" date = datetime(2013, 9, 6, 9, 20, 0, tzinfo=formatting.UTC()) self.assertEqual(unixtime, formatting.timeformat(unixtime, "unix")) self.assertEqual(iso, formatting.timeformat(unixtime, "iso")) self.assertEqual(date, formatting.timeformat(unixtime, "date")) self.assertEqual(unixtime, formatting.timeformat(iso, "unix")) self.assertEqual(iso, formatting.timeformat(iso, "iso")) self.assertEqual(date, formatting.timeformat(iso, "date")) self.assertEqual(unixtime, formatting.timeformat(date, "unix")) self.assertEqual(iso, formatting.timeformat(date, "iso")) self.assertEqual(date, formatting.timeformat(date, "date"))
def test_datetime_to_UNIXtime(self): date = datetime(2013, 9, 19, 12, 0, tzinfo=formatting.UTC()) expected = 1379592000 self.assertEqual(formatting.datetime_to_UNIXtime(date), expected)