コード例 #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)
コード例 #2
0
ファイル: test_times.py プロジェクト: gionniboy/times
    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)
コード例 #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')
コード例 #4
0
ファイル: context.py プロジェクト: marcinn/restosaur
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
コード例 #5
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
    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')
コード例 #6
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def test_convert_non_numeric_from_unix(self):
     """from_unix refuses to accept non-numeric input"""
     with self.assertRaises(TypeError):
         times.from_unix('lol')
コード例 #7
0
ファイル: test_times.py プロジェクト: bytearchive/times
 def test_convert_non_numeric_from_unix(self):
     """from_unix refuses to accept non-numeric input"""
     with self.assertRaises(TypeError):
         times.from_unix('lol')