Example #1
0
 def test_parsing(self):
     self.assert_parse(None, None)
     self.assert_parse(None, 'nil')
     parsed_time = self._parse('23:59:59+01:00')
     assert_equals(
         time(23, 59, 59, tzinfo=iso8601.FixedOffset(1, 0, '+01:00')),
         parsed_time)
     parsed_time = self._parse('23:59:59-02:30')
     assert_equals(
         time(23, 59, 59, tzinfo=iso8601.FixedOffset(-2, -30, '-02:30')),
         parsed_time)
Example #2
0
    def test_parsing(self):
        self.assert_parse(None, None)
        self.assert_parse(None, 'nil')
        self.assert_parse(XSDDate(2012, 10, 26), '2012-10-26')
        self.assert_parse(XSDDate(2016, 2, 29, tzinfo=iso8601.UTC), '2016-02-29Z')
        parsed_date = self._parse('2012-02-29+01:00')
        assert_equals(date(2012, 2, 29), parsed_date.as_datetime_date())
        assert_equals(iso8601.FixedOffset(1, 0, '+01:00').utcoffset(None), parsed_date.tzinfo.utcoffset(None))

        parsed_date = self._parse('2012-02-29-02:30')
        assert_equals(date(2012, 2, 29), parsed_date.as_datetime_date())
        assert_equals(iso8601.FixedOffset(-2, -30, '-02:30').utcoffset(None), parsed_date.tzinfo.utcoffset(None))
Example #3
0
 def test_rendering_timezones(self):
     time_ = time(10,
                  15,
                  20,
                  tzinfo=iso8601.FixedOffset(1, 15, 'dummy zone'))
     rendered_xml = self.xsd_type().xmlvalue(time_)
     assert_equals('10:15:20+01:15', rendered_xml)
Example #4
0
    def test_parsing_timezone(self):
        class Test(xsd.ComplexType):
            time_ = xsd.Element(self.xsd_type, tagname='time')

        parsed = Test.parsexml('<root><time>20:19:00+01:00</time></root>')
        assert_equals(
            time(20, 19, 0, tzinfo=iso8601.FixedOffset(1, 0, '+01:00')),
            parsed.time_)
Example #5
0
File: xsd.py Project: Eveler/dmsic
    def _parse_tz(self, match):
        offset_string = match.group('timezone')
        if not offset_string:
            return None
        elif offset_string == 'Z':
            return iso8601.UTC

        sign = 1 if (match.group('tz_sign') == '+') else -1
        offset_hours = sign * int(match.group('tz_hour'))
        offset_minutes = sign * int(match.group('tz_minute'))
        return iso8601.FixedOffset(offset_hours, offset_minutes, name='UTC' + offset_string)
Example #6
0
 def test_parsing_timezone(self):
     class Test(xsd.ComplexType):
         datetime_ = xsd.Element(xsd.DateTime, tagname='datetime')
     parsed = Test.parsexml('<root><datetime>2011-06-30T20:19:00+01:00</datetime></root>')
     assert_equals(datetime(2011, 6, 30, 20, 19, 0, tzinfo=iso8601.FixedOffset(1, 0, '+01:00')), parsed.datetime_)
Example #7
0
 def test_rendering_timezones(self):
     date_ = XSDDate(2001, 10, 26, tzinfo=iso8601.FixedOffset(1, 15, 'dummy zone'))
     rendered_xml = self.xsd_type().xmlvalue(date_)
     assert_equals('2001-10-26+01:15', rendered_xml)
Example #8
0
def test_parse_no_timezone_different_default():
    tz = iso8601.FixedOffset(2, 0, "test offset")
    d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
    assert d.tzinfo == tz
Example #9
0
 def test_rendering_timezones(self):
     fake_tz = iso8601.FixedOffset(1, 15, 'dummy zone')
     dt = datetime(2001, 10, 26, 21, 32, 52, tzinfo=fake_tz)
     rendered_xml = xsd.DateTime().xmlvalue(dt)
     self.assertEqual('2001-10-26T21:32:52+01:15', rendered_xml)