Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rule_func): time zone shift at wrong precision #12646

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/emqx_rule_engine/test/emqx_rule_funcs_SUITE.erl
Expand Up @@ -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}]),
qzhuyan marked this conversation as resolved.
Show resolved Hide resolved
?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
Expand Down
2 changes: 1 addition & 1 deletion apps/emqx_utils/src/emqx_utils_calendar.erl
Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions changes/ce/fix-12646.en.md
@@ -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.