Exemple #1
0
    def test_from_millisec(self):
        """This tests that time offsets can be created from millisecond values."""
        tests_ts = [(TimeOffset.from_millisec(1), TimeOffset(0, 1000000)),
                    (TimeOffset.from_millisec(1000), TimeOffset(1, 0)),
                    (TimeOffset.from_millisec(-1), TimeOffset(0, 1000000, -1))]

        for t in tests_ts:
            self.assertEqual(t[0], t[1])
Exemple #2
0
    def test_subsec(self):
        """This tests that TimeOffsets can be converted to millisec, nanosec, and microsec values."""
        tests_ts = [
            (TimeOffset(1, 1000000).to_millisec(), 1001),
            (TimeOffset(1, 1000).to_microsec(), 1000001),
            (TimeOffset(1, 1).to_nanosec(), 1000000001),
            (TimeOffset.from_millisec(1001), TimeOffset(1, 1000000)),
            (TimeOffset.from_microsec(1000001), TimeOffset(1, 1000)),
            (TimeOffset.from_nanosec(1000000001), TimeOffset(1, 1)),
            (TimeOffset(1, 500000).to_millisec(TimeOffset.ROUND_DOWN), 1000),
            (TimeOffset(1,
                        500000).to_millisec(TimeOffset.ROUND_NEAREST), 1001),
            (TimeOffset(1,
                        499999).to_millisec(TimeOffset.ROUND_NEAREST), 1000),
            (TimeOffset(1, 500000).to_millisec(TimeOffset.ROUND_UP), 1001),
            (TimeOffset(1, 500000,
                        -1).to_millisec(TimeOffset.ROUND_DOWN), -1001),
            (TimeOffset(1, 500000,
                        -1).to_millisec(TimeOffset.ROUND_NEAREST), -1001),
            (TimeOffset(1, 499999,
                        -1).to_millisec(TimeOffset.ROUND_NEAREST), -1000),
            (TimeOffset(1, 500000, -1).to_millisec(TimeOffset.ROUND_UP), -1000)
        ]

        for t in tests_ts:
            self.assertEqual(t[0], t[1])