42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use chrono::{DateTime, Local};
|
|
use handlebars::handlebars_helper;
|
|
use rocket_dyn_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_compact_seconds: |secs: u64| {
|
|
let hours = secs / 60 / 60;
|
|
let minutes = secs / 60 % 60;
|
|
if hours == 0 {
|
|
format!("{}m", minutes)
|
|
} else {
|
|
format!("{}h", hours)
|
|
}
|
|
});
|
|
engines
|
|
.handlebars
|
|
.register_helper("pretty_compact_seconds", Box::new(pretty_compact_seconds));
|
|
|
|
handlebars_helper!(pretty_seconds: |secs: u64| {
|
|
let hours = secs / 60 / 60;
|
|
let minutes = secs / 60 % 60;
|
|
if hours == 0 {
|
|
format!("{}m", minutes)
|
|
} else if minutes == 0 {
|
|
format!("{}h", hours)
|
|
} else {
|
|
format!("{}h {}m", hours, minutes)
|
|
}
|
|
});
|
|
engines
|
|
.handlebars
|
|
.register_helper("pretty_seconds", Box::new(pretty_seconds));
|
|
}
|