diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/macro_processor/macro_processor.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/macro_processor/macro_processor.rs b/src/macro_processor/macro_processor.rs index 7eb41cf..a5b6a59 100644 --- a/src/macro_processor/macro_processor.rs +++ b/src/macro_processor/macro_processor.rs @@ -218,6 +218,20 @@ fn smp_builtin_indent( Ok(String::new()) } +#[cfg(feature = "time")] +fn smp_builtin_format_time( + _smp: &mut MacroProcessor, + macro_name: &str, + args: &mut [String], +) -> Result<String, SMPError> { + if args.len() < 2 { + return Ok(macro_name.to_string()); + } + let dt = chrono::DateTime::parse_from_rfc3339(&args[1]) + .map_err(|_| SMPError::UnknownError(87, None))?; + Ok(format!("{}", dt.format(&args[0]))) +} + /// Types of macros, this is to make it easy to store both functions and strings #[derive(Clone)] pub enum MacroType { @@ -296,6 +310,11 @@ impl MacroProcessor { MacroType::Function(smp_builtin_indent), ); self.define_macro(String::from("expr"), MacroType::Function(smp_builtin_expr)); + #[cfg(feature = "time")] + self.define_macro( + String::from("format_time"), + MacroType::Function(smp_builtin_format_time), + ); // format('Result id %d', 3282) } |