def test_day_time_duration_constructor(self):
        self.check_value('xs:dayTimeDuration("-P2DT15H")',
                         DayTimeDuration(seconds=-226800))
        self.check_value('xs:dayTimeDuration(xs:duration("-P2DT15H"))',
                         DayTimeDuration(seconds=-226800))

        self.check_value('xs:dayTimeDuration("PT240H")',
                         DayTimeDuration.fromstring("P10D"))
        self.check_value('xs:dayTimeDuration("P365D")',
                         DayTimeDuration.fromstring("P365D"))
        self.check_value('xs:dayTimeDuration(xs:untypedAtomic("PT240H"))',
                         DayTimeDuration.fromstring("P10D"))
        self.check_value(
            'xs:untypedAtomic("PT240H") castable as xs:dayTimeDuration', True)
        self.check_value('xs:dayTimeDuration("-P2DT15H0M0S")',
                         DayTimeDuration.fromstring('-P2DT15H'))
        self.check_value('xs:dayTimeDuration("P3DT10H")',
                         DayTimeDuration.fromstring("P3DT10H"))
        self.check_value('xs:dayTimeDuration("PT1S")', (0, 1))
        self.check_value('xs:dayTimeDuration("PT0S")', (0, 0))

        self.wrong_value('xs:dayTimeDuration("+P3DT10H")', 'FORG0001')
        self.check_value('xs:dayTimeDuration("P999999999999999D")',
                         OverflowError)

        root = self.etree.XML('<root a="P5DT18H"/>')
        context = XPathContext(root)
        self.check_value('xs:dayTimeDuration(@a)',
                         DayTimeDuration(496800),
                         context=context)

        context.item = DayTimeDuration(86400)
        self.check_value('xs:dayTimeDuration(.)',
                         DayTimeDuration(86400),
                         context=context)
示例#2
0
    def test_sub_operator(self):
        date = Date.fromstring
        date10 = Date10.fromstring

        self.assertEqual(
            date("2002-04-02") - date("2002-04-01"),
            DayTimeDuration(seconds=86400))
        self.assertEqual(
            date("-2002-04-02") - date("-2002-04-01"),
            DayTimeDuration(seconds=86400))
        self.assertEqual(
            date("-0002-01-01") - date("-0001-12-31"),
            DayTimeDuration.fromstring('-P729D'))

        self.assertEqual(
            date("-0101-01-01") - date("-0100-12-31"),
            DayTimeDuration.fromstring('-P729D'))
        self.assertEqual(
            date("15032-11-12") - date("15032-11-11"),
            DayTimeDuration(seconds=86400))
        self.assertEqual(
            date("-9999-11-12") - date("-9999-11-11"),
            DayTimeDuration(seconds=86400))
        self.assertEqual(
            date("-9999-11-12") - date("-9999-11-12"),
            DayTimeDuration(seconds=0))

        self.assertEqual(
            date10("-2001-04-02-02:00") - date10("-2001-04-01"),
            DayTimeDuration.fromstring('P1DT2H'))
 def test_day_time_duration(self):
     self.assertEqual(DayTimeDuration(300).seconds, 300)