diff --git a/apps/emqx/src/emqx.app.src b/apps/emqx/src/emqx.app.src index 2a2b3c323..e156d8cf0 100644 --- a/apps/emqx/src/emqx.app.src +++ b/apps/emqx/src/emqx.app.src @@ -2,8 +2,7 @@ {application, emqx, [ {id, "emqx"}, {description, "EMQX Core"}, - % strict semver, bump manually! - {vsn, "5.0.27"}, + {vsn, "5.1.0"}, {modules, []}, {registered, []}, {applications, [ diff --git a/apps/emqx_ft/src/emqx_ft.app.src b/apps/emqx_ft/src/emqx_ft.app.src index c503ab8e0..74d1b84b7 100644 --- a/apps/emqx_ft/src/emqx_ft.app.src +++ b/apps/emqx_ft/src/emqx_ft.app.src @@ -1,6 +1,6 @@ {application, emqx_ft, [ {description, "EMQX file transfer over MQTT"}, - {vsn, "0.1.1"}, + {vsn, "0.1.2"}, {registered, []}, {mod, {emqx_ft_app, []}}, {applications, [ diff --git a/apps/emqx_rule_engine/src/emqx_rule_funcs.erl b/apps/emqx_rule_engine/src/emqx_rule_funcs.erl index 73e2f78e7..a94aa0c8a 100644 --- a/apps/emqx_rule_engine/src/emqx_rule_funcs.erl +++ b/apps/emqx_rule_engine/src/emqx_rule_funcs.erl @@ -228,7 +228,9 @@ format_date/3, format_date/4, date_to_unix_ts/3, - date_to_unix_ts/4 + date_to_unix_ts/4, + timezone_to_second/1, + timezone_to_offset_seconds/1 ]). %% MongoDB specific date functions. These functions return a date tuple. The @@ -1104,6 +1106,12 @@ date_to_unix_ts(TimeUnit, Offset, FormatString, InputString) -> OffsetDelta = erlang:convert_time_unit(OffsetSecond, second, Unit), date_to_unix_ts(Unit, FormatString, InputString) - OffsetDelta. +timezone_to_second(TimeZone) -> + timezone_to_offset_seconds(TimeZone). + +timezone_to_offset_seconds(TimeZone) -> + emqx_calendar:offset_second(TimeZone). + %% @doc This is for sql funcs that should be handled in the specific modules. %% Here the emqx_rule_funcs module acts as a proxy, forwarding %% the function handling to the worker module. diff --git a/apps/emqx_rule_engine/test/emqx_rule_funcs_SUITE.erl b/apps/emqx_rule_engine/test/emqx_rule_funcs_SUITE.erl index 9bb6e2e6f..12110b206 100644 --- a/apps/emqx_rule_engine/test/emqx_rule_funcs_SUITE.erl +++ b/apps/emqx_rule_engine/test/emqx_rule_funcs_SUITE.erl @@ -1012,6 +1012,25 @@ prop_format_date_fun() -> Args3DTUS = [<<"second">>, <<"+04:00">>, <<"--%m--%d--%Y---%H:%M:%S">>, Formatters3], Second == apply_func(date_to_unix_ts, Args3DTUS). +t_timezone_to_offset_seconds(_) -> + timezone_to_offset_seconds_helper(timezone_to_offset_seconds), + %% The timezone_to_second function is kept for compatibility with 4.X. + timezone_to_offset_seconds_helper(timezone_to_second). + +timezone_to_offset_seconds_helper(FunctionName) -> + ?assertEqual(120 * 60, apply_func(FunctionName, [<<"+02:00:00">>])), + ?assertEqual(-120 * 60, apply_func(FunctionName, [<<"-02:00:00">>])), + ?assertEqual(102, apply_func(FunctionName, [<<"+00:01:42">>])), + ?assertEqual(0, apply_func(FunctionName, [<<"z">>])), + ?assertEqual(0, apply_func(FunctionName, [<<"Z">>])), + ?assertEqual(42, apply_func(FunctionName, [42])), + ?assertEqual(0, apply_func(FunctionName, [undefined])), + %% Check that the following does not crash + apply_func(FunctionName, [<<"local">>]), + apply_func(FunctionName, ["local"]), + apply_func(FunctionName, [local]), + ok. + %%------------------------------------------------------------------------------ %% Utility functions %%------------------------------------------------------------------------------ diff --git a/changes/ce/feat-10858.en.md b/changes/ce/feat-10858.en.md new file mode 100644 index 000000000..1e2fa9fee --- /dev/null +++ b/changes/ce/feat-10858.en.md @@ -0,0 +1 @@ +A new utility function timezone_to_offset_seconds/1 has been added to the rule engine SQL language. This function converts a timezone string (for example, "+02:00", "Z" and "local") to the corresponding offset in seconds.