From 6747e8542c34f1977bf26c0c4bd70d1726d5cad2 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 9 Aug 2024 00:19:49 +0500 Subject: [PATCH] time: fix bundling for sqlean.py --- docs/time.md | 2 +- src/time/duration.c | 10 +++++----- src/time/time.c | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/time.md b/docs/time.md index b8a41a98..3fb41bab 100644 --- a/docs/time.md +++ b/docs/time.md @@ -51,7 +51,7 @@ Time is always stored and operated in UTC, but you can convert it from/to a spec Duration is a 64-bit number of nanoseconds, so it can represent values up to about 290 years. You can store duration values as NUMBER. -The calendrical calculations always assume a Gregorian calendar, with no leap seconds. +The calendarical calculations always assume a Gregorian calendar, with no leap seconds. ## Creating time values diff --git a/src/time/duration.c b/src/time/duration.c index 4cee7b48..802d418f 100644 --- a/src/time/duration.c +++ b/src/time/duration.c @@ -56,10 +56,10 @@ double dur_to_hours(Duration d) { #pragma region Rounding -// less_than_half reports whether x+x < y but avoids overflow, +// dless_than_half reports whether x+x < y but avoids overflow, // assuming x and y are both positive (Duration is signed). -static bool less_than_half(Duration x, Duration y) { - return x < y - x; +static bool dless_than_half(Duration x, Duration y) { + return (uint64_t)x + (uint64_t)x < (uint64_t)y; } // dur_truncate returns the result of rounding d toward zero to a multiple of m. @@ -85,7 +85,7 @@ Duration dur_round(Duration d, Duration m) { if (d < 0) { r = -r; - if (less_than_half(r, m)) { + if (dless_than_half(r, m)) { return d + r; } int64_t d1 = d - m + r; @@ -95,7 +95,7 @@ Duration dur_round(Duration d, Duration m) { return MIN_DURATION; // overflow } - if (less_than_half(r, m)) { + if (dless_than_half(r, m)) { return d - r; } int64_t d1 = d + m - r; diff --git a/src/time/time.c b/src/time/time.c index 5d536805..4dce4b28 100644 --- a/src/time/time.c +++ b/src/time/time.c @@ -209,15 +209,15 @@ void abs_clock(uint64_t abs, int* hour, int* min, int* sec) { *sec -= *min * seconds_per_minute; } -// less_than_half reports whether x+x < y but avoids overflow, +// tless_than_half reports whether x+x < y but avoids overflow, // assuming x and y are both positive (Duration is signed). -static bool less_than_half(Duration x, Duration y) { +static bool tless_than_half(Duration x, Duration y) { return (uint64_t)x + (uint64_t)x < (uint64_t)y; } -// div divides t by d and returns the remainder. +// time_div divides t by d and returns the remainder. // Only supports d which is a multiple of 1 second. -static Duration div(Time t, Duration d) { +static Duration time_div(Time t, Duration d) { if (d % Second != 0) { return 0; } @@ -631,7 +631,7 @@ Time time_truncate(Time t, Duration d) { if (d <= 0) { return t; } - Duration r = div(t, d); + Duration r = time_div(t, d); return time_add(t, -r); } @@ -642,8 +642,8 @@ Time time_round(Time t, Duration d) { if (d <= 0) { return t; } - Duration r = div(t, d); - if (less_than_half(r, d)) { + Duration r = time_div(t, d); + if (tless_than_half(r, d)) { return time_add(t, -r); } return time_add(t, d - r);