Skip to content

Commit

Permalink
time: fix bundling for sqlean.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Aug 8, 2024
1 parent c360836 commit 6747e85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/time.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/time/duration.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down

0 comments on commit 6747e85

Please sign in to comment.