diff options
-rw-r--r-- | ChangeLog | 40 | ||||
-rw-r--r-- | doc/clock.n | 258 | ||||
-rw-r--r-- | generic/tclDate.c | 210 | ||||
-rw-r--r-- | generic/tclGetDate.y | 92 | ||||
-rw-r--r-- | tests/clock.test | 102 |
5 files changed, 326 insertions, 376 deletions
@@ -1,3 +1,14 @@ +2000-01-12 Eric Melski <ericm@scriptics.com> + + * doc/tests/clock.test: Added numerous tests for clock scan. + + * doc/generic/tclGetDate.y: Fixed some shift/reduce conflicts in + clock grammar. + + * doc/doc/clock.n: Added documentation for new supported clock + scan formats and additional explanation of daylight savings time + correction algorithm. + 2000-01-12 Jeff Hobbs <hobbs@scriptics.com> * doc/file.n: @@ -26,6 +37,14 @@ the TCL_THREAD_STACK_MIN define) for increasing the default stack size for a thread. [Bug: 3797, 1966] +2000-01-11 Eric Melski <ericm@scriptics.com> + + * generic/tclGetDate.y: Added comments for the Convert function. + Added a fix for daylight savings time handling for relative time + spans of days, weeks or fortnights. (bug 3441, 3868). + + * generic/tclDate.c: Fixed compiler warning issues. + 2000-01-10 Jeff Hobbs <hobbs@scriptics.com> * compat/waitpid.c: use pid_t type instead of int [Bug: 3999] @@ -45,6 +64,27 @@ * unix/tcl.m4: added ELF support for NetBSD [Bug: 3959] +2000-01-10 Eric Melski <ericm@scriptics.com> + + * generic/tclGetDate.y: Added rules for ISO 8601 formats (BUG #847): + CCYY-MM-DD + CCYYMMDD + YY-MM-DD + YYMMDD + CCYYMMDDTHHMMSS + CCYYMMDD HHMMSS + CCYYMMDDTHH:MM:SS + Fixed "clock scan <number>" to scan the number as an hour for the + current day, rather than a minute after 00:00 for the current day + (bug #2732). + + +2000-01-07 Eric Melski <ericm@scriptics.com> + + * generic/tclClock.c: Changed switch in Tcl_ClockObjCmd to use + enumerated values instead of constants. (ie, COMMAND_SCAN instead + of 3). + 1999-12-22 Jeff Hobbs <hobbs@scriptics.com> * changes: updated changes file diff --git a/doc/clock.n b/doc/clock.n index ed3daa9..2075e96 100644 --- a/doc/clock.n +++ b/doc/clock.n @@ -1,193 +1,65 @@ -'\" -'\" Copyright (c) 1992-1995 Karl Lehenbauer and Mark Diekhans. -'\" Copyright (c) 1995-1997 Sun Microsystems, Inc. -'\" Copyright (c) 1998-1999 Scriptics Corporation -'\" -'\" This documentation is derived from the time and date facilities of -'\" TclX, by Mark Diekhans and Karl Lehenbauer. -'\" -'\" See the file "license.terms" for information on usage and redistribution -'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. -'\" -'\" RCS: @(#) $Id: clock.n,v 1.4 1999/09/21 04:20:35 hobbs Exp $ -'\" -.so man.macros -.TH clock n 8.3 Tcl "Tcl Built-In Commands" -.BS -'\" Note: do not modify the .SH NAME line immediately below! -.SH NAME -clock \- Obtain and manipulate time -.SH SYNOPSIS -\fBclock \fIoption\fR ?\fIarg arg ...\fR? -.BE - -.SH DESCRIPTION -.PP -This command performs one of several operations that may obtain -or manipulate strings or values that represent some notion of -time. The \fIoption\fR argument determines what action is carried -out by the command. The legal \fIoptions\fR (which may be -abbreviated) are: -.TP -.VS 8.3 -\fBclock clicks\fR ?\fB\-milliseconds\fR? -Return a high-resolution time value as a system-dependent integer -value. The unit of the value is system-dependent but should be the -highest resolution clock available on the system such as a CPU cycle -counter. If \fB\-milliseconds\fR is specified, then the value is -guaranteed to be of millisecond granularity. -This value should only be used for the relative measurement -of elapsed time. -.VE 8.3 -.TP -\fBclock format \fIclockValue\fR ?\fB\-format \fIstring\fR? ?\fB\-gmt \fIboolean\fR? -Converts an integer time value, typically returned by -\fBclock seconds\fR, \fBclock scan\fR, or the \fBatime\fR, \fBmtime\fR, -or \fBctime\fR options of the \fBfile\fR command, to human-readable -form. If the \fB\-format\fR argument is present the next argument is a -string that describes how the date and time are to be formatted. -Field descriptors consist of a \fB%\fR followed by a field -descriptor character. All other characters are copied into the result. -Valid field descriptors are: -.RS -.IP \fB%%\fR -Insert a %. -.IP \fB%a\fR -Abbreviated weekday name (Mon, Tue, etc.). -.IP \fB%A\fR -Full weekday name (Monday, Tuesday, etc.). -.IP \fB%b\fR -Abbreviated month name (Jan, Feb, etc.). -.IP \fB%B\fR -Full month name. -.IP \fB%c\fR -Locale specific date and time. -.IP \fB%d\fR -Day of month (01 - 31). -.IP \fB%H\fR -Hour in 24-hour format (00 - 23). -.IP \fB%I\fR -Hour in 12-hour format (00 - 12). -.IP \fB%j\fR -Day of year (001 - 366). -.IP \fB%m\fR -Month number (01 - 12). -.IP \fB%M\fR -Minute (00 - 59). -.IP \fB%p\fR -AM/PM indicator. -.IP \fB%S\fR -Seconds (00 - 59). -.IP \fB%U\fR -Week of year (00 - 52), Sunday is the first day of the week. -.IP \fB%w\fR -Weekday number (Sunday = 0). -.IP \fB%W\fR -Week of year (00 - 52), Monday is the first day of the week. -.IP \fB%x\fR -Locale specific date format. -.IP \fB%X\fR -Locale specific time format. -.IP \fB%y\fR -Year without century (00 - 99). -.IP \fB%Y\fR -Year with century (e.g. 1990) -.IP \fB%Z\fR -Time zone name. -.RE -.sp -.RS -In addition, the following field descriptors may be supported on some -systems (e.g. Unix but not Windows): -.IP \fB%D\fR -Date as %m/%d/%y. -.IP \fB%e\fR -Day of month (1 - 31), no leading zeros. -.IP \fB%h\fR -Abbreviated month name. -.IP \fB%n\fR -Insert a newline. -.IP \fB%r\fR -Time as %I:%M:%S %p. -.IP \fB%R\fR -Time as %H:%M. -.IP \fB%t\fR -Insert a tab. -.IP \fB%T\fR -Time as %H:%M:%S. -.RE -.sp -.RS -If the \fB\-format\fR argument is not specified, the format string -"\fB%a %b %d %H:%M:%S %Z %Y\fR" is used. If the \fB\-gmt\fR argument -is present the next argument must be a boolean which if true specifies -that the time will be formatted as Greenwich Mean Time. If false -then the local timezone will be used as defined by the operating -environment. -.RE -.TP -\fBclock scan \fIdateString\fR ?\fB\-base \fIclockVal\fR? ?\fB\-gmt \fIboolean\fR? -Convert \fIdateString\fR to an integer clock value (see \fBclock seconds\fR). -This command can parse and convert virtually any standard date and/or time -string, which can include standard time zone mnemonics. If only a time is -specified, the current date is assumed. If the string does not contain a -time zone mnemonic, the local time zone is assumed, unless the \fB\-gmt\fR -argument is true, in which case the clock value is calculated assuming -that the specified time is relative to Greenwich Mean Time. -.sp -If the \fB\-base\fR flag is specified, the next argument should contain -an integer clock value. Only the date in this value is used, not the -time. This is useful for determining the time on a specific day or -doing other date-relative conversions. -.sp -The \fIdateString\fR consists of zero or more specifications of the -following form: -.RS -.TP -\fItime\fR -A time of day, which is of the form: \fIhh\fR?\fI:mm\fR?\fI:ss\fR?? -?\fImeridian\fR? ?\fIzone\fR? or \fIhhmm \fR?\fImeridian\fR? -?\fIzone\fR?. If no meridian is specified, \fIhh\fR is interpreted on -a 24-hour clock. -.TP -\fIdate\fR -A specific month and day with optional year. The -acceptable formats are \fImm/dd\fR?\fI/yy\fR?, \fImonthname dd\fR -?, \fIyy\fR?, \fIdd monthname \fR?\fIyy\fR? and \fIday, dd monthname -yy\fR. The default year is the current year. If the year is less -.VS -than 100, we treat the years 00-68 as 2000-2068 and the years 69-99 -as 1969-1999. Not all platforms can represent the years 38-70, so -an error may result if these years are used. -.VE -.TP -\fIrelative time\fR -A specification relative to the current time. The format is \fInumber -unit\fR acceptable units are \fByear\fR, \fBfortnight\fR, \fBmonth\fR, \fBweek\fR, \fBday\fR, -\fBhour\fR, \fBminute\fR (or \fBmin\fR), and \fBsecond\fR (or \fBsec\fR). The -unit can be specified as a singular or plural, as in \fB3 weeks\fR. -These modifiers may also be specified: -\fBtomorrow\fR, \fByesterday\fR, \fBtoday\fR, \fBnow\fR, -\fBlast\fR, \fBthis\fR, \fBnext\fR, \fBago\fR. -.RE -.sp -.RS -The actual date is calculated according to the following steps. -First, any absolute date and/or time is processed and converted. -Using that time as the base, day-of-week specifications are added. -Next, relative specifications are used. If a date or day is -specified, and no absolute or relative time is given, midnight is -used. Finally, a correction is applied so that the correct hour of -the day is produced after allowing for daylight savings time -differences and the correct date is given when going from the end -of a long month to a short month. -.RE -.TP -\fBclock seconds\fR -Return the current date and time as a system-dependent integer value. The -unit of the value is seconds, allowing it to be used for relative time -calculations. The value is usually defined as total elapsed time from -an ``epoch''. You shouldn't assume the value of the epoch. - -.SH KEYWORDS -clock, date, time +PCL-CVS release R-2_0-Beta_2. Copyright (C) 1991-1995 Per Cederqvist +Pcl-cvs comes with absolutely no warranty; for details consult the manual. +This is free software, and you are welcome to redistribute it under certain +conditions; again, consult the Texinfo manual for details. + +In directory : + * Modified ci ChangeLog + +In directory compat/: + +In directory doc/: + * Modified ci doc/clock.n + +In directory generic/: + Unknown generic/clock.lex + Unknown generic/foo + * Modified ci generic/tclDate.c + * Modified ci generic/tclGetDate.y + Unknown generic/y.tab.c + +In directory library/: + +In directory library/dde1.0/: + +In directory library/dde1.1/: + +In directory library/encoding/: + +In directory library/http1.0/: + +In directory library/http2.0/: + +In directory library/http2.1/: + +In directory library/msgcat1.0/: + +In directory library/opt0.1/: + +In directory library/opt0.4/: + +In directory library/reg1.0/: + +In directory library/tcltest1.0/: + +In directory mac/: + +In directory tests/: + * Modified ci tests/clock.test + +In directory tests/pkg/: + +In directory tests/pkg1/: + +In directory tools/: + +In directory tools/encoding/: + +In directory unix/: + Unknown unix/sttNrknd + Unknown unix/stuJRhh5 + +In directory unix/dltest/: + +In directory win/: +--------------------- End --------------------- diff --git a/generic/tclDate.c b/generic/tclDate.c index 0be0d2d..7da7e59 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclDate.c,v 1.12 2000/01/12 03:13:19 ericm Exp $ + * RCS: @(#) $Id: tclDate.c,v 1.13 2000/01/12 19:36:41 ericm Exp $ */ #include "tclInt.h" @@ -90,7 +90,7 @@ static MERIDIAN TclDateMeridian; static time_t TclDateRelMonth; static time_t TclDateRelDay; static time_t TclDateRelSeconds; - +static time_t *TclDateRelPointer; /* * Prototypes of internal functions. @@ -217,16 +217,16 @@ static TABLE MonthDayTable[] = { * Time units table. */ static TABLE UnitsTable[] = { - { "year", tMONTH_UNIT, 12 }, - { "month", tMONTH_UNIT, 1 }, - { "fortnight", tDAY_UNIT, 14 }, - { "week", tDAY_UNIT, 7 }, - { "day", tDAY_UNIT, 1 }, - { "hour", tMINUTE_UNIT, 60 }, - { "minute", tMINUTE_UNIT, 1 }, - { "min", tMINUTE_UNIT, 1 }, - { "second", tSEC_UNIT, 1 }, - { "sec", tSEC_UNIT, 1 }, + { "year", tMONTH_UNIT, 12 }, + { "month", tMONTH_UNIT, 1 }, + { "fortnight", tDAY_UNIT, 14 }, + { "week", tDAY_UNIT, 7 }, + { "day", tDAY_UNIT, 1 }, + { "hour", tSEC_UNIT, 60 * 60 }, + { "minute", tSEC_UNIT, 60 }, + { "min", tSEC_UNIT, 60 }, + { "second", tSEC_UNIT, 1 }, + { "sec", tSEC_UNIT, 1 }, { NULL } }; @@ -237,9 +237,9 @@ static TABLE OtherTable[] = { { "tomorrow", tDAY_UNIT, 1 }, { "yesterday", tDAY_UNIT, -1 }, { "today", tDAY_UNIT, 0 }, - { "now", tMINUTE_UNIT, 0 }, + { "now", tSEC_UNIT, 0 }, { "last", tUNUMBER, -1 }, - { "this", tMINUTE_UNIT, 0 }, + { "this", tSEC_UNIT, 0 }, { "next", tUNUMBER, 1 }, #if 0 { "first", tUNUMBER, 1 }, @@ -789,7 +789,9 @@ TclGetDate(p, now, zone, timePtr) int thisyear; TclDateInput = p; - tm = TclpGetDate((TclpTime_t) &now, 0); + /* now has to be cast to a time_t for 64bit compliance */ + Start = now; + tm = TclpGetDate((TclpTime_t) &Start, 0); thisyear = tm->tm_year + TM_YEAR_BASE; TclDateYear = thisyear; TclDateMonth = tm->tm_mon + 1; @@ -808,6 +810,8 @@ TclGetDate(p, now, zone, timePtr) TclDateRelSeconds = 0; TclDateRelMonth = 0; TclDateRelDay = 0; + TclDateRelPointer = NULL; + TclDateHaveDate = 0; TclDateHaveDay = 0; TclDateHaveRel = 0; @@ -876,18 +880,20 @@ static CONST TclDatetabelem TclDateexca[] ={ 0, -1, -2, 0, }; -# define YYNPROD 51 -# define YYLAST 248 +# define YYNPROD 47 +# define YYLAST 247 static CONST TclDatetabelem TclDateact[]={ - 18, 48, 46, 50, 49, 34, 45, 52, 35, 42, - 33, 51, 27, 43, 26, 71, 70, 66, 65, 64, - 63, 62, 61, 60, 44, 24, 41, 40, 39, 36, - 53, 68, 38, 69, 59, 56, 58, 57, 47, 37, - 17, 9, 8, 54, 7, 6, 5, 4, 3, 2, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 20, 46, 19, 23, 21, 45, 32, 31, 41, 33, + 69, 22, 42, 68, 28, 64, 27, 63, 62, 61, + 60, 59, 57, 43, 40, 39, 36, 25, 34, 50, + 66, 38, 49, 67, 56, 37, 53, 55, 54, 47, + 35, 18, 51, 9, 8, 7, 6, 5, 4, 3, + 2, 1, 30, 17, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, + 0, 0, 0, 0, 58, 0, 0, 0, 0, 0, + 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -899,62 +905,55 @@ static CONST TclDatetabelem TclDateact[]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 16, 12, 0, 0, 19, 14, 21, - 20, 0, 10, 11, 15, 25, 13, 22, 23, 29, - 28, 31, 30, 0, 0, 0, 0, 0, 0, 32, - 0, 0, 0, 0, 0, 0, 55, 55 }; + 0, 0, 0, 0, 0, 16, 12, 0, 0, 0, + 14, 23, 21, 0, 10, 11, 15, 26, 13, 22, + 24, 0, 29, 23, 21, 0, 0, 0, 0, 0, + 0, 22, 0, 0, 0, 52, 52 }; static CONST TclDatetabelem TclDatepact[]={ --10000000, -45,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000, - -33, -260,-10000000, -263, -238,-10000000, -5, -225, -239,-10000000, --10000000,-10000000,-10000000,-10000000, -240,-10000000, -241, -254, -243,-10000000, --10000000,-10000000,-10000000,-10000000, -265,-10000000, -6,-10000000,-10000000, -261, - -15, -12, -8, -9,-10000000,-10000000, -24, -244,-10000000,-10000000, --10000000,-10000000,-10000000, -245, -246,-10000000, -247, -248, -249, -250, --10000000,-10000000, -14,-10000000,-10000000,-10000000, -25,-10000000, -251, -252, --10000000,-10000000 }; +-10000000, -43,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000,-10000000, + -31, -263,-10000000, -262, -239,-10000000, -4, -241, -226,-10000000, +-10000000,-10000000,-10000000,-10000000,-10000000, -242,-10000000, -243, -255, -244, + -226,-10000000, -266,-10000000, -5,-10000000, -261,-10000000,-10000000, -16, + -11, -7, -8,-10000000,-10000000,-10000000, -24, -245, -226,-10000000, + -246, -247,-10000000, -248, -249, -250, -252,-10000000,-10000000,-10000000, + -15,-10000000,-10000000,-10000000, -25,-10000000, -254, -257,-10000000,-10000000 }; static CONST TclDatetabelem TclDatepgo[]={ - 0, 7, 50, 49, 48, 47, 46, 45, 44, 42, - 41, 40 }; + 0, 41, 35, 53, 32, 51, 50, 49, 48, 47, + 46, 45, 44, 43 }; static CONST TclDatetabelem TclDater1[]={ - 0, 2, 2, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 5, 5, 5, 7, 7, - 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 9, 9, 9, 8, 8, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 10, 1, - 1 }; + 0, 5, 5, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 8, 8, 8, 10, 10, + 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 12, 12, 12, 11, 11, 11, 3, 3, 1, + 1, 1, 2, 2, 13, 4, 4 }; static CONST TclDatetabelem TclDater2[]={ 0, 0, 4, 3, 3, 3, 3, 3, 3, 2, 5, 9, 11, 13, 15, 5, 3, 3, 3, 5, 5, 7, 11, 3, 11, 11, 5, 9, 5, 3, - 7, 7, 15, 5, 5, 2, 5, 7, 3, 7, - 5, 3, 7, 5, 3, 7, 5, 3, 3, 1, - 3 }; + 7, 7, 15, 5, 9, 7, 5, 3, 3, 3, + 3, 3, 3, 1, 3, 1, 3 }; static CONST TclDatetabelem TclDatechk[]={ --10000000, -2, -3, -4, -5, -6, -7, -8, -9, -10, - 267, 268, 259, 271, 263, 269, 258, -11, 45, 262, - 265, 264, 272, 261, 58, 258, 47, 45, 263, 262, - 265, 264, 272, 270, 268, 271, 267, 44, 257, 267, - 267, 267, 263, 267, 267, 271, 267, 44, 262, 265, - 264, 272, -1, 45, 58, 261, 47, 45, 45, 58, - 267, 267, 267, 267, 267, 267, 267, -1, 45, 58, - 267, 267 }; +-10000000, -5, -6, -7, -8, -9, -10, -11, -12, -13, + 267, 268, 259, 271, 263, 269, 258, -3, -1, 45, + 43, 265, 272, 264, 261, 58, 258, 47, 45, 263, + -1, 270, 268, 271, 267, 44, 267, -2, 257, 267, + 267, 263, 267, 267, -2, 271, 267, 44, -1, -4, + 45, 58, 261, 47, 45, 45, 58, 267, -2, 267, + 267, 267, 267, 267, 267, -4, 45, 58, 267, 267 }; static CONST TclDatetabelem TclDatedef[]={ 1, -2, 2, 3, 4, 5, 6, 7, 8, 9, - 48, 16, 17, 23, 0, 29, 18, 35, 0, 38, - 41, 44, 47, 10, 0, 20, 0, 0, 28, 36, - 40, 43, 46, 15, 0, 33, 26, 19, 34, 0, - 49, 21, 0, 0, 30, 31, 0, 0, 37, 39, - 42, 45, 11, 0, 0, 50, 0, 0, 0, 0, - 27, 12, 49, 22, 24, 25, 0, 13, 0, 0, - 14, 32 }; + 44, 16, 17, 23, 0, 29, 18, 0, 43, 37, + 38, 39, 40, 41, 10, 0, 20, 0, 0, 28, + 43, 15, 0, 33, 26, 19, 0, 36, 42, 45, + 21, 0, 0, 30, 35, 31, 0, 0, 43, 11, + 0, 0, 46, 0, 0, 0, 0, 27, 34, 12, + 45, 22, 24, 25, 0, 13, 0, 0, 14, 32 }; typedef struct #ifdef __cplusplus TclDatetoktype @@ -996,7 +995,7 @@ char * TclDatereds[] = "item : zone", "item : date", "item : day", - "item : rel", + "item : relspec", "item : iso", "item : number", "time : tUNUMBER tMERIDIAN", @@ -1023,20 +1022,16 @@ char * TclDatereds[] = "iso : tISOBASE tZONE tISOBASE", "iso : tISOBASE tZONE tUNUMBER ':' tUNUMBER ':' tUNUMBER", "iso : tISOBASE tISOBASE", - "rel : relunit tAGO", - "rel : relunit", - "relunit : tUNUMBER tMINUTE_UNIT", - "relunit : '-' tUNUMBER tMINUTE_UNIT", - "relunit : tMINUTE_UNIT", - "relunit : '-' tUNUMBER tSEC_UNIT", - "relunit : tUNUMBER tSEC_UNIT", - "relunit : tSEC_UNIT", - "relunit : '-' tUNUMBER tMONTH_UNIT", - "relunit : tUNUMBER tMONTH_UNIT", - "relunit : tMONTH_UNIT", - "relunit : '-' tUNUMBER tDAY_UNIT", - "relunit : tUNUMBER tDAY_UNIT", - "relunit : tDAY_UNIT", + "relspec : sign tUNUMBER unit ago", + "relspec : tUNUMBER unit ago", + "relspec : unit ago", + "sign : '-'", + "sign : '+'", + "unit : tSEC_UNIT", + "unit : tDAY_UNIT", + "unit : tMONTH_UNIT", + "ago : tAGO", + "ago : /* empty */", "number : tUNUMBER", "o_merid : /* empty */", "o_merid : tMERIDIAN", @@ -1718,48 +1713,17 @@ case 33:{ TclDateMinutes = (TclDatepvt[-0].Number % 10000)/100; TclDateSeconds = TclDatepvt[-0].Number % 100; } break; -case 34:{ - TclDateRelSeconds = -TclDateRelSeconds; - TclDateRelMonth = -TclDateRelMonth; - TclDateRelDay = -TclDateRelDay; - } break; -case 36:{ - TclDateRelSeconds += TclDatepvt[-1].Number * TclDatepvt[-0].Number * 60L; - } break; -case 37:{ - TclDateRelSeconds -= TclDatepvt[-1].Number * TclDatepvt[-0].Number * 60L; - } break; -case 38:{ - TclDateRelSeconds += TclDatepvt[-0].Number * 60L; - } break; -case 39:{ - TclDateRelSeconds -= TclDatepvt[-1].Number; - } break; -case 40:{ - TclDateRelSeconds += TclDatepvt[-1].Number; - } break; -case 41:{ - TclDateRelSeconds++; - } break; -case 42:{ - TclDateRelMonth -= TclDatepvt[-1].Number * TclDatepvt[-0].Number; - } break; -case 43:{ - TclDateRelMonth += TclDatepvt[-1].Number * TclDatepvt[-0].Number; - } break; +case 34:{ *TclDateRelPointer += TclDatepvt[-3].Number * TclDatepvt[-2].Number * TclDatepvt[-1].Number * TclDatepvt[-0].Number; } break; +case 35:{ *TclDateRelPointer += TclDatepvt[-2].Number * TclDatepvt[-1].Number * TclDatepvt[-0].Number; } break; +case 36:{ *TclDateRelPointer += TclDatepvt[-1].Number * TclDatepvt[-0].Number; } break; +case 37:{ TclDateval.Number = -1; } break; +case 38:{ TclDateval.Number = 1; } break; +case 39:{ TclDateval.Number = TclDatepvt[-0].Number; TclDateRelPointer = &TclDateRelSeconds; } break; +case 40:{ TclDateval.Number = TclDatepvt[-0].Number; TclDateRelPointer = &TclDateRelDay; } break; +case 41:{ TclDateval.Number = TclDatepvt[-0].Number; TclDateRelPointer = &TclDateRelMonth; } break; +case 42:{ TclDateval.Number = -1; } break; +case 43:{ TclDateval.Number = 1; } break; case 44:{ - TclDateRelMonth += TclDatepvt[-0].Number; - } break; -case 45:{ - TclDateRelDay -= TclDatepvt[-1].Number * TclDatepvt[-0].Number; - } break; -case 46:{ - TclDateRelDay += TclDatepvt[-1].Number * TclDatepvt[-0].Number; - } break; -case 47:{ - TclDateRelDay += TclDatepvt[-0].Number; - } break; -case 48:{ if (TclDateHaveTime && TclDateHaveDate && !TclDateHaveRel) { TclDateYear = TclDatepvt[-0].Number; } else { @@ -1775,10 +1739,10 @@ case 48:{ TclDateMeridian = MER24; } } break; -case 49:{ +case 45:{ TclDateval.Meridian = MER24; } break; -case 50:{ +case 46:{ TclDateval.Meridian = TclDatepvt[-0].Meridian; } break; } diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index c5d7231..510f164 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclGetDate.y,v 1.10 2000/01/12 03:13:20 ericm Exp $ + * RCS: @(#) $Id: tclGetDate.y,v 1.11 2000/01/12 19:36:42 ericm Exp $ */ %{ @@ -107,7 +107,7 @@ static MERIDIAN yyMeridian; static time_t yyRelMonth; static time_t yyRelDay; static time_t yyRelSeconds; - +static time_t *yyRelPointer; /* * Prototypes of internal functions. @@ -142,6 +142,7 @@ yyparse _ANSI_ARGS_((void)); %type <Number> tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT tDST %type <Number> tSEC_UNIT tSNUMBER tUNUMBER tZONE tISOBASE tDAY_UNIT +%type <Number> unit ago sign %type <Meridian> tMERIDIAN o_merid %% @@ -162,7 +163,7 @@ item : time { | day { yyHaveDay++; } - | rel { + | relspec { yyHaveRel++; } | iso { @@ -312,50 +313,19 @@ iso : tISOBASE tZONE tISOBASE { } ; -rel : relunit tAGO { - yyRelSeconds = -yyRelSeconds; - yyRelMonth = -yyRelMonth; - yyRelDay = -yyRelDay; - } - | relunit +relspec : sign tUNUMBER unit ago { *yyRelPointer += $1 * $2 * $3 * $4; } + | tUNUMBER unit ago { *yyRelPointer += $1 * $2 * $3; } + | unit ago { *yyRelPointer += $1 * $2; } ; - -relunit : tUNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | '-' tUNUMBER tMINUTE_UNIT { - yyRelSeconds -= $2 * $3 * 60L; - } - | tMINUTE_UNIT { - yyRelSeconds += $1 * 60L; - } - | '-' tUNUMBER tSEC_UNIT { - yyRelSeconds -= $2; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tSEC_UNIT { - yyRelSeconds++; - } - | '-' tUNUMBER tMONTH_UNIT { - yyRelMonth -= $2 * $3; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tMONTH_UNIT { - yyRelMonth += $1; - } - | '-' tUNUMBER tDAY_UNIT { - yyRelDay -= $2 * $3; - } - | tUNUMBER tDAY_UNIT { - yyRelDay += $1 * $2; - } - | tDAY_UNIT { - yyRelDay += $1; - } +sign : '-' { $$ = -1; } + | '+' { $$ = 1; } + ; +unit : tSEC_UNIT { $$ = $1; yyRelPointer = &yyRelSeconds; } + | tDAY_UNIT { $$ = $1; yyRelPointer = &yyRelDay; } + | tMONTH_UNIT { $$ = $1; yyRelPointer = &yyRelMonth; } + ; +ago : tAGO { $$ = -1; } + | { $$ = 1; } ; number : tUNUMBER @@ -422,16 +392,16 @@ static TABLE MonthDayTable[] = { * Time units table. */ static TABLE UnitsTable[] = { - { "year", tMONTH_UNIT, 12 }, - { "month", tMONTH_UNIT, 1 }, - { "fortnight", tDAY_UNIT, 14 }, - { "week", tDAY_UNIT, 7 }, - { "day", tDAY_UNIT, 1 }, - { "hour", tMINUTE_UNIT, 60 }, - { "minute", tMINUTE_UNIT, 1 }, - { "min", tMINUTE_UNIT, 1 }, - { "second", tSEC_UNIT, 1 }, - { "sec", tSEC_UNIT, 1 }, + { "year", tMONTH_UNIT, 12 }, + { "month", tMONTH_UNIT, 1 }, + { "fortnight", tDAY_UNIT, 14 }, + { "week", tDAY_UNIT, 7 }, + { "day", tDAY_UNIT, 1 }, + { "hour", tSEC_UNIT, 60 * 60 }, + { "minute", tSEC_UNIT, 60 }, + { "min", tSEC_UNIT, 60 }, + { "second", tSEC_UNIT, 1 }, + { "sec", tSEC_UNIT, 1 }, { NULL } }; @@ -442,9 +412,9 @@ static TABLE OtherTable[] = { { "tomorrow", tDAY_UNIT, 1 }, { "yesterday", tDAY_UNIT, -1 }, { "today", tDAY_UNIT, 0 }, - { "now", tMINUTE_UNIT, 0 }, + { "now", tSEC_UNIT, 0 }, { "last", tUNUMBER, -1 }, - { "this", tMINUTE_UNIT, 0 }, + { "this", tSEC_UNIT, 0 }, { "next", tUNUMBER, 1 }, #if 0 { "first", tUNUMBER, 1 }, @@ -994,7 +964,9 @@ TclGetDate(p, now, zone, timePtr) int thisyear; yyInput = p; - tm = TclpGetDate((TclpTime_t) &now, 0); + /* now has to be cast to a time_t for 64bit compliance */ + Start = now; + tm = TclpGetDate((TclpTime_t) &Start, 0); thisyear = tm->tm_year + TM_YEAR_BASE; yyYear = thisyear; yyMonth = tm->tm_mon + 1; @@ -1013,6 +985,8 @@ TclGetDate(p, now, zone, timePtr) yyRelSeconds = 0; yyRelMonth = 0; yyRelDay = 0; + yyRelPointer = NULL; + yyHaveDate = 0; yyHaveDay = 0; yyHaveRel = 0; diff --git a/tests/clock.test b/tests/clock.test index 1b1632f..fd97091 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -10,7 +10,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: clock.test,v 1.5 1999/09/21 04:20:44 hobbs Exp $ +# RCS: @(#) $Id: clock.test,v 1.6 2000/01/12 19:36:42 ericm Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -158,6 +158,106 @@ test clock-4.11 {clock scan tests} { clock format $time -format {%b %d,%Y %H:%M GMT} -gmt true } {Jan 01,2037 00:00 GMT} +test clock-4.12 {clock scan, relative times} { + set time [clock scan "Oct 23, 1992 -1 day"] + clock format $time -format {%b %d, %Y} +} "Oct 22, 1992" +test clock-4.13 {clock scan, ISO 8601 base date format} { + set time [clock scan "19921023"] + clock format $time -format {%b %d, %Y} +} "Oct 23, 1992" +test clock-4.14 {clock scan, ISO 8601 expanded date format} { + set time [clock scan "1992-10-23"] + clock format $time -format {%b %d, %Y} +} "Oct 23, 1992" +test clock-4.15 {clock scan, DD-Mon-YYYY format} { + set time [clock scan "23-Oct-1992"] + clock format $time -format {%b %d, %Y} +} "Oct 23, 1992" +test clock-4.16 {clock scan, ISO 8601 point in time format} { + set time [clock scan "19921023T235959"] + clock format $time -format {%b %d, %Y %H:%M:%S} +} "Oct 23, 1992 23:59:59" +test clock-4.17 {clock scan, ISO 8601 point in time format} { + set time [clock scan "19921023 235959"] + clock format $time -format {%b %d, %Y %H:%M:%S} +} "Oct 23, 1992 23:59:59" + +# CLOCK SCAN REAL TESTS +test clock-4.18 {clock scan, number meridian} { + set t1 [clock scan "5 am" -base 946627200 -gmt true] + set t2 [clock scan "5 pm" -base 946627200 -gmt true] + set t3 [clock scan "5 a.m." -base 946627200 -gmt true] + set t4 [clock scan "5 p.m." -base 946627200 -gmt true] + list \ + [clock format $t1 -format {%b %d, %Y %H:%M:%S} -gmt true] \ + [clock format $t2 -format {%b %d, %Y %H:%M:%S} -gmt true] \ + [clock format $t3 -format {%b %d, %Y %H:%M:%S} -gmt true] \ + [clock format $t4 -format {%b %d, %Y %H:%M:%S} -gmt true] +} [list "Dec 31, 1999 05:00:00" "Dec 31, 1999 17:00:00" \ + "Dec 31, 1999 05:00:00" "Dec 31, 1999 17:00:00"] +test clock-4.19 {clock scan, number:number meridian} { + clock format [clock scan "5:30 pm" -base 946627200 -gmt true] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Dec 31, 1999 17:30:00" +test clock-4.20 {clock scan, number:number-timezone} { + clock format [clock scan "00:00-0800" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Dec 31, 1999 08:00:00" +test clock-4.21 {clock scan, number:number:number o_merid} { + clock format [clock scan "8:00:00" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Dec 31, 1999 08:00:00" +test clock-4.22 {clock scan, number:number:number o_merid} { + clock format [clock scan "8:00:00 am" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Dec 31, 1999 08:00:00" +test clock-4.23 {clock scan, number:number:number o_merid} { + clock format [clock scan "8:00:00 pm" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Dec 31, 1999 20:00:00" +test clock-4.24 {clock scan, number:number:number-timezone} { + clock format [clock scan "00:00:30-0800" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Dec 31, 1999 08:00:30" +test clock-4.25 {clock scan, DST for days} { + clock scan "tomorrow" -base 941353200 +} 941443200 +test clock-4.26 {clock scan, DST for days} { + clock scan "yesterday" -base 941443200 +} 941353200 +test clock-4.27 {clock scan, day} knownBug { + clock format [clock scan "Monday" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} +} "Jan 03, 2000 00:00:00" +test clock-4.28 {clock scan, number/number} { + clock format [clock scan "1/1" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Jan 01, 1999 00:00:00" +test clock-4.28 {clock scan, number/number} { + clock format [clock scan "1/1/1999" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Jan 01, 1999 00:00:00" +test clock-4.28 {clock scan, number/number} { + clock format [clock scan "19990101" -gmt true -base 946627200] \ + -format {%b %d, %Y %H:%M:%S} -gmt true +} "Jan 01, 1999 00:00:00" +test clock-4.29 {clock scan, relative minutes} { + clock scan "now + 1 minute" -base 946627200 +} 946627260 +test clock-4.30 {clock scan, relative minutes} { + clock scan "now +1 minute" -base 946627200 +} 946627260 +test clock-4.31 {clock scan, relative minutes} { + clock scan "now 1 minute" -base 946627200 +} 946627260 +test clock-4.32 {clock scan, relative minutes} { + clock scan "now - 1 minute" -base 946627200 +} 946627140 +test clock-4.33 {clock scan, relative minutes} { + clock scan "now -1 minute" -base 946627200 +} 946627140 + # clock seconds test clock-5.1 {clock seconds tests} { expr [clock seconds]+1 |