Skip to content

Commit

Permalink
Merge pull request #4 from flightaware/merge-sebres-20
Browse files Browse the repository at this point in the history
Merge branch 'sebresgh-20--neg-relmonth-offs'
  • Loading branch information
bovine authored May 14, 2020
2 parents 52ed179 + b08db60 commit a046190
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dnl to configure the system for the local environment.
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------

AC_INIT([tclclockmod], [8.6.706])
AC_INIT([tclclockmod], [8.6.707])

#--------------------------------------------------------------------
# Call TEA_INIT as the first TEA_ macro to set up initial vars.
Expand Down
5 changes: 5 additions & 0 deletions generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -4144,6 +4144,11 @@ ClockCalcRelTime(
yyMonth += yyRelMonth - 1;
yyYear += yyMonth / 12;
m = yyMonth % 12;
/* compiler fix for negative offs - wrap y, m = (0, -1) -> (-1, 11) */
if (m < 0) {
yyYear--;
m = 12 + m;
}
yyMonth = m + 1;

/* if the day doesn't exist in the current month, repair it */
Expand Down
18 changes: 18 additions & 0 deletions tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -35308,6 +35308,24 @@ test clock-30.8 {clock add months, negative} {
set x4 [clock format $f4 -format %Y-%m-%d -timezone :UTC]
list $x1 $x2 $x3 $x4
} {2000-02-29 2000-01-31 1999-12-31 1999-11-30}
test clock-30.8a {clock add months, negative, over threshold of a year} {
set t [clock scan 2019-01-31 -format %Y-%m-%d -timezone :UTC]
list [clock format [clock add $t -1 month -timezone :UTC] -format %Y-%m-%d -timezone :UTC] \
[clock format [clock add $t -2 month -timezone :UTC] -format %Y-%m-%d -timezone :UTC] \
[clock format [clock add $t -3 month -timezone :UTC] -format %Y-%m-%d -timezone :UTC] \
[clock format [clock add $t -4 month -timezone :UTC] -format %Y-%m-%d -timezone :UTC]
} {2018-12-31 2018-11-30 2018-10-31 2018-09-30}
test clock-30.8b {clock add months, negative, over threshold of a year} {
set t [clock scan 2000-01-28 -format %Y-%m-%d -timezone :UTC]
for {set i 1} {$i < 24} {incr i 1} {
set f1 [clock add $t -$i month -timezone :UTC]
set f2 [clock add $f1 $i month -timezone :UTC]
if {$f2 != $t} {
error "\[clock add $t -$i month -timezone :UTC\] does not consider\
\[clock add $f1 $i month -timezone :UTC\] != $t"
}
}
} {}
test clock-30.9 {clock add days} {
set t [clock scan {2000-01-01 12:34:56} -format {%Y-%m-%d %H:%M:%S} \
-timezone :UTC]
Expand Down

0 comments on commit a046190

Please sign in to comment.