mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-02 23:36:17 +00:00
Remove hack to accept "UTC" in timezone_offset_zulu
This commit is contained in:
parent
e985f08868
commit
9ab02596a7
@ -743,6 +743,17 @@ fn test_datetime_from_str() {
|
|||||||
)
|
)
|
||||||
.unwrap())
|
.unwrap())
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
"2015-02-18T23:16:9.15Utc".parse::<DateTime<Utc>>(),
|
||||||
|
Ok(Utc
|
||||||
|
.from_local_datetime(
|
||||||
|
&NaiveDate::from_ymd_opt(2015, 2, 18)
|
||||||
|
.unwrap()
|
||||||
|
.and_hms_milli_opt(23, 16, 9, 150)
|
||||||
|
.unwrap()
|
||||||
|
)
|
||||||
|
.unwrap())
|
||||||
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"2015-2-18T23:16:9.15Z".parse::<DateTime<FixedOffset>>(),
|
"2015-2-18T23:16:9.15Z".parse::<DateTime<FixedOffset>>(),
|
||||||
|
@ -542,7 +542,8 @@ impl str::FromStr for DateTime<FixedOffset> {
|
|||||||
/// Differences with RFC3339:
|
/// Differences with RFC3339:
|
||||||
/// - Values don't require padding to two digits.
|
/// - Values don't require padding to two digits.
|
||||||
/// - Years outside the range 0...=9999 are accepted, but they must include a sign.
|
/// - Years outside the range 0...=9999 are accepted, but they must include a sign.
|
||||||
/// - `UTC` is accepted as a valid timezone name/offset.
|
/// - `UTC` is accepted as a valid timezone name/offset (for compatibility with the debug format of
|
||||||
|
/// `DateTime<Utc>`.
|
||||||
/// - There can be spaces between any of the components.
|
/// - There can be spaces between any of the components.
|
||||||
/// - The colon in the offset may be missing.
|
/// - The colon in the offset may be missing.
|
||||||
fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a str, ())> {
|
fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult<(&'a str, ())> {
|
||||||
@ -565,7 +566,6 @@ fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult
|
|||||||
Item::Numeric(Numeric::Second, Pad::Zero),
|
Item::Numeric(Numeric::Second, Pad::Zero),
|
||||||
Item::Fixed(Fixed::Nanosecond),
|
Item::Fixed(Fixed::Nanosecond),
|
||||||
Item::Space(""),
|
Item::Space(""),
|
||||||
Item::Fixed(Fixed::TimezoneOffsetZ),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
s = match parse_internal(parsed, s, DATE_ITEMS.iter()) {
|
s = match parse_internal(parsed, s, DATE_ITEMS.iter()) {
|
||||||
@ -580,11 +580,19 @@ fn parse_rfc3339_relaxed<'a>(parsed: &mut Parsed, mut s: &'a str) -> ParseResult
|
|||||||
None => return Err(TOO_SHORT),
|
None => return Err(TOO_SHORT),
|
||||||
};
|
};
|
||||||
|
|
||||||
match parse_internal(parsed, s, TIME_ITEMS.iter()) {
|
s = match parse_internal(parsed, s, TIME_ITEMS.iter()) {
|
||||||
Err((s, e)) if e.0 == ParseErrorKind::TooLong => Ok((s, ())),
|
Err((s, e)) if e.0 == ParseErrorKind::TooLong => s,
|
||||||
Err((_s, e)) => Err(e),
|
Err((_s, e)) => return Err(e),
|
||||||
Ok(s) => Ok((s, ())),
|
Ok(_) => return Err(NOT_ENOUGH),
|
||||||
}
|
};
|
||||||
|
s = s.trim_start();
|
||||||
|
let (s, offset) = if s.len() >= 3 && "UTC".eq_ignore_ascii_case(&s[..3]) {
|
||||||
|
(&s[3..], 0)
|
||||||
|
} else {
|
||||||
|
scan::timezone_offset(s, scan::colon_or_space, true, false, true)?
|
||||||
|
};
|
||||||
|
parsed.set_offset(i64::from(offset))?;
|
||||||
|
Ok((s, ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -210,21 +210,8 @@ where
|
|||||||
F: FnMut(&str) -> ParseResult<&str>,
|
F: FnMut(&str) -> ParseResult<&str>,
|
||||||
{
|
{
|
||||||
if allow_zulu {
|
if allow_zulu {
|
||||||
let bytes = s.as_bytes();
|
if let Some(&b'Z' | &b'z') = s.as_bytes().first() {
|
||||||
match bytes.first() {
|
return Ok((&s[1..], 0));
|
||||||
Some(&b'z') | Some(&b'Z') => return Ok((&s[1..], 0)),
|
|
||||||
Some(&b'u') | Some(&b'U') => {
|
|
||||||
if bytes.len() >= 3 {
|
|
||||||
let (b, c) = (bytes[1], bytes[2]);
|
|
||||||
match (b | 32, c | 32) {
|
|
||||||
(b't', b'c') => return Ok((&s[3..], 0)),
|
|
||||||
_ => return Err(INVALID),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(INVALID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user