Esempio n. 1
0
    def test_convert_between_unix_times(self):  # noqa
        """Can convert UNIX time to universal time and back."""
        given_unix = 1328257004.456  # as returned by time.time()
        self.assertEquals(times.to_unix(times.from_unix(given_unix)),
                          int(given_unix))

        given_dt = self.sometime_univ
        self.assertEquals(times.from_unix(times.to_unix(given_dt)), given_dt)
Esempio n. 2
0
    def test_convert_between_unix_times(self):  # noqa
        """Can convert UNIX time to universal time and back."""
        given_unix = 1328257004.456  # as returned by time.time()
        self.assertEquals(
            times.to_unix(times.from_unix(given_unix)),
            int(given_unix)
        )

        given_dt = self.sometime_univ
        self.assertEquals(times.from_unix(times.to_unix(given_dt)),
                          given_dt)
Esempio n. 3
0
    def test_convert_unix_time_to_datetime(self):  # noqa
        """Can convert from UNIX time to universal time."""
        unix_time = 1328257004.456  # as returned by time.time()
        self.assertEquals(times.from_unix(unix_time),
                          datetime(2012, 2, 3, 8, 16, 44, 456000))

        self.assertEquals(times.format(times.from_unix(unix_time), 'UTC'),
                          '2012-02-03T08:16:44.456000+00:00')
        self.assertEquals(
            times.format(times.from_unix(unix_time), 'Europe/Amsterdam'),
            '2012-02-03T09:16:44.456000+01:00')
        self.assertEquals(
            times.format(times.from_unix(unix_time), 'Pacific/Auckland'),
            '2012-02-03T21:16:44.456000+13:00')
Esempio n. 4
0
def parse_http_date(header, headers):
    if header in headers and headers[header]:
        timetuple = email.utils.parsedate_tz(headers[header])
        try:
            return times.from_unix(email.utils.mktime_tz(timetuple))
        except (TypeError, ValueError):
            pass
Esempio n. 5
0
    def test_convert_unix_time_to_datetime(self):  # noqa
        """Can convert from UNIX time to universal time."""
        unix_time = 1328257004.456  # as returned by time.time()
        self.assertEquals(
            times.from_unix(unix_time),
            datetime(2012, 2, 3, 8, 16, 44, 456000)
        )

        self.assertEquals(
            times.format(times.from_unix(unix_time), 'UTC'),
            '2012-02-03T08:16:44.456000+00:00')
        self.assertEquals(
            times.format(times.from_unix(unix_time), 'Europe/Amsterdam'),
            '2012-02-03T09:16:44.456000+01:00')
        self.assertEquals(
            times.format(times.from_unix(unix_time), 'Pacific/Auckland'),
            '2012-02-03T21:16:44.456000+13:00')
Esempio n. 6
0
 def test_convert_non_numeric_from_unix(self):
     """from_unix refuses to accept non-numeric input"""
     with self.assertRaises(TypeError):
         times.from_unix('lol')
Esempio n. 7
0
 def test_convert_non_numeric_from_unix(self):
     """from_unix refuses to accept non-numeric input"""
     with self.assertRaises(TypeError):
         times.from_unix('lol')