109 Commits

Author SHA1 Message Date
Chris Leach
2e1cd2f5fa
Fix incorrect parsing of fixed-length second fractions (#1705)
Co-authored-by: Chris Leach <chris.leach@garrison.com>
2025-06-03 13:48:36 +02:00
Nicolas Boichat
6d29c8abe7 Add quarter (%q) date string specifier
GNU date supports %q as a date string specifier. This adds
support for that in chrono.

This is needed by uutils/coreutils for compability.
2025-02-25 16:18:20 +01:00
Dirkjan Ochtman
7f6cf5e504 Switch to 2024 style 2025-02-21 11:20:55 +01:00
Viktor Szépe
77d50b1fc1 Fix typos 2024-10-20 07:46:13 +00:00
Dirkjan Ochtman
e6f5d515cc Apply clippy suggestions from Rust 1.79 2024-07-08 10:11:53 +02:00
Paul Dicker
b882f58fa4 Simplify error value of parse_internal 2024-02-26 11:15:33 +01:00
Paul Dicker
ded9fe1585 Move TOO_LONG error out of parse_internal 2024-02-09 12:00:44 +01:00
Paul Dicker
42db00a981 Remove incomplete parsing support for -0000 offset 2024-02-07 13:36:44 +01:00
Paul Dicker
9c07a015df Make range check more accurate, and add comment why it is not useless 2024-02-07 13:36:44 +01:00
Paul Dicker
51cb026a58 Replace 86_400 with MAX_RFC3339_OFFSET 2024-02-07 13:36:44 +01:00
Paul Dicker
bfc7b26239 Make std imply alloc feature 2023-09-23 13:12:21 +02:00
Paul Dicker
935e7b5953 Parse to NaiveDateTime in parse_rfc850 test
The format string doesn't contain any offset info.
2023-09-05 14:23:14 +02:00
Paul Dicker
5a6b2b40a7 Fix arbitrary string slicing in parse_rfc3339_relaxed 2023-09-05 09:16:15 +02:00
Paul Dicker
9ab02596a7 Remove hack to accept "UTC" in timezone_offset_zulu 2023-08-29 15:15:11 +02:00
Paul Dicker
e985f08868 Switch RFC3339 formatting item to relaxed parser to match documentation 2023-08-29 15:15:11 +02:00
Paul Dicker
3f8a5005e9 Use parse_rfc3339 directly in DateTime::parse_from_rfc3339
We want this to use the strict parser directly, so we can switch the `RFC3339`
item to a relaxed parser.
2023-08-29 15:15:11 +02:00
Paul Dicker
ccd7f8545d Allow 't' as a seperator between date and time in parse_rfc3339_relaxed
From the standard:
> NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this syntax may
> alternatively be lower case "t" or "z" respectively.

The strict parser accepted 't', now the relaxed parser also does.
2023-08-29 15:15:11 +02:00
Paul Dicker
fb4371bcc1 Don't consume trailing whitespace in parse_rfc3339_relaxed
When used for the `RFC3339` formatting item it should not consume the trailing
whitespace, only in the `from_str` method.
2023-08-29 15:15:11 +02:00
Paul Dicker
459b82f039 Extract relaxed RFC 3339 parser from FromStr impl for DateTime
This allows us to start using the permissive parser for the `RFC3339` item,
which matches the documentation more closely.
2023-08-29 15:15:11 +02:00
Paul Dicker
1c517cf43c RFC 3339: accept space as separator between date and time
From the standard:
> NOTE: ISO 8601 defines date and time separated by "T". Applications using
> this syntax may choose, for the sake of readability, to specify a full-date
> and full-time separated by (say) a space character.

The permissive parser already accepted a space, now the strict parser also
accepts it.
The vague wording suggest more characters than 'T' and ' ' might be allowed,
but I have stopped at adding just a space.
2023-08-29 15:15:11 +02:00
Paul Dicker
29923331b2 Adjust formatting 2023-07-18 17:07:13 +02:00
Paul Dicker
20e7dd5f1d Convert macro to function 2023-07-07 12:40:51 +02:00
Paul Dicker
823e98190d Backport more checks in test_parse from main 2023-07-07 12:40:51 +02:00
Paul Dicker
838ba6813a Import Fixed variants 2023-07-07 12:40:51 +02:00
Paul Dicker
33c69f8d8a Split up test_parse 2023-07-07 12:40:51 +02:00
Paul Dicker
ee3d61b179 Rust issue #22255 is no longer relevant 2023-07-07 12:40:51 +02:00
Paul Dicker
72e1fba0d2 Make formatting only available with alloc or std feature, not with test 2023-06-30 11:59:01 +02:00
Paul Dicker
eec5232a69 Make formatting tests require alloc or std feature 2023-06-30 11:58:56 +02:00
Paul Dicker
41a1b99b9e Make test_rfc2822 work without formatting 2023-06-30 11:50:12 +02:00
Paul Dicker
e15b897b9b Make test_rfc3339 work without formatting 2023-06-30 11:50:12 +02:00
Paul Dicker
7afc6a2600 Replace macros for formatting items with functions 2023-06-30 11:06:23 +02:00
Dirkjan Ochtman
69456af23c Fold permissive parsing into timezone_offset() 2023-06-29 14:07:56 +02:00
Dirkjan Ochtman
5293ed7746 Fold zulu parsing into timezone_offset() 2023-06-29 14:07:56 +02:00
Dirkjan Ochtman
11a63a07d1 Inline trivial single-use function 2023-06-29 14:07:56 +02:00
Dirkjan Ochtman
224933ec51 Remove indirection for parsing timezone offset 2023-06-29 14:07:56 +02:00
Paul Dicker
b2cb0fdf7b Move test in format::parse to test module 2023-06-12 12:05:08 +02:00
Paul Dicker
8f2e94d930 Remove #![allow(deprecated)] 2023-06-12 12:05:08 +02:00
jtmoon79
7a4da413cf timezone allows leading MINUS SIGN (U+2212)
Timezone signage also allows MINUS SIGN (U+2212) as
specified by ISO 8601 and RFC 3339.

Not for RFC 2822 format or RFC 8536 transition string.

Issue #835
2023-06-12 10:04:23 +02:00
jtmoon79
b9a0a251c5 Add tests for RFC 850 failures 2023-06-12 10:04:23 +02:00
jtmoon79
29e728ae9f Add parse tests focused on timezone signage
Add parse tests focused on timezone siganges "+", "-", and
bad offsets
2023-06-12 10:04:23 +02:00
Paul Dicker
8bd13db242 Use result in doctest 2023-05-30 21:15:42 +02:00
Paul Dicker
becc22219d Revert backport of #807 2023-05-30 21:15:42 +02:00
jtmoon79
c0d848d4c8 parse tests around nanosecond parsing bare '.' 2023-05-30 09:57:11 +02:00
Paul Dicker
7c90f35a65 Ensure results are used 2023-05-26 12:16:08 +02:00
Paul Dicker
c944b9c396 Add parse_and_remainder methods 2023-05-19 14:55:43 +02:00
jtmoon79
1a233aa75d Constrain timezone parsing
Constrain timezone parsing further. Only allow optional colon
char `:` between timezone hour offset and timezone minute offset.

Issue #660
2023-05-15 10:48:13 +02:00
jtmoon79
f90d4037f0 Constrain timezone separator colon strings
Constrain timezone middle-colon separator string from
infinite intermixed whitespace and colons
to possible patterns `":"`, `" "`, `" :"`, `": "`, or `" : "`.
A reasonable trade-off of previous extreme flexibility for
a little flexbility and concise input.

Issue #660
2023-05-15 10:48:13 +02:00
jtmoon79
1f45d8ed3f Exact whitespace parsing
Be exact about allowed whitespace around and between data and
parsing formats for all parsing.
Except RFC 2822 which explicitly allows arbitrary whitespace.

Issue #660
2023-05-15 10:48:13 +02:00
jtmoon79
bc58a7db52 Add various tests for current parsing
Add more varying testing for most parsing functions.
Tests emphasize whitespace, literals, timezones, and timezone
delimiters (colons and whitespace).

Add tests for multiple-byte characters and combining characters
in and around data and parsing formats.

These tests are added to aid humans verifying the next commit that
changes parsing behavior.

Issue #660
2023-05-15 10:48:13 +02:00
Paul Dicker
93e2a91618 Add test for string slicing panic from issue 1010 2023-04-18 15:15:03 +02:00