summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-09-15 06:27:39 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-09-15 06:27:39 (GMT)
commit7539841ffd6ed3122986a4aef9fc0b60e477c607 (patch)
treec6bd2858a3640b4ce87297c427f1c80a1cf177ce
parent1cee49ead8bc5aef05af90885883c758e46f928c (diff)
parent39c9ae29d9fb0b0f6935081aae95607f8d2de414 (diff)
downloadtcl-7539841ffd6ed3122986a4aef9fc0b60e477c607.zip
tcl-7539841ffd6ed3122986a4aef9fc0b60e477c607.tar.gz
tcl-7539841ffd6ed3122986a4aef9fc0b60e477c607.tar.bz2
Merge 8.6
-rw-r--r--.github/workflows/linux-build.yml1
-rw-r--r--generic/tclClock.c8
-rw-r--r--tests/clock.test14
3 files changed, 20 insertions, 3 deletions
diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml
index 96ee7d9..a17751c 100644
--- a/.github/workflows/linux-build.yml
+++ b/.github/workflows/linux-build.yml
@@ -21,6 +21,7 @@ jobs:
- "--enable-symbols"
- "--enable-symbols=mem"
- "--enable-symbols=all"
+ - "CFLAGS=-ftrapv"
defaults:
run:
shell: bash
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 39fb073..4f97cb9 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -447,11 +447,13 @@ ClockGetdatefieldsObjCmd(
}
/*
- * Extract Julian day.
+ * Extract Julian day. Always round the quotient down by subtracting 1
+ * when the remainder is negative (i.e. if the quotient was rounded up).
*/
- fields.julianDay = (int) ((fields.localSeconds + JULIAN_SEC_POSIX_EPOCH)
- / SECONDS_PER_DAY);
+ fields.julianDay = (int) ((fields.localSeconds / SECONDS_PER_DAY) -
+ ((fields.localSeconds % SECONDS_PER_DAY) < 0) +
+ JULIAN_DAY_POSIX_EPOCH);
/*
* Convert to Julian or Gregorian calendar.
diff --git a/tests/clock.test b/tests/clock.test
index 4bac104..3f20607 100644
--- a/tests/clock.test
+++ b/tests/clock.test
@@ -18596,6 +18596,20 @@ test clock-7.9 {Julian Day, two values} {
clock scan {2440588 2440589} -format {%J %J} -gmt true
} 86400
+test clock-7.10 {Julian Day, negative amount} {
+ # Note: %J does not accept negative input;
+ # add negative amounts to Julian day 0 instead
+ set s0 [clock scan 0 -format %J -gmt true]
+ set J0 [scan [clock format $s0 -format %J -gmt true] %lld]
+ set s0m1d [clock add $s0 -1 days]
+ set s0m24h [clock add $s0 -24 hours]
+ set J0m24h [scan [clock format $s0m24h -format %J -gmt true] %lld]
+ set s0m1s [clock add $s0 -1 seconds]
+ set J0m1s [scan [clock format $s0m1s -format %J -gmt true] %lld]
+ list $s0m1d $s0m24h $J0m24h $s0m1s $J0m1s $s0 $J0 \
+ [::tcl::mathop::== $s0m1d $s0m24h] [::tcl::mathop::== $J0m24h $J0m1s]
+} [list -210866889600 -210866889600 -1 -210866803201 -1 -210866803200 0 1 1]
+
# BEGIN testcases8
# Test parsing of ccyymmdd