pub fn seconds_to_duration() -> impl tera::Function {
    Box::new(
        move |args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
            match args.get("seconds") {
                Some(val) => match tera::from_value::<i32>(val.clone()) {
                    Ok(v) => Ok(if v < 0 {
                        tera::to_value("Unknown").unwrap()
                    } else {
                        let d = std::time::Duration::from_secs(v as u64);
                        let seconds = d.as_secs() % 60;
                        let minutes = (d.as_secs() / 60) % 60;
                        let hours = (d.as_secs() / 60) / 60 % 24;
                        let days = (d.as_secs() / 60) / 60 / 24;
                        if days > 0 {
                            tera::to_value(format!(
                                "{}d {}h {}m {}s",
                                days, hours, minutes, seconds
                            ))
                            .unwrap()
                        } else if hours > 0 {
                            tera::to_value(format!("{}h {}m {}s", hours, minutes, seconds)).unwrap()
                        } else if minutes > 0 {
                            tera::to_value(format!("{}m {}s", minutes, seconds)).unwrap()
                        } else {
                            tera::to_value(format!("{}s", seconds)).unwrap()
                        }
                    }),
                    Err(_) => Err("Can't parse 'seconds' as i32.".into()),
                },
                None => Err("No parameter 'seconds' passed to seconds_to_duration()".into()),
            }
        },
    )
}
/// Converts seconds to a duration String.
Converts seconds to a duration String.
Converts seconds to a duration String .
pub fn seconds_to_duration() -> impl tera::Function {
    Box::new(
        move |args: &HashMap<String, tera::Value>| -> tera::Result<tera::Value> {
            match args.get("seconds") {
                Some(val) => match tera::from_value::<i32>(val.clone()) {
                    Ok(v) => Ok(if v < 0 {
                        tera::to_value("Unknown").unwrap()
                    } else {
                        let d = std::time::Duration::from_secs(v as u64);
                        let seconds = d.as_secs() % 60;
                        let minutes = (d.as_secs() / 60) % 60;
                        let hours = (d.as_secs() / 60) / 60 % 24;
                        let days = (d.as_secs() / 60) / 60 / 24;
                        if days > 0 {
                            tera::to_value(format!(
                                "{}d {}h {}m {}s",
                                days, hours, minutes, seconds
                            ))
                            .unwrap()
                        } else if hours > 0 {
                            tera::to_value(format!("{}h {}m {}s", hours, minutes, seconds)).unwrap()
                        } else if minutes > 0 {
                            tera::to_value(format!("{}m {}s", minutes, seconds)).unwrap()
                        } else {
                            tera::to_value(format!("{}s", seconds)).unwrap()
                        }
                    }),
                    Err(_) => Err("Can't parse 'seconds' as i32.".into()),
                },
                None => Err("No parameter 'seconds' passed to seconds_to_duration()".into()),
            }
        },
    )
}
pub fn seconds_to_duration ( ) -> impl tera :: Function { Box :: new ( move | args : & HashMap < String , tera :: Value > | -> tera :: Result < tera :: Value > { match args . get ( " " ) { Some ( val ) => match tera :: from_value :: < i32 > ( val . clone ( ) ) { Ok ( v ) => Ok ( if v < 0 { tera :: to_value ( " " ) . unwrap ( ) } else { let d = std :: time :: Duration :: from_secs ( v as u64 ) ; let seconds = d . as_secs ( ) % 60 ; let minutes = ( d . as_secs ( ) / 60 ) % 60 ; let hours = ( d . as_secs ( ) / 60 ) / 60 % 24 ; let days = ( d . as_secs ( ) / 60 ) / 60 / 24 ; if days > 0 { tera :: to_value ( format ! ( " " days hours minutes seconds ) ) . unwrap ( ) } else if hours > 0 { tera :: to_value ( format ! ( " " hours minutes seconds ) ) . unwrap ( ) } else if minutes > 0 { tera :: to_value ( format ! ( " " minutes seconds ) ) . unwrap ( ) } else { tera :: to_value ( format ! ( " " seconds ) ) . unwrap ( ) } } ) , Err ( _ ) => Err ( " " . into ( ) ) , } , None => Err ( " " . into ( ) ) , } } , ) }
Converts seconds to a duration String.
Converts seconds to a duration String .