aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-22 01:22:33 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-22 02:01:03 -0800
commit5c01b306219a8eacc4cd69c8e5dcbdc17aec0e53 (patch)
tree36e3bc44fa76a876d911daf7829a60d495576c05
parentadb4ab50062581c60b27ba93a78966514f465557 (diff)
downloadadenosine-5c01b306219a8eacc4cd69c8e5dcbdc17aec0e53.tar.gz
adenosine-5c01b306219a8eacc4cd69c8e5dcbdc17aec0e53.zip
cli: fix created_at_now helper
-rw-r--r--adenosine-cli/src/lib.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/adenosine-cli/src/lib.rs b/adenosine-cli/src/lib.rs
index ce08078..19ba060 100644
--- a/adenosine-cli/src/lib.rs
+++ b/adenosine-cli/src/lib.rs
@@ -316,9 +316,24 @@ pub fn value_from_fields(fields: Vec<ArgField>) -> Value {
Value::Object(serde_json::map::Map::from_iter(map.into_iter()))
}
-/// Helper to generate the current timestamp as right now, UTC, formatted as a string
+/// Helper to generate the current timestamp as right now, UTC, formatted as a string.
+///
+/// Returns something like "2022-11-22T09:21:15Z"
pub fn created_at_now() -> String {
- let now = time::OffsetDateTime::now_utc();
+ let now = time::OffsetDateTime::now_utc()
+ .replace_microsecond(0)
+ .unwrap();
now.format(&time::format_description::well_known::Rfc3339)
.unwrap()
}
+
+#[test]
+fn test_created_at_now() {
+ // eg: 2022-11-22T09:20:44Z
+ let ts = created_at_now();
+ println!("{}", ts);
+ assert_eq!(&ts[4..5], "-");
+ assert_eq!(&ts[7..8], "-");
+ assert_eq!(&ts[10..11], "T");
+ assert_eq!(&ts[19..20], "Z");
+}