Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src Pull up following revision(s) (requested by nonaka in tic...



details:   https://anonhg.NetBSD.org/src/rev/c68b8d4c2b83
branches:  netbsd-6
changeset: 776954:c68b8d4c2b83
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Apr 17 10:24:09 2015 +0000

description:
Pull up following revision(s) (requested by nonaka in ticket #1291):
        tests/lib/libutil/t_parsedate.c: revision 1.4-1.13
        lib/libutil/parsedate.y: revision 1.14-1.20
        lib/libutil/parsedate.3: revision 1.11-1.14
Distinguish between a non-error result of (time_t)-1 and an error result.
Modernise the test code inside #ifdef TEST.
add rcsid
fix timezone bugs in rev.1.11 and rev.1.13.  PR/47916.
Some years don't need the "maybe add 1900 or 2000" adjustment
that was designed for handling two-digit abbreviated years.
For example, "1/2/70" still refers to the year 1970, as before,
but "70-01-02" now refers to the year 70.
* Add a new yyHaveFullYear member to struct dateinfo, to record whether
  or not the year needs to be adjusted.
* Code that parses years sets yyHaveFullYear=1 if they know that the
  year should not be adjusted (as is the case for ISO 8601 dates), or if
  they perform their own adjustment (as is the case for CVS timestamps).
* Move the year adjustment code into a new function, AdjustYear,
  instead of inline in Convert().
* Make Convert() assume the year doesn't need to be adjusted,
  and make Convert's callers first call AdjustYear() if appropriate.
A time like HH:MM:SS.sss says nothing about whether DST is on or off.
Add a new non-terminal "time_numericzone" for a time with
a numeric timezone.  Move some productions from "time" to "time_numericzone".
Increment yyHaveZone when encountering one of these.
Previously, input of the form "HH:MM:SS +ZZZZ" would not have set the
yyhaveZone flag.
Improved handling of local times.
* A magic value USE_LOCAL_TIME (defined as 99999) may be passed as the
  Timezone to Convert(), instructing it to use mktime() to work
  in the local time zone, instead of using mktime_z to work in UTC
  (and then adding the specified timezone offset).
* Some old code is removed now that there's no need to find the local
  timezone offset.
* Allow either one or both of the now and zone arguments to
  parsedate() to be NULL, treating them independently.  Previously,
  if either one was NULL, the other was ignored.
* If the zone argument is specified, then the current date is calculated
  in the specified zone, not in local time.
Also add some disabled debug code.
This should fix PR lib/47916.
Fix capitalization and typo, from Bug Hunting.
Document that errno may be used to distinguish between a
non-error result of -1 and an error.
Document that years in ISO 8601 dates are taken literally.
"69-09-10" is in the year 69, not 2069.
The tzoff argument is in minutes (behind/west of UTC), not seconds.
While here, also say that time = NULL and tzoff = NULL are independent.
The code doesn't yet implement that, but it will soon.
mention the PR# in the description like everyone else.
To be on the safe side, use the category/number notation when referring to
PRs (otherwise third-party sed-scripts might miss the references). Also
remove white-space.
* Test that parsedate("@0", ...) returns (time_t)0 regardless of timezone.
* Test that parsedate("@-1", NULL, NULL) returns (time_t)-1
  without setting errno.
Test parsedate("@-2",...) (should return -2 and not set errno);
and parsedate("@junk",...) (should return -1 and set errno).
We were already testing "@-1".
Add local parsecheck() function and use it for several tests.
Instead of just checking that parsedate(3) does not return an error,
also pass the result through localtime_r(3) or gmtime_r(3) and check the
year/month/day/hour/minute/second fields in the resulting struct tm.
Add comments for some non-obvious cases.
Also add a test with year=70, which is documented to be treated as 1970.
Adapt to a recent change in parsedate().
"9/10/69" still refers to 2069, and "9/10/70" still refers to 1970,
but "69-09-10" and "70-09-10" now refer to the years 69 and 70.
Add tests for PR lib/47916.  Some of these fail.
When tests fail, print all args, notjust the date string.
2013-07-09 was in British Summer TIme, so use tzoff=-60, not 0.

diffstat:

 lib/libutil/parsedate.3         |   43 +++++-
 lib/libutil/parsedate.y         |  226 ++++++++++++++++++++++-----------------
 tests/lib/libutil/t_parsedate.c |  219 +++++++++++++++++++++++++++++++++++---
 3 files changed, 358 insertions(+), 130 deletions(-)

diffs (truncated from 794 to 300 lines):

diff -r ae38a31504d1 -r c68b8d4c2b83 lib/libutil/parsedate.3
--- a/lib/libutil/parsedate.3   Thu Apr 16 13:40:00 2015 +0000
+++ b/lib/libutil/parsedate.3   Fri Apr 17 10:24:09 2015 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: parsedate.3,v 1.10 2010/12/22 09:12:28 wiz Exp $
+.\"     $NetBSD: parsedate.3,v 1.10.8.1 2015/04/17 10:24:09 msaitoh Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 20, 2010
+.Dd October 8, 2014
 .Dt PARSEDATE 3
 .Os
 .Sh NAME
@@ -44,17 +44,22 @@
 .Fn parsedate
 function parses a datetime from
 .Ar datestr
-described in english relative to an optional
+described in English relative to an optional
 .Ar time
-point and an optional timezone offset in seconds specified in
+point,
+and an optional timezone offset (in minutes behind/west of UTC)
+specified in
 .Ar tzoff .
-If either
+If
 .Ar time
-or
+is
+.Dv NULL 
+then the current time is used.
+If
 .Ar tzoff
-are
+is
 .Dv NULL ,
-then the current time and timezone offset are used.
+then the current time zone is used.
 .Pp
 The
 .Ar datestr
@@ -94,7 +99,7 @@
 10,
 .Dv eleventh or eleven =
 11,
-.Dv twelfth or twoelve =
+.Dv twelfth or twelve =
 12.
 .Pp
 The following words are recognized in English only:
@@ -198,11 +203,14 @@
 .Pp
 A variety of unambiguous dates are recognized:
 .Bl -tag -compact -width "20 Jun 1994"
-.It 69-09-10
+.It 9/10/69
 For years between 69-99 we assume 1900+ and for years between 0-68
 we assume 2000+.
 .It 2006-11-17
 An ISO-8601 date.
+.It 69-09-10
+The year in an ISO-8601 date is always taken literally,
+so this is the year 69, not 2069.
 .It 10/1/2000
 October 10, 2000; the common US format.
 .It 20 Jun 1994
@@ -210,7 +218,8 @@
 .It 1-sep-06
 Other common abbreviations.
 .It 1/11
-the year can be omitted
+The year can be omitted.
+This is the US month/day format.
 .El
 .Pp
 As well as times:
@@ -241,8 +250,20 @@
 returns the number of seconds passed since the Epoch, or
 .Dv \-1
 if the date could not be parsed properly.
+A non-error result of
+.Dv \-1
+can be distinguished from an error by setting
+.Va errno
+to
+.Dv 0
+before calling
+.Fn parsedate ,
+and checking the value of
+.Va errno
+afterwards.
 .Sh SEE ALSO
 .Xr date 1 ,
+.Xr errno 2 ,
 .Xr eeprom 8
 .Sh HISTORY
 The parser used in
diff -r ae38a31504d1 -r c68b8d4c2b83 lib/libutil/parsedate.y
--- a/lib/libutil/parsedate.y   Thu Apr 16 13:40:00 2015 +0000
+++ b/lib/libutil/parsedate.y   Fri Apr 17 10:24:09 2015 +0000
@@ -12,8 +12,14 @@
 /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
+#include <sys/cdefs.h>
+#ifdef __RCSID
+__RCSID("$NetBSD: parsedate.y,v 1.11.2.2 2015/04/17 10:24:09 msaitoh Exp $");
+#endif
+
 #include <stdio.h>
 #include <ctype.h>
+#include <errno.h>
 #include <string.h>
 #include <time.h>
 #include <util.h>
@@ -36,6 +42,7 @@
 #define HOUR(x)                ((time_t)(x) * 60)
 #define SECSPERDAY     (24L * 60L * 60L)
 
+#define USE_LOCAL_TIME 99999 /* special case for Convert() and yyTimezone */
 
 /*
 **  An entry in the lexical lookup table.
@@ -63,22 +70,24 @@
 
 
 struct dateinfo {
-       DSTMODE yyDSTmode;
+       DSTMODE yyDSTmode;      /* DST on/off/maybe */
        time_t  yyDayOrdinal;
        time_t  yyDayNumber;
        int     yyHaveDate;
+       int     yyHaveFullYear; /* if true, year is not abbreviated. */
+                               /* if false, need to call AdjustYear(). */
        int     yyHaveDay;
        int     yyHaveRel;
        int     yyHaveTime;
        int     yyHaveZone;
-       time_t  yyTimezone;
-       time_t  yyDay;
-       time_t  yyHour;
-       time_t  yyMinutes;
-       time_t  yyMonth;
-       time_t  yySeconds;
-       time_t  yyYear;
-       MERIDIAN        yyMeridian;
+       time_t  yyTimezone;     /* Timezone as minutes ahead/east of UTC */
+       time_t  yyDay;          /* Day of month [1-31] */
+       time_t  yyHour;         /* Hour of day [0-24] or [1-12] */
+       time_t  yyMinutes;      /* Minute of hour [0-59] */
+       time_t  yyMonth;        /* Month of year [1-12] */
+       time_t  yySeconds;      /* Second of minute [0-60] */
+       time_t  yyYear;         /* Year, see also yyHaveFullYear */
+       MERIDIAN yyMeridian;    /* Interpret yyHour as AM/PM/24 hour clock */
        time_t  yyRelMonth;
        time_t  yyRelSeconds;
 };
@@ -110,6 +119,10 @@
 item   : time {
            param->yyHaveTime++;
        }
+       | time_numericzone {
+           param->yyHaveTime++;
+           param->yyHaveZone++;
+       }
        | zone {
            param->yyHaveZone++;
        }
@@ -138,6 +151,7 @@
 cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER {
            param->yyYear = $1;
            if (param->yyYear < 100) param->yyYear += 1900;
+           param->yyHaveFullYear = 1;
            param->yyMonth = $3;
            param->yyDay = $5;
            param->yyHour = $7;
@@ -148,8 +162,8 @@
        }
        ;
 
-epochdate: AT_SIGN tUNUMBER {
-            time_t    when = $2;
+epochdate: AT_SIGN at_number {
+            time_t    when = $<Number>2;
             struct tm tmbuf;
             if (gmtime_r(&when, &tmbuf) != NULL) {
                param->yyYear = tmbuf.tm_year + 1900;
@@ -168,11 +182,14 @@
                param->yyMinutes = 0;
                param->yySeconds = 0;
            }
+           param->yyHaveFullYear = 1;
            param->yyDSTmode = DSToff;
            param->yyTimezone = 0;
        }
        ;
 
+at_number : tUNUMBER | tSNUMBER ;
+
 time   : tUNUMBER tMERIDIAN {
            param->yyHour = $1;
            param->yyMinutes = 0;
@@ -185,19 +202,28 @@
            param->yySeconds = 0;
            param->yyMeridian = $4;
        }
-       | tUNUMBER ':' tUNUMBER tSNUMBER {
+       | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
+           param->yyHour = $1;
+           param->yyMinutes = $3;
+           param->yySeconds = $5;
+           param->yyMeridian = $6;
+       }
+       | tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
+           param->yyHour = $1;
+           param->yyMinutes = $3;
+           param->yySeconds = $5;
+           param->yyMeridian = MER24;
+/* XXX: Do nothing with millis */
+       }
+       ;
+
+time_numericzone : tUNUMBER ':' tUNUMBER tSNUMBER {
            param->yyHour = $1;
            param->yyMinutes = $3;
            param->yyMeridian = MER24;
            param->yyDSTmode = DSToff;
            param->yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
        }
-       | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yySeconds = $5;
-           param->yyMeridian = $6;
-       }
        | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
            param->yyHour = $1;
            param->yyMinutes = $3;
@@ -206,15 +232,6 @@
            param->yyDSTmode = DSToff;
            param->yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
        }
-       | tUNUMBER ':' tUNUMBER ':' tUNUMBER '.' tUNUMBER {
-           param->yyHour = $1;
-           param->yyMinutes = $3;
-           param->yySeconds = $5;
-           param->yyMeridian = MER24;
-           param->yyDSTmode = DSToff;
-/* XXX: Do nothing with millis */
-/*         param->yyTimezone = ($7 % 100 + ($7 / 100) * 60); */
-       }
        ;
 
 zone   : tZONE {
@@ -264,6 +281,7 @@
        | tUNUMBER tSNUMBER tSNUMBER {
            /* ISO 8601 format.  yyyy-mm-dd.  */
            param->yyYear = $1;
+           param->yyHaveFullYear = 1;
            param->yyMonth = -$2;
            param->yyDay = -$3;
        }
@@ -573,26 +591,16 @@
 }
 
 
-/* Year is either
-   * A negative number, which means to use its absolute value (why?)
-   * A number from 0 to 99, which means a year from 1900 to 1999, or
-   * The actual year (>=100).  */
+/* Adjust year from a value that might be abbreviated, to a full value.
+ * e.g. convert 70 to 1970.
+ * Input Year is either:
+ *  - A negative number, which means to use its absolute value (why?)
+ *  - A number from 0 to 99, which means a year from 1900 to 1999, or
+ *  - The actual year (>=100).
+ * Returns the full year. */
 static time_t
-Convert(
-    time_t     Month,          /* month of year [1-12] */
-    time_t     Day,            /* day of month [1-31] */
-    time_t     Year,           /* year; see above comment */
-    time_t     Hours,          /* Hour of day [0-24] */
-    time_t     Minutes,        /* Minute of hour [0-59] */
-    time_t     Seconds,        /* Second of minute [0-60] */
-    time_t     Timezone,       /* Timezone as seconds west of UTC */
-    MERIDIAN   Meridian,       /* Hours are am/pm/24 hour clock */
-    DSTMODE    DSTmode         /* DST on/off/maybe */
-)
+AdjustYear(time_t Year)
 {
-    struct tm tm = {.tm_sec = 0};
-    time_t result;
-



Home | Main Index | Thread Index | Old Index