]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move %nextime() to %time.next()
authorAlan T. DeKok <aland@freeradius.org>
Wed, 7 May 2025 14:49:00 +0000 (10:49 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 7 May 2025 15:38:10 +0000 (11:38 -0400)
doc/antora/modules/reference/pages/xlat/builtin.adoc
src/lib/unlang/xlat_builtin.c
src/tests/keywords/nexttime

index 6912eb24a95e5d29fe6848adfd67f1672456cefa..760ed0e21aeb2e0cdf482c687aaf0e7d0881b0b4 100644 (file)
@@ -162,7 +162,7 @@ bob
 not bob!
 ```
 
-=== %nexttime(<time>)
+=== %time.next(<time>)
 
 Calculate number of seconds until next n hour(`s`), day(`s`), week(`s`), year(`s`).
 
@@ -170,11 +170,11 @@ Calculate number of seconds until next n hour(`s`), day(`s`), week(`s`), year(`s
 
 .Example
 
-With the current time at 16:18, `%nexttime(1h)` will expand to `2520`.
+With the current time at 16:18, `%time.next(1h)` will expand to `2520`.
 
 [source,unlang]
 ----
-reply.Reply-Message := "You should wait for %nexttime(1h)s"
+reply.Reply-Message := "You should wait for %time.next(1h)s"
 ----
 
 .Output
@@ -323,7 +323,7 @@ group {
 ----
 
 This kind of math works well for "tomorrow", but it is less useful for
-"next week Monday", or "start of next month".  The `%nexttime(...)`
+"next week Monday", or "start of next month".  The `%time.next(...)`
 expansion above should be used for those time operations.
 
 // Copyright (C) 2023 Network RADIUS SAS.  Licenced under CC-by-NC 4.0.
index 5a4b5ab70fe9bb501ee02a69e1c1c51741157106..2221dc49ab0d9946de608846ded07fffa8583236 100644 (file)
@@ -1344,7 +1344,7 @@ static xlat_arg_parser_t const xlat_func_next_time_args[] = {
 
 /** Calculate number of seconds until the next n hour(s), day(s), week(s), year(s).
  *
- * For example, if it were 16:18 %nexttime(1h) would expand to 2520.
+ * For example, if it were 16:18 %time.next(1h) would expand to 2520.
  *
  * The envisaged usage for this function is to limit sessions so that they don't
  * cross billing periods. The output of the xlat should be combined with %rand() to create
@@ -1378,7 +1378,7 @@ static xlat_action_t xlat_func_next_time(TALLOC_CTX *ctx, fr_dcursor_t *out,
 
        num = strtoul(p, &q, 10);
        if (!q || *q == '\0') {
-               REDEBUG("nexttime: <int> must be followed by period specifier (h|d|w|m|y)");
+               REDEBUG("<int> must be followed by time period (h|d|w|m|y)");
                return XLAT_ACTION_FAIL;
        }
 
@@ -1420,7 +1420,7 @@ static xlat_action_t xlat_func_next_time(TALLOC_CTX *ctx, fr_dcursor_t *out,
                break;
 
        default:
-               REDEBUG("nexttime: Invalid period specifier '%c', must be h|d|w|m|y", *p);
+               REDEBUG("Invalid time period '%c', must be h|d|w|m|y", *p);
                return XLAT_ACTION_FAIL;
        }
 
@@ -4281,7 +4281,11 @@ do { \
        XLAT_REGISTER_ARGS("log.info", xlat_func_log_info, FR_TYPE_NULL, xlat_func_log_arg);
        XLAT_REGISTER_ARGS("log.warn", xlat_func_log_warn, FR_TYPE_NULL, xlat_func_log_arg);
        XLAT_REGISTER_ARGS("log.destination", xlat_func_log_dst, FR_TYPE_STRING, xlat_func_log_dst_args);
+
        XLAT_REGISTER_ARGS("nexttime", xlat_func_next_time, FR_TYPE_UINT64, xlat_func_next_time_args);
+       XLAT_NEW("time.next");
+       XLAT_REGISTER_ARGS("time.next", xlat_func_next_time, FR_TYPE_UINT64, xlat_func_next_time_args);
+
        XLAT_REGISTER_ARGS("pairs", xlat_func_pairs, FR_TYPE_STRING, xlat_func_pairs_args);
 
        XLAT_REGISTER_ARGS("str.subst", xlat_func_subst, FR_TYPE_STRING, xlat_func_subst_args);
index 9ab47cc3857b1c89f5f5cf70b82d2297242bbe71..f9b7d4caa0047bf7d180665a4b50c090fce24af6 100644 (file)
@@ -8,7 +8,7 @@ uint32 result_integer
 #  different numbers of days involved.  Check hour / day / week
 #
 
-result_integer := "%{%nexttime('2h') - %nexttime('1h')}"
+result_integer := "%{%time.next('2h') - %time.next('1h')}"
 
 # We have a fudge factor of 1 second either way
 if ((result_integer < 3599) || (result_integer > 3601)) {
@@ -18,7 +18,7 @@ if ((result_integer < 3599) || (result_integer > 3601)) {
 #
 #  Day
 #
-result_integer := "%{%nexttime('3d') - %nexttime('1d')}"
+result_integer := "%{%time.next('3d') - %time.next('1d')}"
 if ((result_integer < 172799) || (result_integer > 172801)) {
        test_fail
 }
@@ -26,7 +26,7 @@ if ((result_integer < 172799) || (result_integer > 172801)) {
 #
 #  Week
 #
-result_integer := "%{%nexttime('4w') - %nexttime('2w')}"
+result_integer := "%{%time.next('4w') - %time.next('2w')}"
 if ((result_integer < 1209599) || (result_integer > 1209601)) {
        test_fail
 }