Skip to content

Commit

Permalink
Add test_chrono
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 25, 2024
1 parent ea88088 commit 9c7e1c3
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 0 deletions.
283 changes: 283 additions & 0 deletions v4-sign/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions v4-sign/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = "0.4.35"

[dev-dependencies]
anyhow = "1.0.81"
13 changes: 13 additions & 0 deletions v4-sign/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ mod tests {
"%3F%3D%21%23%24%26%27%28%29%2A%2B%2C%3A%3B%40%5B%5D%22"
);
}

#[test]
fn test_chrono() -> anyhow::Result<()> {
let date_time =
chrono::DateTime::<chrono::FixedOffset>::parse_from_rfc3339("2020-01-02T03:04:05Z")?
.naive_utc()
.and_utc();
let date = date_time.format("%Y%m%d").to_string();
let x_goog_date = date_time.format("%Y%m%dT%H%M%SZ").to_string();
assert_eq!(date, "20200102");
assert_eq!(x_goog_date, "20200102T030405Z");
Ok(())
}
}

0 comments on commit 9c7e1c3

Please sign in to comment.