diff --git a/Cargo.toml b/Cargo.toml index 6525762d..afb9445a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ sea-orm-migration = { version = "1.1.0", features = [ "sqlx-sqlite" ] } serde_json = "1.0.134" +chrono-humanize = "0.2.3" [expand] color = "always" diff --git a/src/view_model/ingestion.rs b/src/view_model/ingestion.rs index a92d5826..ffadb394 100644 --- a/src/view_model/ingestion.rs +++ b/src/view_model/ingestion.rs @@ -2,6 +2,8 @@ use crate::lib::dosage::Dosage; use crate::lib::formatter::Formatter; use crate::lib::orm::ingestion; use crate::lib::route_of_administration::RouteOfAdministrationClassification; +use chrono::TimeZone; +use chrono_humanize::HumanTime; use core::convert::From; use serde::Deserialize; use serde::Serialize; @@ -30,13 +32,15 @@ impl From for ViewModel let dosage = Dosage::from_base_units(model.dosage.into()); let route_enum: RouteOfAdministrationClassification = model.route_of_administration.parse().unwrap_or_default(); + let local_ingestion_date = + chrono::Local::from_utc_datetime(&chrono::Local, &model.ingested_at); Self::builder() .id(model.id) .substance_name(model.substance_name) .route(route_enum.to_string()) .dosage(dosage.to_string()) - .ingested_at(model.ingested_at.to_string()) + .ingested_at(HumanTime::from(local_ingestion_date).to_string()) .build() } } @@ -45,6 +49,7 @@ impl Display for ViewModel { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // TODO: Implement formatter for pretty and json let table = Table::new(vec![self]).to_string(); f.write_str(table.as_ref()) }