Skip to content

Commit

Permalink
Run cargo update
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitrySamoylov committed Oct 3, 2023
1 parent a62c0be commit fc82a35
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 231 deletions.
266 changes: 184 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

43 changes: 23 additions & 20 deletions xsd-types/src/types/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Date {
impl Default for Date {
fn default() -> Date {
Self {
value: NaiveDate::from_ymd(1, 1, 1),
value: NaiveDate::from_ymd_opt(1, 1, 1).unwrap(),
timezone: None,
}
}
Expand All @@ -43,7 +43,7 @@ impl FromStr for Date {
if let Some(s) = s.strip_suffix('Z') {
return Ok(Date {
value: parse_naive_date(s)?,
timezone: Some(FixedOffset::east(0)),
timezone: Some(FixedOffset::east_opt(0).unwrap()),
});
}

Expand Down Expand Up @@ -100,7 +100,7 @@ mod tests {
assert_eq!(
Date::from_str("2020-02-02"),
Ok(Date {
value: NaiveDate::from_ymd(2020, 2, 2),
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: None
})
);
Expand All @@ -109,26 +109,26 @@ mod tests {
assert_eq!(
Date::from_str("2020-02-02Z"),
Ok(Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::east(0))
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::east_opt(0).unwrap())
})
);

// Positive offset.
assert_eq!(
Date::from_str("2020-02-02+06:30"),
Ok(Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60))
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap())
})
);

// Negative offset.
assert_eq!(
Date::from_str("2020-02-02-06:30"),
Ok(Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60))
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap())
})
);
}
Expand All @@ -138,7 +138,7 @@ mod tests {
// No timezone.
assert_eq!(
Date {
value: NaiveDate::from_ymd(2020, 2, 2),
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: None
}
.to_string(),
Expand All @@ -148,8 +148,8 @@ mod tests {
// Timezone +00:00.
assert_eq!(
Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::east(0))
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::east_opt(0).unwrap())
}
.to_string(),
"2020-02-02+00:00"
Expand All @@ -158,8 +158,8 @@ mod tests {
// Positive offset.
assert_eq!(
Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60))
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap())
}
.to_string(),
"2020-02-02+06:30"
Expand All @@ -168,8 +168,8 @@ mod tests {
// Negative offset.
assert_eq!(
Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::west(6 * 3600 + 30 * 60))
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap())
}
.to_string(),
"2020-02-02-06:30"
Expand All @@ -196,8 +196,8 @@ mod tests {
"#;
let m = Message {
created_at: Date {
value: NaiveDate::from_ymd(2020, 2, 2),
timezone: Some(FixedOffset::east(6 * 3600 + 30 * 60)),
value: NaiveDate::from_ymd_opt(2020, 2, 2).unwrap(),
timezone: Some(FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap()),
},
text: "Hello world".to_string(),
};
Expand All @@ -214,10 +214,13 @@ mod tests {
</t:Message>
"#;
let m: Message = yaserde::de::from_str(s).unwrap();
assert_eq!(m.created_at.value, NaiveDate::from_ymd(2020, 2, 2));
assert_eq!(
m.created_at.value,
NaiveDate::from_ymd_opt(2020, 2, 2).unwrap()
);
assert_eq!(
m.created_at.timezone,
Some(FixedOffset::west(6 * 3600 + 30 * 60)),
Some(FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap()),
);
assert_eq!(m.text, "Hello world".to_string());
}
Expand Down
80 changes: 56 additions & 24 deletions xsd-types/src/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ mod tests {
#[test]
fn datetime_parse_test() {
// No timezone.
let offset = FixedOffset::east(0);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(0).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTime::from_str("2020-03-07T04:40:00"),
Ok(DateTime { value: dt })
Expand All @@ -78,18 +82,26 @@ mod tests {
);

// Positive offset.
let offset = FixedOffset::east(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTime::from_str("2020-03-07T04:40:00+06:30"),
Ok(DateTime { value: dt })
);

// Negative offset.
let offset = FixedOffset::west(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTime::from_str("2020-03-07T04:40:00-06:30"),
Ok(DateTime { value: dt })
Expand All @@ -99,27 +111,39 @@ mod tests {
#[test]
fn datetime_display_test() {
// Timezone +00:00.
let offset = FixedOffset::east(0);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(0).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTime { value: dt }.to_string(),
"2020-03-07T04:40:00+00:00"
);

// Positive offset.
let offset = FixedOffset::east(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTime { value: dt }.to_string(),
"2020-03-07T04:40:00+06:30"
);

// Negative offset.
let offset = FixedOffset::west(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTime { value: dt }.to_string(),
"2020-03-07T04:40:00-06:30"
Expand All @@ -145,9 +169,13 @@ mod tests {
</t:Message>
"#;

let offset = FixedOffset::east(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
let m = Message {
created_at: DateTime { value: dt },
text: "Hello world".to_string(),
Expand All @@ -166,9 +194,13 @@ mod tests {
"#;
let m: Message = yaserde::de::from_str(s).unwrap();

let offset = FixedOffset::west(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);

assert_eq!(m.created_at.value, dt);
assert_eq!(m.text, "Hello world".to_string());
Expand Down
80 changes: 56 additions & 24 deletions xsd-types/src/types/datetimestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ mod tests {
#[test]
fn datetime_parse_test() {
// No timezone.
let offset = FixedOffset::east(0);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(0).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert!(DateTimeStamp::from_str("2020-03-07T04:40:00").is_err());
// Timezone "Z".
assert_eq!(
Expand All @@ -60,18 +64,26 @@ mod tests {
);

// Positive offset.
let offset = FixedOffset::east(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTimeStamp::from_str("2020-03-07T04:40:00+06:30"),
Ok(DateTimeStamp::from_chrono_datetime(dt))
);

// Negative offset.
let offset = FixedOffset::west(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTimeStamp::from_str("2020-03-07T04:40:00-06:30"),
Ok(DateTimeStamp::from_chrono_datetime(dt))
Expand All @@ -81,27 +93,39 @@ mod tests {
#[test]
fn datetime_display_test() {
// Timezone +00:00.
let offset = FixedOffset::east(0);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(0).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTimeStamp::from_chrono_datetime(dt).to_string(),
"2020-03-07T04:40:00+00:00"
);

// Positive offset.
let offset = FixedOffset::east(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTimeStamp::from_chrono_datetime(dt).to_string(),
"2020-03-07T04:40:00+06:30"
);

// Negative offset.
let offset = FixedOffset::west(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
assert_eq!(
DateTimeStamp::from_chrono_datetime(dt).to_string(),
"2020-03-07T04:40:00-06:30"
Expand All @@ -127,9 +151,13 @@ mod tests {
</t:Message>
"#;

let offset = FixedOffset::east(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::east_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);
let m = Message {
created_at: DateTimeStamp::from_chrono_datetime(dt),
text: "Hello world".to_string(),
Expand All @@ -148,9 +176,13 @@ mod tests {
"#;
let m: Message = yaserde::de::from_str(s).unwrap();

let offset = FixedOffset::west(6 * 3600 + 30 * 60);
let dt_utc = NaiveDate::from_ymd(2020, 3, 7).and_hms(4, 40, 0) - offset;
let dt = CDateTime::<FixedOffset>::from_utc(dt_utc, offset);
let offset = FixedOffset::west_opt(6 * 3600 + 30 * 60).unwrap();
let dt_utc = NaiveDate::from_ymd_opt(2020, 3, 7)
.unwrap()
.and_hms_opt(4, 40, 0)
.unwrap()
- offset;
let dt = CDateTime::<FixedOffset>::from_naive_utc_and_offset(dt_utc, offset);

assert_eq!(m.created_at.value, DateTime::from_chrono_datetime(dt));
assert_eq!(m.text, "Hello world".to_string());
Expand Down
Loading

0 comments on commit fc82a35

Please sign in to comment.