Merge pull request #12646 from zmstone/0304-rule-engin-func-fix-zone-shift-in-date-string-parse

fix(rule_func): time zone shift at wrong precision
This commit is contained in:
Zaiming (Stone) Shi 2024-03-06 13:22:30 +01:00 committed by GitHub
commit fc8b5d4522
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View File

@ -1181,7 +1181,18 @@ t_parse_date_errors(_) ->
?assertEqual(
UnixTsLeap2,
emqx_rule_funcs:date_to_unix_ts(second, <<"%Y-%m-%d %H:%M:%S">>, <<"2024-03-04 06:56:27">>)
).
),
%% None zero zone shift with millisecond level precision
Tz1 = calendar:rfc3339_to_system_time("2024-02-23T15:00:00.123+08:00", [{unit, second}]),
?assertEqual(
Tz1,
emqx_rule_funcs:date_to_unix_ts(
second, <<"%Y-%m-%d %H:%M:%S.%3N%:z">>, <<"2024-02-23 15:00:00.123+08:00">>
)
),
ok.
%%------------------------------------------------------------------------------
%% Utility functions

View File

@ -507,7 +507,7 @@ do_parse(DateStr, Unit, Formatter) ->
(nanosecond, V, Res) ->
Res + V;
(parsed_offset, V, Res) ->
Res - V
Res - V * Precise
end,
Count = maps:fold(Counter, 0, DateInfo) - (?SECONDS_PER_DAY * Precise),
erlang:convert_time_unit(Count, PrecisionUnit, Unit).

View File

@ -0,0 +1,3 @@
Fix rule engine date time string parser.
Prior to this fix, time zone shift can only work when date time string is at second level precision.