Skip to content

Commit

Permalink
add humanized ingestion date display
Browse files Browse the repository at this point in the history
add `chrono_humanize` and humanize local DateTime value into relative time since ingestion, handling differences between different timezones. #NEU-8
  • Loading branch information
keinsell committed Jan 6, 2025
1 parent 9bb5cab commit da50fc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion src/view_model/ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -30,13 +32,15 @@ impl From<ingestion::Model> 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()
}
}
Expand Down

0 comments on commit da50fc8

Please sign in to comment.