def test_timedelta_to_offset(self):
        # positive deltas
        t = datetime.timedelta(hours=5)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+05:00')
        t = datetime.timedelta(minutes=300)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+05:00')
        t = datetime.timedelta(hours=5, minutes=12)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+05:12')
        t = datetime.timedelta(seconds=10800)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+03:00')

        # negative deltas
        t = datetime.timedelta(hours=-4)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-04:00')
        t = datetime.timedelta(minutes=-258)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-04:18')
        t = datetime.timedelta(hours=-2, minutes=-12)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-02:12')
        t = datetime.timedelta(seconds=-10000)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-02:46')
示例#2
0
    def test_timedelta_to_offset(self):
        # positive deltas
        t = datetime.timedelta(hours=5)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+05:00')
        t = datetime.timedelta(minutes=300)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+05:00')
        t = datetime.timedelta(hours=5, minutes=12)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+05:12')
        t = datetime.timedelta(seconds=10800)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '+03:00')

        # negative deltas
        t = datetime.timedelta(hours=-4)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-04:00')
        t = datetime.timedelta(minutes=-258)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-04:18')
        t = datetime.timedelta(hours=-2, minutes=-12)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-02:12')
        t = datetime.timedelta(seconds=-10000)
        self.assertEqual(DateTimeFormatter.timedelta_to_offset(t), '-02:46')
示例#3
0
def test_timedelta_to_offset(offset, timedelta):
    assert DateTimeFormatter.timedelta_to_offset(TD(**timedelta)) == offset