diff --git a/modules/timestamp/tests/test_format_date.c b/modules/timestamp/tests/test_format_date.c index 0effb9bd23d..17617f836f7 100644 --- a/modules/timestamp/tests/test_format_date.c +++ b/modules/timestamp/tests/test_format_date.c @@ -81,6 +81,11 @@ Test(format_date, test_format_date_with_timestamp_argument_formats_it_using_strf assert_template_format("$(format-date %Y-%m-%dT%H:%M:%S 1667500613)", "2022-11-03T19:36:53"); } +Test(format_date, test_format_date_with_timestamp_argument_using_fractions_and_timezone_works) +{ + assert_template_format("$(format-date %Y-%m-%dT%H:%M:%S 1667500613.613+05:00)", "2022-11-03T23:36:53"); +} + Test(format_date, test_format_date_with_time_zone_option_overrrides_timezone) { assert_template_format("$(format-date --time-zone PST8PDT %Y-%m-%dT%H:%M:%S 1667500613)", "2022-11-03T11:36:53"); diff --git a/modules/timestamp/tf-format-date.c b/modules/timestamp/tf-format-date.c index a67f4a18068..37b6c1958df 100644 --- a/modules/timestamp/tf-format-date.c +++ b/modules/timestamp/tf-format-date.c @@ -117,11 +117,12 @@ tf_format_date_call(LogTemplateFunction *self, gpointer s, const LogTemplateInvo if (state->super.argc != 0) { const gchar *ts = args->argv[0]->str; - if (!type_cast_to_datetime_msec(ts, &msec, NULL)) - msec = 0; - ut.ut_sec = msec / 1000; - ut.ut_usec = (msec % 1000) * 1000; - ut.ut_gmtoff = -1; + if (!type_cast_to_datetime_unixtime(ts, &ut, NULL)) + { + ut.ut_sec = 0; + ut.ut_usec = 0; + ut.ut_gmtoff = -1; + } } else {