diff --git a/src/routes/api_v1.rs b/src/routes/api_v1.rs index 3dbf453..a895739 100644 --- a/src/routes/api_v1.rs +++ b/src/routes/api_v1.rs @@ -23,25 +23,36 @@ pub async fn love() -> impl Responder { struct InfoBTF { unix_epoch: u64, countdown: String, + since: String, } #[get("/backtofrance")] pub async fn btf() -> impl Responder { let target = 1_736_618_100; + let start = 1_724_832_000; let current_time: u64 = Utc::now().timestamp().try_into().unwrap(); - let info = InfoBTF { - unix_epoch: target, - countdown: if current_time > target { - "Already happened".to_owned() - } else { - let duration_epoch = target - current_time; - let duration = Duration::from_secs(duration_epoch); - format_duration(duration).to_string() - }, - }; - - HttpResponse::Ok().json(info) + if current_time > target { + HttpResponse::Ok().json(InfoBTF { + unix_epoch: target, + countdown: "Already happened".to_owned(), + since: "Not relevant anymore".to_owned(), + }) + } else { + HttpResponse::Ok().json(InfoBTF { + unix_epoch: target, + countdown: { + let duration_epoch = target - current_time; + let duration = Duration::from_secs(duration_epoch); + format_duration(duration).to_string() + }, + since: { + let duration_epoch = current_time - start; + let duration = Duration::from_secs(duration_epoch); + format_duration(duration).to_string() + }, + }) + } } #[get("/websites")]