Files
stl/src/handlebars_util.rs
Joakim Hulthe a85d43b35d Update database schema
Also bump major version to match schema version
2020-11-09 17:44:28 +01:00

27 lines
799 B
Rust

use chrono::{DateTime, Local};
use handlebars::handlebars_helper;
use rocket_contrib::templates::Engines;
pub fn register_helpers(engines: &mut Engines) {
handlebars_helper!(pretty_datetime: |dt: str| {
let dt: DateTime<Local> = dt.parse().unwrap();
format!("{}", dt.format("%Y-%m-%d %H:%M"))
});
engines
.handlebars
.register_helper("pretty_datetime", Box::new(pretty_datetime));
handlebars_helper!(pretty_seconds: |secs: u64| {
let hours = secs / 60 / 60;
let minutes = secs / 60 % 60;
if hours > 0 {
format!("{}h {}m", hours, minutes)
} else {
format!("{}m", minutes)
}
});
engines
.handlebars
.register_helper("pretty_seconds", Box::new(pretty_seconds));
}