Some refactoring

This commit is contained in:
2020-10-30 23:20:24 +01:00
parent fe5cd04506
commit 24f3d69301
11 changed files with 241 additions and 182 deletions

View File

@ -1,13 +1,26 @@
use rocket_contrib::templates::Engines;
use chrono::NaiveDateTime;
use handlebars::handlebars_helper;
use rocket_contrib::templates::Engines;
pub fn register_helpers(engines: &mut Engines) {
handlebars_helper!(pretty_datetime: |dt: str| {
let date = dt.trim_end_matches(|c| c != 'T').trim_end_matches('T');
let time = dt.trim_start_matches(|c| c != 'T').trim_start_matches('T')
.trim_end_matches(|c| c != ':').trim_end_matches(':');
format!("{} {}", date, time)
let dt: NaiveDateTime = dt.parse().unwrap();
format!("{}", dt.format("%Y-%m-%d %H:%M"))
});
engines
.handlebars
.register_helper("pretty_datetime", Box::new(pretty_datetime));
engines.handlebars.register_helper("pretty_datetime", Box::new(pretty_datetime));
handlebars_helper!(pretty_seconds: |secs: u64| {
let minutes = secs / 60;
let hours = minutes / 60;
if hours > 0 {
format!("{}h {}m", hours, minutes)
} else {
format!("{}m", minutes)
}
});
engines
.handlebars
.register_helper("pretty_seconds", Box::new(pretty_seconds));
}