/// Formats string and evaluates all time expressions enclosed in {..}.
Formats string and evaluates all time expressions enclosed in {..}.
Formats string and evaluates all time expressions enclosed in { .. } .
pub async fn tsfmt(ctx: &Ctx, msg: &Message) -> CommandResult {
    let mut args = Args::new(&msg.content_safe(&ctx.cache), &[Delimiter::Single(' ')]);
    args.trimmed();
    args.advance();
    let timezone = args.single::<String>()?;
    let timezone = match try_get_timezone(&timezone) {
        Ok(tz) => tz,
        Err(e) => {
            msg.reply(
                &ctx.http,
                MessageBuilder::new().push_codeblock(e, None).build(),
            )
            .await?;
            return Ok(());
        }
    };
    let text = match args.remains() {
        Some(t) => t,
        None => return Ok(()),
    };
    let formatted_string = TS_FMT_RGX.replace_all(text, |caps: &Captures| {
        let time = match try_parse_written_time_with_tz(&caps[1], timezone) {
            Ok(time) => time,
            Err(_) => return "INVALID FORMAT".to_string(),
        };
        let fmt = if let Some(format) = caps.get(2) {
            TimestampFormat::from_modifier(format.as_str()).unwrap_or(TimestampFormat::Full)
        } else {
            TimestampFormat::Full
        };
        fmt.parse_timestamp(time.timestamp())
    });
    msg.reply(
        &ctx.http,
        MessageBuilder::new()
            .push_codeblock(formatted_string.clone(), None)
            .push(formatted_string)
            .build(),
    )
    .await?;
    Ok(())
}
pub async fn tsfmt ( ctx : & Ctx , msg : & Message ) -> CommandResult { let mut args = Args :: new ( & msg . content_safe ( & ctx . cache ) , & [ Delimiter :: Single ( ' ' ) ] ) ; args . trimmed ( ) ; args . advance ( ) ; let timezone = args . single :: < String > ( ) ? ; let timezone = match try_get_timezone ( & timezone ) { Ok ( tz ) => tz , Err ( e ) => { msg . reply ( & ctx . http , MessageBuilder :: new ( ) . push_codeblock ( e , None ) . build ( ) , ) . await ? ; return Ok ( ( ) ) ; } } ; let text = match args . remains ( ) { Some ( t ) => t , None => return Ok ( ( ) ) , } ; let formatted_string = TS_FMT_RGX . replace_all ( text , | caps : & Captures | { let time = match try_parse_written_time_with_tz ( & caps [ 1 ] , timezone ) { Ok ( time ) => time , Err ( _ ) => return " " . to_string ( ) , } ; let fmt = if let Some ( format ) = caps . get ( 2 ) { TimestampFormat :: from_modifier ( format . as_str ( ) ) . unwrap_or ( TimestampFormat :: Full ) } else { TimestampFormat :: Full } ; fmt . parse_timestamp ( time . timestamp ( ) ) } ) ; msg . reply ( & ctx . http , MessageBuilder :: new ( ) . push_codeblock ( formatted_string . clone ( ) , None ) . push ( formatted_string ) . build ( ) , ) . await ? ; Ok ( ( ) ) }
Formats string and evaluates all time expressions enclosed in {..}.
Formats string and evaluates all time expressions enclosed in { .. } .
ctx
&Ctx
msg
&Message