Skip to content

Commit

Permalink
merge 8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
sebres committed Jul 28, 2024
2 parents 8d54b05 + d90942b commit d49bf1f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
8 changes: 4 additions & 4 deletions doc/clock.n
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ slowing its clock by a tiny fraction for some minutes until it is
back in sync with UTC; its data model does not represent minutes that
have 59 or 61 seconds.
.TP
\fI\-now\fR
Instead of \fItimeVal\fR a non-integer option \fI\-now\fR can be used as
\fI\now\fR
Instead of \fItimeVal\fR a non-integer option \fI\now\fR can be used as
replacement for today, which is simply interpolated to the runt-time as value
of \fBclock seconds\fR. For example:
.sp
\fBclock format -now -f %a; # current day of the week\fR
\fBclock format now -f %a; # current day of the week\fR
.sp
\fBclock add -now 1 month; # next month\fR
\fBclock add now 1 month; # next month\fR
.TP
\fIunit\fR
.
Expand Down
20 changes: 12 additions & 8 deletions generic/tclClock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3417,16 +3417,18 @@ ClockParseFmtScnArgs(
if (opts->baseObj != NULL) {
Tcl_Obj *baseObj = opts->baseObj;

/* bypass integer recognition if looks like option "-now" */
if ((baseObj->bytes && baseObj->length == 4 && baseObj->bytes[1] == 'n')
/* bypass integer recognition if looks like "now" or "-now" */
if ((baseObj->bytes &&
((baseObj->length == 3 && baseObj->bytes[0] == 'n') ||
(baseObj->length == 4 && baseObj->bytes[1] == 'n')))
|| TclGetWideIntFromObj(NULL, baseObj, &baseVal) != TCL_OK) {
/* we accept "-now" as current date-time */
/* we accept "now" and "-now" as current date-time */
static const char *const nowOpts[] = {
"-now", NULL
"now", "-now", NULL
};
int idx;

if (Tcl_GetIndexFromObj(interp, baseObj, nowOpts, "seconds",
if (Tcl_GetIndexFromObj(NULL, baseObj, nowOpts, "seconds",
TCL_EXACT, &idx) == TCL_OK) {
goto baseNow;
}
Expand All @@ -3435,7 +3437,9 @@ ClockParseFmtScnArgs(
goto baseOverflow;
}

Tcl_AppendResult(interp, " or integer", (char *)NULL);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"bad seconds \"%s\": must be now or integer",
TclGetString(baseObj)));
i = baseIdx;
goto badOption;
}
Expand Down Expand Up @@ -3527,7 +3531,7 @@ ClockFormatObjCmd(
Tcl_Obj *const objv[]) /* Parameter values */
{
ClockClientData *dataPtr = (ClockClientData *)clientData;
static const char *syntax = "clock format clockval|-now "
static const char *syntax = "clock format clockval|now "
"?-format string? "
"?-gmt boolean? "
"?-locale LOCALE? ?-timezone ZONE?";
Expand Down Expand Up @@ -4358,7 +4362,7 @@ ClockAddObjCmd(
int objc, /* Parameter count */
Tcl_Obj *const objv[]) /* Parameter values */
{
static const char *syntax = "clock add clockval|-now ?number units?..."
static const char *syntax = "clock add clockval|now ?number units?..."
"?-gmt boolean? "
"?-locale LOCALE? ?-timezone ZONE?";
ClockClientData *dataPtr = (ClockClientData *)clientData;
Expand Down
16 changes: 8 additions & 8 deletions tests/clock.test
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ test clock-0.1 "initial: auto-loading of ensemble and stubs on demand" -setup {
clock seconds; # init ensemble (but not yet stubs, loading of clock.tcl retarded)
lappend ret ens:[namespace ensemble exists ::clock]
lappend ret stubs:[expr {[namespace which -command ::tcl::clock::GetSystemTimeZone] ne ""}]
clock format -now; # clock.tcl stubs expected
clock format now; # clock.tcl stubs expected
lappend ret stubs:[expr {[namespace which -command ::tcl::clock::GetSystemTimeZone] ne ""}]
}
} -cleanup {
Expand All @@ -298,7 +298,7 @@ test clock-0.1a "initial: safe interpreter shares clock command with parent" -se
$sci eval { clock seconds }; # init ensemble (but not yet stubs, loading of clock.tcl retarded)
lappend ret ens:[namespace ensemble exists ::clock]
lappend ret stubs:[expr {[namespace which -command ::tcl::clock::GetSystemTimeZone] ne ""}]
$sci eval { clock format -now }; # clock.tcl stubs expected
$sci eval { clock format now }; # clock.tcl stubs expected
lappend ret stubs:[expr {[namespace which -command ::tcl::clock::GetSystemTimeZone] ne ""}]
}
} -cleanup {
Expand All @@ -314,14 +314,14 @@ test clock-0.2 "initial: loading of format/locale does not overwrite interp stat
if {[catch {
return -level 0 -code error -errorcode {EXPERR TEST-ERROR} -errorinfo "ERROR expected error" test
}]} {
clock format -now -locale de; # should not overwrite error code/info
clock format now -locale de; # should not overwrite error code/info
list $::errorCode $::errorInfo
}
} -result {{EXPERR TEST-ERROR} {ERROR expected error}}

# Test some of the basics of [clock format]

set syntax "clockval|-now ?-format string? ?-gmt boolean? ?-locale LOCALE? ?-timezone ZONE?"
set syntax "clockval|now ?-format string? ?-gmt boolean? ?-locale LOCALE? ?-timezone ZONE?"
test clock-1.0 "clock format - wrong # args" {
list [catch {clock format} msg] $msg $::errorCode
} [subst {1 {wrong # args: should be "clock format $syntax"} {CLOCK wrongNumArgs}}]
Expand All @@ -332,7 +332,7 @@ test clock-1.0.1 "clock format - wrong # args (compiled ensemble with invalid sy

test clock-1.1 "clock format - bad time" {
list [catch {clock format foo} msg opt] $msg [dict getd $opt -errorcode {}]
} {1 {bad seconds "foo": must be -now or integer} {CLOCK badOption foo}}
} {1 {bad seconds "foo": must be now or integer} {CLOCK badOption foo}}

test clock-1.2 "clock format - bad gmt val" {
list [catch {clock format 0 -gmt foo} msg] $msg
Expand Down Expand Up @@ -367,10 +367,10 @@ test clock-1.7.1 "clock format - command abbreviations (compat regression test)"
clock f 0 -g 1 -f "%Y-%m-%d"
} 1970-01-01

test clock-1.8 "clock format -now" {
test clock-1.8 "clock format now" {
# give one second more for test (if on boundary of the current second):
set n [clock format [clock seconds] -g 1 -f "%s"]
expr {[clock format -now -g 1 -f "%s"] in [list $n [incr n]]}
expr {[clock format now -g 1 -f "%s"] in [list $n [incr n]]}
} 1

test clock-1.9 "clock arguments: option doubly present" {
Expand Down Expand Up @@ -18704,7 +18704,7 @@ test clock-6.8 {input of seconds} {

test clock-6.8b "clock scan - bad base" {
list [catch {clock scan "" -base foo -gmt 1} msg opt] $msg [dict getd $opt -errorcode {}]
} {1 {bad seconds "foo": must be -now or integer} {CLOCK badOption foo}}
} {1 {bad seconds "foo": must be now or integer} {CLOCK badOption foo}}

test clock-6.9 {input of seconds - overflow} {
list [catch {clock scan -9223372036854775809 -format %s -gmt true} result opt] $result [dict getd $opt -errorcode ""]
Expand Down
2 changes: 1 addition & 1 deletion tests/cmdAH.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ testConstraint filetime64bit [expr {
# check whether disk may have 2038 problem, see [fd91b0ca09cb171f]:
set fn [makeFile "" foo.text]
if {[catch {
exec sh -c "TZ=:UTC LC_TYME=en_US touch -ma -t '207006290000' '$fn' && TZ=:UTC LC_TYME=en_US ls -l '$fn'"
exec sh -c "TZ=:UTC LC_TIME=en_US touch -ma -t '207006290000' '$fn' && TZ=:UTC LC_TIME=en_US ls -l '$fn'"
} res]} {
#puts "Check constraint failed:\t$res"
set res {}
Expand Down

0 comments on commit d49bf1f

Please sign in to comment.