]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use the src enum for time resolution, not the dst enum
authorAlan T. DeKok <aland@freeradius.org>
Wed, 14 Aug 2024 13:42:24 +0000 (09:42 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 14 Aug 2024 13:42:49 +0000 (09:42 -0400)
and add tests for it.

src/lib/util/value.c
src/tests/keywords/cast-time_delta

index 3a37e7c976c22a7e56b193cde87e31bfa83905d0..3ffa5bd8b83e387e7416792b958e631332e798d8 100644 (file)
@@ -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);
        }
index 61e2037f86d960dfccd4596775751d5c1ca05b97..645b82094ae83f4a3cb9bd24b063b07a63430e2d 100644 (file)
@@ -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