Exemple #1
0
def test_parse_invalid_date2():
    try:
        iso8601.parse_date("23")
    except iso8601.ParseError:
        pass
    else: # pragma: no cover
        assert 1 == 2
Exemple #2
0
def test_parse_invalid_date2():
    try:
        iso8601.parse_date("23")
    except iso8601.ParseError:
        pass
    else:  # pragma: no cover
        assert 1 == 2
Exemple #3
0
 def test_parse_date(self):
     d = iso8601.parse_date("2006-10-20T15:34:56Z")
     self.assertEqual(d.year, 2006)
     self.assertEqual(d.month, 10)
     self.assertEqual(d.day, 20)
     self.assertEqual(d.hour, 15)
     self.assertEqual(d.minute, 34)
     self.assertEqual(d.second, 56)
     self.assertEqual(d.tzinfo, iso8601.UTC)
Exemple #4
0
def test_parse_date():
    d = iso8601.parse_date("2006-10-20T15:34:56Z")
    assert d.year == 2006
    assert d.month == 10
    assert d.day == 20
    assert d.hour == 15
    assert d.minute == 34
    assert d.second == 56
    assert d.tzinfo == iso8601.UTC
Exemple #5
0
def test_parse_date():
    d = iso8601.parse_date("2006-10-20T15:34:56Z")
    assert d.year == 2006
    assert d.month == 10
    assert d.day == 20
    assert d.hour == 15
    assert d.minute == 34
    assert d.second == 56
    assert d.tzinfo == iso8601.UTC
Exemple #6
0
 def test_parse_date(self):
     d = iso8601.parse_date("2006-10-20T15:34:56Z")
     self.assertEqual(d.year, 2006)
     self.assertEqual(d.month, 10)
     self.assertEqual(d.day, 20)
     self.assertEqual(d.hour, 15)
     self.assertEqual(d.minute, 34)
     self.assertEqual(d.second, 56)
     self.assertEqual(d.tzinfo, iso8601.UTC)
Exemple #7
0
 def test_parse_date_fraction(self):
     d = iso8601.parse_date("2006-10-20T15:34:56.123Z")
     assert d.year == 2006
     assert d.month == 10
     assert d.day == 20
     assert d.hour == 15
     assert d.minute == 34
     assert d.second == 56
     assert d.microsecond == 123000
     assert d.tzinfo == iso8601.UTC
Exemple #8
0
 def test_parse_date_fraction(self):
     d = iso8601.parse_date("2006-10-20T15:34:56.123Z")
     assert d.year == 2006
     assert d.month == 10
     assert d.day == 20
     assert d.hour == 15
     assert d.minute == 34
     assert d.second == 56
     assert d.microsecond == 123000
     assert d.tzinfo == iso8601.UTC
Exemple #9
0
 def test_parse_date_fraction_2(self):
     """From bug 6"""
     d = iso8601.parse_date("2007-5-7T11:43:55.328Z'")
     assert d.year == 2007
     assert d.month == 5
     assert d.day == 7
     assert d.hour == 11
     assert d.minute == 43
     assert d.second == 55
     assert d.microsecond == 328000
     assert d.tzinfo == iso8601.UTC
Exemple #10
0
 def test_space_separator(self):
     """Handle a separator other than T"""
     d = iso8601.parse_date("2007-06-23 06:40:34.00Z")
     assert d.year == 2007
     assert d.month == 6
     assert d.day == 23
     assert d.hour == 6
     assert d.minute == 40
     assert d.second == 34
     assert d.microsecond == 0
     assert d.tzinfo == iso8601.UTC
Exemple #11
0
 def test_parse_date_fraction_2(self):
     """From bug 6"""
     d = iso8601.parse_date("2007-5-7T11:43:55.328Z'")
     assert d.year == 2007
     assert d.month == 5
     assert d.day == 7
     assert d.hour == 11
     assert d.minute == 43
     assert d.second == 55
     assert d.microsecond == 328000
     assert d.tzinfo == iso8601.UTC
Exemple #12
0
 def test_space_separator(self):
     """Handle a separator other than T"""
     d = iso8601.parse_date("2007-06-23 06:40:34.00Z")
     assert d.year == 2007
     assert d.month == 6
     assert d.day == 23
     assert d.hour == 6
     assert d.minute == 40
     assert d.second == 34
     assert d.microsecond == 0
     assert d.tzinfo == iso8601.UTC
Exemple #13
0
 def test_parse_date_tz(self):
     d = iso8601.parse_date("2006-10-20T15:34:56.123+02:30")
     assert d.year == 2006
     assert d.month == 10
     assert d.day == 20
     assert d.hour == 15
     assert d.minute == 34
     assert d.second == 56
     assert d.microsecond == 123000
     assert d.tzinfo.tzname(None) == "+02:30"
     offset = d.tzinfo.utcoffset(None)
     assert offset.days == 0
     assert offset.seconds == 60 * 60 * 2.5
Exemple #14
0
def test_parse_date_tz():
    d = iso8601.parse_date("2006-10-20T15:34:56.123+02:30")
    assert d.year == 2006
    assert d.month == 10
    assert d.day == 20
    assert d.hour == 15
    assert d.minute == 34
    assert d.second == 56
    assert d.microsecond == 123000
    assert d.tzinfo.tzname(None) == "+02:30"
    offset = d.tzinfo.utcoffset(None)
    assert offset.days == 0
    assert offset.seconds == 60 * 60 * 2.5
Exemple #15
0
    def to_field(self, value):
        if not value:
            return null

        try:
            result = iso8601.parse_date(value, default_timezone=self.default_tzinfo)
        except (iso8601.ParseError, TypeError):
            try:
                year, month, day = map(int, value.split("-", 2))
                result = datetime.datetime(year, month, day, tzinfo=self.default_tzinfo)
            except Exception:
                raise Invalid(self.error_invalid_date, self)

        return result
Exemple #16
0
    def to_field(self, value):
        if not value:
            return null

        try:
            result = iso8601.parse_date(value)
            result = result.date()
        except (iso8601.ParseError, TypeError):
            try:
                year, month, day = map(int, value.split('-', 2))
                result = datetime.date(year, month, day)
            except Exception:
                raise Invalid(self.error_invalid_date, self)

        return result
Exemple #17
0
    def deserialize(self, value):
        if not value:
            return null

        try:
            result = iso8601.parse_date(
                value, default_timezone=self.default_tzinfo)
        except (iso8601.ParseError, TypeError) as e:
            try:
                year, month, day = map(int, value.split('-', 2))
                result = datetime.datetime(year, month, day,
                                           tzinfo=self.default_tzinfo)
            except Exception as e:
                raise Invalid(self, _('Invalid date',
                                      mapping={'val': value, 'err': e}))
        return result
Exemple #18
0
    def test_parse_no_timezone(self):
        """issue 4 - Handle datetime string without timezone

        This tests what happens when you parse a date with no timezone.
        While not strictly correct this is quite common. I'll assume UTC
        for the time zone in this case.
        """
        d = iso8601.parse_date("2007-01-01T08:00:00")
        assert d.year == 2007
        assert d.month == 1
        assert d.day == 1
        assert d.hour == 8
        assert d.minute == 0
        assert d.second == 0
        assert d.microsecond == 0
        assert d.tzinfo == iso8601.UTC
Exemple #19
0
def test_parse_no_timezone():
    """issue 4 - Handle datetime string without timezone

    This tests what happens when you parse a date with no timezone. While not
    strictly correct this is quite common. I'll assume UTC for the time zone
    in this case.
    """
    d = iso8601.parse_date("2007-01-01T08:00:00")
    assert d.year == 2007
    assert d.month == 1
    assert d.day == 1
    assert d.hour == 8
    assert d.minute == 0
    assert d.second == 0
    assert d.microsecond == 0
    assert d.tzinfo == iso8601.UTC
Exemple #20
0
    def deserialize(self, value):
        if not value:
            return null

        try:
            result = iso8601.parse_date(
                value, default_timezone=self.default_tzinfo)
        except (iso8601.ParseError, TypeError) as e:
            try:
                year, month, day = map(int, value.split('-', 2))
                result = datetime.datetime(year, month, day,
                                           tzinfo=self.default_tzinfo)
            except Exception as e:
                raise Invalid(self, _('Invalid date',
                                      mapping={'val': value, 'err': e}))
        return result
Exemple #21
0
 def test_parse_no_timezone_different_default(self):
     tz = iso8601.FixedOffset(2, 0, "test offset")
     d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
     assert d.tzinfo == tz
Exemple #22
0
 def test_parse_datetime(self):
     """
     Parse datetime object returns same object
     """
     now = datetime.datetime.now()
     self.assertIs(iso8601.parse_date(now), now)
Exemple #23
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
Exemple #24
0
 def test_parse_datetime(self):
     """
     Parse datetime object returns same object
     """
     now = datetime.datetime.now()
     self.assertIs(iso8601.parse_date(now), now)