fn format_time_helper(h: &Helper<'_, '_>, out: &mut dyn Output) -> HelperResult {
    // Extract the input parameter
    let input: &str = h
        .param(0)
        // Convert to string
        .and_then(|p| p.value().as_str())
        // Error on no input
        .ok_or(RenderError::new(
            "format_time helper expects one string parameter.",
        ))?;

    // Try to parse a timestamp
    if let Ok(timestamp) = input.parse::<DateTime<Local>>() {
        let formatted: String = timestamp
            // Format date.
            .format("%_I:%M %P")
            .to_string();
        out.write(formatted.as_str())?;
        return Ok(());
    }

    // Next try a naive timestamp
    if let Ok(timestamp) = input.parse::<NaiveDateTime>() {
        let formatted: String = timestamp.format("%_I:%M %P").to_string();
        out.write(formatted.as_str())?;
        return Ok(());
    }

    // Lastly try just a time.
    let formatted: String = input
        .parse::<NaiveTime>()
        // Convert and propagate error if necessary
        .map_err(|_| RenderError::new("format_time helper expects a date or timestamp"))?
        // Format the time.
        .format("%_I:%M %P")
        .to_string();
    out.write(formatted.as_str())?;
    Ok(())
}
/// Handlebars helper to format time information.
Handlebars helper to format time information.
Handlebars helper to format time information .
fn format_time_helper(h: &Helper<'_, '_>, out: &mut dyn Output) -> HelperResult {
    // Extract the input parameter
    let input: &str = h
        .param(0)
        // Convert to string
        .and_then(|p| p.value().as_str())
        // Error on no input
        .ok_or(RenderError::new(
            "format_time helper expects one string parameter.",
        ))?;
    // Try to parse a timestamp
    if let Ok(timestamp) = input.parse::<DateTime<Local>>() {
        let formatted: String = timestamp
            // Format date.
            .format("%_I:%M %P")
            .to_string();
        out.write(formatted.as_str())?;
        return Ok(());
    }
    // Next try a naive timestamp
    if let Ok(timestamp) = input.parse::<NaiveDateTime>() {
        let formatted: String = timestamp.format("%_I:%M %P").to_string();
        out.write(formatted.as_str())?;
        return Ok(());
    }
    // Lastly try just a time.
    let formatted: String = input
        .parse::<NaiveTime>()
        // Convert and propagate error if necessary
        .map_err(|_| RenderError::new("format_time helper expects a date or timestamp"))?
        // Format the time.
        .format("%_I:%M %P")
        .to_string();
    out.write(formatted.as_str())?;
    Ok(())
}
fn format_time_helper ( h : & Helper < ' _ , ' _ > , out : & mut dyn Output ) -> HelperResult { // Extract the input parameter let input : & str = h . param ( 0 ) // Convert to string . and_then ( | p | p . value ( ) . as_str ( ) ) // Error on no input . ok_or ( RenderError :: new ( " " , ) ) ? ; // Try to parse a timestamp if let Ok ( timestamp ) = input . parse :: < DateTime < Local > > ( ) { let formatted : String = timestamp // Format date. . format ( " " ) . to_string ( ) ; out . write ( formatted . as_str ( ) ) ? ; return Ok ( ( ) ) ; } // Next try a naive timestamp if let Ok ( timestamp ) = input . parse :: < NaiveDateTime > ( ) { let formatted : String = timestamp . format ( " " ) . to_string ( ) ; out . write ( formatted . as_str ( ) ) ? ; return Ok ( ( ) ) ; } // Lastly try just a time. let formatted : String = input . parse :: < NaiveTime > ( ) // Convert and propagate error if necessary . map_err ( | _ | RenderError :: new ( " " ) ) ? // Format the time. . format ( " " ) . to_string ( ) ; out . write ( formatted . as_str ( ) ) ? ; Ok ( ( ) ) }
Handlebars helper to format time information.
Handlebars helper to format time information .
h
&Helper<'_, '_>
out
&mut dyn Output
h
&Helper<'_, '_>
out
&mut dyn Output