diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2024-11-04 17:47:20 +0100 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2024-11-04 17:47:20 +0100 |
| commit | 56233352feb78ec6da39d8ab7734102abae1e4ed (patch) | |
| tree | 9792970aa7f77e19c3bae0a86d17b1d241289059 /src/handlers/frontend_builder.rs | |
| parent | fa7f650562337c7f3a4fb7446e56575e26380494 (diff) | |
Feat: Add date formatting
Diffstat (limited to 'src/handlers/frontend_builder.rs')
| -rw-r--r-- | src/handlers/frontend_builder.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/handlers/frontend_builder.rs b/src/handlers/frontend_builder.rs index bac9f22..4a9ea67 100644 --- a/src/handlers/frontend_builder.rs +++ b/src/handlers/frontend_builder.rs @@ -1,5 +1,6 @@ use axum::response::IntoResponse; use axum::Extension; +use chrono::DateTime; use maud::{html, Markup, DOCTYPE}; use crate::db::product::{get_all_specificproducts, ProductMarker, SpecificProduct}; @@ -57,6 +58,14 @@ fn cards<T: PageBuilder + ProductMarker>( } fn card<T: PageBuilder + ProductMarker>(specific_product: SpecificProduct<T>) -> Markup { + let date = |i: i64| -> String { + if let Some(datetime) = DateTime::from_timestamp(i / 1_000, 0) { + return format!("{}", datetime.format("%Y/%m/%d")).to_string(); + } + "Unknown".to_string() + }; + let upload_date = date(specific_product.product.uploaddate); + let update_date = date(specific_product.product.updatedate); html!( div class="p-9 shadow" { h2 class="text-[#601B69] dark:text-[#E1B1E7]" { @@ -69,8 +78,10 @@ fn card<T: PageBuilder + ProductMarker>(specific_product: SpecificProduct<T>) -> (specific_product.detail.product_specific_card_content()) } div class="flex flex-row space-x-5 mt-9 text-xs" { - span {"Update: " (specific_product.product.updatedate)} - span {"Upload: " (specific_product.product.uploaddate)} + span {"Upload: " (upload_date)} + @if upload_date != update_date { + span {"Update: " (update_date)} + } } } ) |
