summaryrefslogtreecommitdiffstats
path: root/generic/tclClock.c
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2024-07-28 19:44:23 (GMT)
committersebres <sebres@users.sourceforge.net>2024-07-28 19:44:23 (GMT)
commit46c7acb6251b5bfb6c463c3de469eb498d4e676c (patch)
tree1307ce2eefa710083b603a8b7db0e6f908ec4971 /generic/tclClock.c
parent4626e4fb3b531a8d3de9bc5c3c7ee6d8f23cfe12 (diff)
downloadtcl-46c7acb6251b5bfb6c463c3de469eb498d4e676c.zip
tcl-46c7acb6251b5bfb6c463c3de469eb498d4e676c.tar.gz
tcl-46c7acb6251b5bfb6c463c3de469eb498d4e676c.tar.bz2
closes [cd25761979]: `clock format` and `clock add` will accept `now` as clock value (value `-now` retained to compat reasons to earlier versions and tclclockmod, undocumented at the moment)
Diffstat (limited to 'generic/tclClock.c')
-rw-r--r--generic/tclClock.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 20da59f..0b72bf4 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -3419,16 +3419,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;
}
@@ -3437,7 +3439,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;
}
@@ -3529,7 +3533,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?";
@@ -4363,7 +4367,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;