Skip to content

Commit 3b179fb

Browse files
convert timestamp to rfc3339
1 parent 0322632 commit 3b179fb

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/private/storj/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use admin::AdminCanisters;
1414
use anyhow::Context;
1515
use anyhow::Result;
1616
use chrono::{DateTime, Utc};
17-
use futures::{StreamExt, TryStreamExt};
17+
use futures::TryStreamExt;
1818
use ic_agent::Agent;
1919
use nsfw::IsNsfw;
2020
use redis::{aio::MultiplexedConnection, AsyncCommands, JsonAsyncCommands};

src/private/storj/posts.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::{collections::BTreeMap, sync::Arc};
1+
use std::{collections::BTreeMap, sync::Arc, time::UNIX_EPOCH};
22

33
use anyhow::Context;
44
use candid::Principal;
5-
use chrono::{DateTime, Utc};
5+
use chrono::{DateTime, NaiveDateTime, Utc};
66
use futures::{future, stream, StreamExt, TryStreamExt};
77
use serde::{Deserialize, Serialize};
88
use yral_canisters_client::individual_user_template::{
9-
GetPostsOfUserProfileError, IndividualUserTemplate, PostDetailsForFrontend, SystemTime,
9+
GetPostsOfUserProfileError, IndividualUserTemplate, PostDetailsForFrontend,
1010
};
1111

1212
use super::{
@@ -20,7 +20,7 @@ pub(crate) struct Item {
2020
pub(crate) publisher_user_id: String,
2121
pub(crate) post_id: u64,
2222
pub(crate) canister_id: Principal,
23-
pub(crate) timestamp: SystemTime,
23+
pub(crate) timestamp: String,
2424
pub(crate) is_nsfw: IsNsfw, // TODO: extra metadata
2525
}
2626

@@ -58,6 +58,12 @@ async fn load_all_posts(
5858
Ok(posts)
5959
}
6060

61+
fn nanos_to_rfc3339(secs: i64, subsec_nanos: u32) -> String {
62+
let time = DateTime::from_timestamp(secs, subsec_nanos).unwrap();
63+
64+
time.to_rfc3339()
65+
}
66+
6167
pub(crate) async fn load_items<'a>(
6268
admin: Arc<AdminCanisters>,
6369
low_pass: DateTime<Utc>,
@@ -124,7 +130,10 @@ pub(crate) async fn load_items<'a>(
124130
.try_flatten_unordered(None)
125131
.map(|post| {
126132
post.map(|(canister, is_nsfw, post)| Item {
127-
timestamp: post.created_at,
133+
timestamp: nanos_to_rfc3339(
134+
post.created_at.secs_since_epoch as i64,
135+
post.created_at.nanos_since_epoch,
136+
),
128137
video_id: post.video_uid,
129138
publisher_user_id: post.created_by_user_principal_id.to_text(),
130139
canister_id: canister,

0 commit comments

Comments
 (0)