fn format_date_helper(h: &Helper<'_, '_>, out: &mut dyn Output) -> HelperResult {
    // Get the first parameter.
    let input: &str = h
        .param(0)
        // Get the value of the parameter
        .and_then(|param| param.value().as_str())
        // Handle missing parameter.
        .ok_or(RenderError::new(
            "format_date helper requires one string parameter",
        ))?;

    // If the input is a timestamp with timezone
    if let Ok(timestamp) = input.parse::<DateTime<Local>>() {
        // Format the date properly.
        let formatted: String = timestamp
            // Format
            .format("%B %_d, %Y")
            .to_string();
        // Write to output and return.
        out.write(formatted.as_str())?;
        return Ok(());
    }

    // If the input is a naive timestamp
    if let Ok(timestamp) = input.parse::<NaiveDateTime>() {
        let formatted: String = timestamp.format("%B %_d, %Y").to_string();
        out.write(formatted.as_str())?;
        return Ok(());
    }

    // If the input is just a date
    let formatted = input
        .parse::<NaiveDate>()
        // If it fails to parse, the parameter is malformed.
        .map_err(|_| RenderError::new("format_date helper expects date or timestamp"))?
        // Format
        .format("%B %_d, %Y")
        // Convert to string.
        .to_string();
    // Write to output
    out.write(formatted.as_str())?;
    // Return ok
    Ok(())
}
/// Handlebars helper to format dates. This should be able to accept a value of
/// either a date or a timestamp or a timestamp with timezone, and format the date
/// as "Month Day, Year".
Handlebars helper to format dates. This should be able to accept a value of
either a date or a timestamp or a timestamp with timezone, and format the date
as "Month Day, Year".
Handlebars helper to format dates . This should be able to accept a value of either a date or a timestamp or a timestamp with timezone and format the date as " Month Day Year " .
fn format_date_helper(h: &Helper<'_, '_>, out: &mut dyn Output) -> HelperResult {
    // Get the first parameter.
    let input: &str = h
        .param(0)
        // Get the value of the parameter
        .and_then(|param| param.value().as_str())
        // Handle missing parameter.
        .ok_or(RenderError::new(
            "format_date helper requires one string parameter",
        ))?;
    // If the input is a timestamp with timezone
    if let Ok(timestamp) = input.parse::<DateTime<Local>>() {
        // Format the date properly.
        let formatted: String = timestamp
            // Format
            .format("%B %_d, %Y")
            .to_string();
        // Write to output and return.
        out.write(formatted.as_str())?;
        return Ok(());
    }
    // If the input is a naive timestamp
    if let Ok(timestamp) = input.parse::<NaiveDateTime>() {
        let formatted: String = timestamp.format("%B %_d, %Y").to_string();
        out.write(formatted.as_str())?;
        return Ok(());
    }
    // If the input is just a date
    let formatted = input
        .parse::<NaiveDate>()
        // If it fails to parse, the parameter is malformed.
        .map_err(|_| RenderError::new("format_date helper expects date or timestamp"))?
        // Format
        .format("%B %_d, %Y")
        // Convert to string.
        .to_string();
    // Write to output
    out.write(formatted.as_str())?;
    // Return ok
    Ok(())
}
fn format_date_helper ( h : & Helper < ' _ , ' _ > , out : & mut dyn Output ) -> HelperResult { // Get the first parameter. let input : & str = h . param ( 0 ) // Get the value of the parameter . and_then ( | param | param . value ( ) . as_str ( ) ) // Handle missing parameter. . ok_or ( RenderError :: new ( " " , ) ) ? ; // If the input is a timestamp with timezone if let Ok ( timestamp ) = input . parse :: < DateTime < Local > > ( ) { // Format the date properly. let formatted : String = timestamp // Format . format ( " " ) . to_string ( ) ; // Write to output and return. out . write ( formatted . as_str ( ) ) ? ; return Ok ( ( ) ) ; } // If the input is a naive timestamp if let Ok ( timestamp ) = input . parse :: < NaiveDateTime > ( ) { let formatted : String = timestamp . format ( " " ) . to_string ( ) ; out . write ( formatted . as_str ( ) ) ? ; return Ok ( ( ) ) ; } // If the input is just a date let formatted = input . parse :: < NaiveDate > ( ) // If it fails to parse, the parameter is malformed. . map_err ( | _ | RenderError :: new ( " " ) ) ? // Format . format ( " " ) // Convert to string. . to_string ( ) ; // Write to output out . write ( formatted . as_str ( ) ) ? ; // Return ok Ok ( ( ) ) }
Handlebars helper to format dates.
Handlebars helper to format dates .
h
&Helper<'_, '_>
out
&mut dyn Output
h
&Helper<'_, '_>
out
&mut dyn Output