Skip to content

Commit

Permalink
Allow seconds in DateTime::from_str offset
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed May 24, 2023
1 parent 83668c6 commit d622df8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,17 @@ fn test_datetime_from_str() {
)
.unwrap())
);
assert_eq!(
"2015-2-18T13:16:9.15-10:00:00".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!("2015-2-18T23:16:9.15".parse::<DateTime<Utc>>().is_err());

// no test for `DateTime<Local>`, we cannot verify that much.
Expand Down
3 changes: 2 additions & 1 deletion src/format/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ where
/// - `UTC` and `Z` are accepted as a valid timezone offset.
/// - There can be a space between time and offset.
/// - The colon in the offset may be missing.
/// - The offset may optionally have seconds (compatible with the `Debug` format of `DateTime`).
///
/// ```
/// # use chrono::{DateTime, offset::FixedOffset};
Expand All @@ -604,7 +605,7 @@ impl str::FromStr for DateTime<FixedOffset> {
Item::Fixed(Fixed::Nanosecond),
];
const OFFSET_FORMAT: UtcOffsetFormat = UtcOffsetFormat {
precision: OffsetPrecision::Minutes,
precision: OffsetPrecision::OptionalSeconds,
colons: Colon::Maybe,
allow_zulu: true,
padding: Pad::Zero,
Expand Down

0 comments on commit d622df8

Please sign in to comment.