fix(rule_func): time zone shift at wrong precision
This commit is contained in:
parent
1badbfa81a
commit
9929025820
|
@ -1181,7 +1181,18 @@ t_parse_date_errors(_) ->
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
UnixTsLeap2,
|
UnixTsLeap2,
|
||||||
emqx_rule_funcs:date_to_unix_ts(second, <<"%Y-%m-%d %H:%M:%S">>, <<"2024-03-04 06:56:27">>)
|
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
|
%% Utility functions
|
||||||
|
|
|
@ -507,7 +507,7 @@ do_parse(DateStr, Unit, Formatter) ->
|
||||||
(nanosecond, V, Res) ->
|
(nanosecond, V, Res) ->
|
||||||
Res + V;
|
Res + V;
|
||||||
(parsed_offset, V, Res) ->
|
(parsed_offset, V, Res) ->
|
||||||
Res - V
|
Res - V * Precise
|
||||||
end,
|
end,
|
||||||
Count = maps:fold(Counter, 0, DateInfo) - (?SECONDS_PER_DAY * Precise),
|
Count = maps:fold(Counter, 0, DateInfo) - (?SECONDS_PER_DAY * Precise),
|
||||||
erlang:convert_time_unit(Count, PrecisionUnit, Unit).
|
erlang:convert_time_unit(Count, PrecisionUnit, Unit).
|
||||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue