summaryrefslogtreecommitdiffstats
path: root/adenosine-cli/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-12-19 18:38:10 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-12-19 18:38:10 -0800
commit110d15e345824b57d83d336d55f383509333ae99 (patch)
tree84a474881bb4522122ae1527d3009470d97e4194 /adenosine-cli/src
parent2cbb962c8de81b4af597352fc7e84c9b99e0fc12 (diff)
downloadadenosine-110d15e345824b57d83d336d55f383509333ae99.tar.gz
adenosine-110d15e345824b57d83d336d55f383509333ae99.zip
timestamps: use millisecond precision
Diffstat (limited to 'adenosine-cli/src')
-rw-r--r--adenosine-cli/src/lib.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/adenosine-cli/src/lib.rs b/adenosine-cli/src/lib.rs
index 19ba060..e232667 100644
--- a/adenosine-cli/src/lib.rs
+++ b/adenosine-cli/src/lib.rs
@@ -316,24 +316,28 @@ 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 an RFC 3339 string.
///
-/// Returns something like "2022-11-22T09:21:15Z"
+/// Currently, bluesky PDS expects millisecond precision, so we use that.
+///
+/// Returns something like "2022-11-22T09:21:15.640Z"
pub fn created_at_now() -> String {
- let now = time::OffsetDateTime::now_utc()
- .replace_microsecond(0)
- .unwrap();
+ let now = time::OffsetDateTime::now_utc();
+ // remove microsecond precision, but retain millisecond precision
+ let ms = now.millisecond();
+ let now = now.replace_microsecond(0).unwrap();
+ let now = now.replace_millisecond(ms).unwrap();
now.format(&time::format_description::well_known::Rfc3339)
.unwrap()
}
#[test]
fn test_created_at_now() {
- // eg: 2022-11-22T09:20:44Z
+ // eg: 2022-11-22T09:20:44.123Z
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");
+ assert_eq!(&ts[23..24], "Z");
}