diff --git a/cli/src/template_builder.rs b/cli/src/template_builder.rs index 7dbb31877..ad62aeb25 100644 --- a/cli/src/template_builder.rs +++ b/cli/src/template_builder.rs @@ -665,8 +665,10 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a>>( let mut map = TemplateBuildMethodFnMap::::new(); map.insert("ago", |language, _build_ctx, self_property, function| { template_parser::expect_no_arguments(function)?; - let out_property = TemplateFunction::new(self_property, |timestamp| { - Ok(time_util::format_timestamp_relative_to_now(×tamp)) + let now = Timestamp::now(); + let format = timeago::Formatter::new(); + let out_property = TemplateFunction::new(self_property, move |timestamp| { + Ok(time_util::format_duration(×tamp, &now, &format)) }); Ok(language.wrap_string(out_property)) }); diff --git a/cli/src/time_util.rs b/cli/src/time_util.rs index d5a0fabec..fbffe34b4 100644 --- a/cli/src/time_util.rs +++ b/cli/src/time_util.rs @@ -81,7 +81,3 @@ pub fn format_duration(from: &Timestamp, to: &Timestamp, format: &timeago::Forma .map(|duration| format.convert(duration)) .unwrap_or_else(|| "".to_string()) } - -pub fn format_timestamp_relative_to_now(timestamp: &Timestamp) -> String { - format_duration(timestamp, &Timestamp::now(), &timeago::Formatter::new()) -}