not bob!
```
-=== %nexttime(<time>)
+=== %time.next(<time>)
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
----
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.
/** 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
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;
}
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;
}
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);
# 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)) {
#
# Day
#
-result_integer := "%{%nexttime('3d') - %nexttime('1d')}"
+result_integer := "%{%time.next('3d') - %time.next('1d')}"
if ((result_integer < 172799) || (result_integer > 172801)) {
test_fail
}
#
# Week
#
-result_integer := "%{%nexttime('4w') - %nexttime('2w')}"
+result_integer := "%{%time.next('4w') - %time.next('2w')}"
if ((result_integer < 1209599) || (result_integer > 1209601)) {
test_fail
}