Skip to content

Commit

Permalink
Consider %s to have be a timestamp in UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 7, 2023
1 parent 15f8116 commit fb781d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,10 @@ fn test_datetime_parse_from_str() {
Utc.datetime_from_str("Fri, 09 Aug 2013 23:54:35 GMT", "%a, %d %b %Y %H:%M:%S GMT"),
Ok(Utc.with_ymd_and_hms(2013, 8, 9, 23, 54, 35).unwrap())
);
assert_eq!(
DateTime::parse_from_str("0", "%s").unwrap(),
NaiveDateTime::from_timestamp_opt(0, 0).unwrap().and_utc().fixed_offset()
);
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/format/parsed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ impl Parsed {
/// plus a time zone offset.
/// Either way those fields have to be consistent to each other.
pub fn to_datetime(&self) -> ParseResult<DateTime<FixedOffset>> {
let offset = self.offset.ok_or(NOT_ENOUGH)?;
// If there is no explicit offset, consider a timestamp value as indication of a UTC value.
let offset = self.offset.or(self.timestamp.map(|_| 0)).ok_or(NOT_ENOUGH)?;
let datetime = self.to_naive_datetime_with_offset(offset)?;
let offset = FixedOffset::east_opt(offset).ok_or(OUT_OF_RANGE)?;

Expand Down

0 comments on commit fb781d1

Please sign in to comment.