From cfbf5dc609a572743aba72ced66175bc25d3b9c6 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 16 Dec 2024 02:32:59 +0100 Subject: [PATCH] add since field --- src/routes/api_v1.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/routes/api_v1.rs b/src/routes/api_v1.rs index a895739..aa90722 100644 --- a/src/routes/api_v1.rs +++ b/src/routes/api_v1.rs @@ -8,13 +8,22 @@ use serde::Serialize; /// Response for /love #[derive(Serialize)] struct InfoLove { - unix_epoch: u32, + unix_epoch: u64, + since: String, } #[get("/love")] pub async fn love() -> impl Responder { + let target = 1_605_576_600; + let current_time: u64 = Utc::now().timestamp().try_into().unwrap(); + HttpResponse::Ok().json(InfoLove { - unix_epoch: 1_605_576_600, + unix_epoch: target, + since: { + let duration_epoch = current_time - target; + let duration = Duration::from_secs(duration_epoch); + format_duration(duration).to_string() + }, }) }