From: Alan T. DeKok Date: Wed, 14 Aug 2024 13:42:24 +0000 (-0400) Subject: use the src enum for time resolution, not the dst enum X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a875be91c3540690faf645a04220a43ac6c3fda;p=thirdparty%2Ffreeradius-server.git use the src enum for time resolution, not the dst enum and add tests for it. --- diff --git a/src/lib/util/value.c b/src/lib/util/value.c index 3a37e7c976c..3ffa5bd8b83 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -2973,7 +2973,7 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f case FR_TYPE_DATE: { fr_time_res_t res = FR_TIME_RES_SEC; - if (dst->enumv) res = dst->enumv->flags.flag_time_res; + if (src->enumv) res = src->enumv->flags.flag_time_res; tmp = fr_unix_time_to_integer(src->vb_date, res); } @@ -2989,7 +2989,7 @@ static inline int fr_value_box_cast_integer_to_integer(UNUSED TALLOC_CTX *ctx, f { fr_time_res_t res = FR_TIME_RES_SEC; - if (dst->enumv) res = dst->enumv->flags.flag_time_res; + if (src->enumv) res = src->enumv->flags.flag_time_res; tmp = (uint64_t)fr_time_delta_to_integer(src->vb_time_delta, res); } diff --git a/src/tests/keywords/cast-time_delta b/src/tests/keywords/cast-time_delta index 61e2037f86d..645b82094ae 100644 --- a/src/tests/keywords/cast-time_delta +++ b/src/tests/keywords/cast-time_delta @@ -7,19 +7,32 @@ time_delta diff time_delta diff2 uint32 num -if (%cast("ms", 60s) != (uint32) 60000) { +# +# We can cast a time duration to milliseconds, and get a sane value. +# +if (%cast("ms", 60s) != 60000) { + test_fail +} + +if (%cast("weeks", 7d) != 1) { test_fail } -if (0) { +if (%cast("weeks", 8d) != 1.864) { + test_fail +} + + # # And then for dates # +# These dates are one minute apart. +# &one = "2024-08-12T00:00:00Z" &two = "2024-08-12T00:01:00Z" &diff = &two - &one -if (&diff != 60) { +if (&diff != 60s) { test_fail } @@ -34,6 +47,5 @@ if (&diff != 60) { if (&num != 60000) { test_fail } -} success