add since field

This commit is contained in:
Mylloon 2024-12-16 02:32:59 +01:00
parent b1d8500611
commit cfbf5dc609
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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()
},
})
}