Source-Changes-HG archive

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

[src/trunk]: src/lib/libutil POSIX requires that when converting 2 digit year...



details:   https://anonhg.NetBSD.org/src/rev/cb014bdd94f6
branches:  trunk
changeset: 956035:cb014bdd94f6
user:      kre <kre%NetBSD.org@localhost>
date:      Mon Oct 19 15:05:53 2020 +0000

description:
POSIX requires that when converting 2 digit year representations to
actual specific years, values from 69-99 be treated as 20th century,
and values from 0-68 be treated as 21st century.  This allows for those
unfortunate enough to reside in a timezone west of Greenwich to convert
the epoch (or a time very close to it) to text, write that with just two
digits, and correctly convert it back to a time near the epoch, rather
than to something in 2069.

We used to split things so 0-69 were 21st century, and 70-99 were 20th.
Change that (this requires a change in the parsedate ATF tests which
test this specific boundary).

While here, add support for another POSIX requirement, that the radix
char before fractional seconds can be either a ',' or a '.'.  We used
to allow only '.', add support for ','.   This is something of a meaningless
change, as parsedate() returns a time_t in which there is no way to
represent fractional seconds, so there's little point in ever specifying
them regardless of what char is used for the "decimal point" - they will
be ignored anyway.    But at least fractional seconds using a ',' as the
radix char will no longer cause the conversion to fail (or do something else
bizarre).

diffstat:

 lib/libutil/parsedate.y |  16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r 73d1477c8ed6 -r cb014bdd94f6 lib/libutil/parsedate.y
--- a/lib/libutil/parsedate.y   Mon Oct 19 14:52:19 2020 +0000
+++ b/lib/libutil/parsedate.y   Mon Oct 19 15:05:53 2020 +0000
@@ -14,7 +14,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __RCSID
-__RCSID("$NetBSD: parsedate.y,v 1.32 2017/03/22 18:17:42 kre Exp $");
+__RCSID("$NetBSD: parsedate.y,v 1.33 2020/10/19 15:05:53 kre Exp $");
 #endif
 
 #include <stdio.h>
@@ -249,7 +249,14 @@
                param->yyMinutes = $3;
                param->yySeconds = $5;
                param->yyMeridian = MER24;
-               /* XXX: Do nothing with millis */
+               /* XXX: Do nothing with fractional secs ($7) */
+         }
+       | tUNUMBER ':' tUNUMBER ':' tUNUMBER ',' tUNUMBER {
+               param->yyHour = $1;
+               param->yyMinutes = $3;
+               param->yySeconds = $5;
+               param->yyMeridian = MER24;
+               /* XXX: Do nothing with fractional seconds ($7) */
          }
        | tTIME {
                param->yyHour = $1;
@@ -664,7 +671,8 @@
  * 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
+ *  - A number from 0 to 68, which means a year from 2000 to 2068, 
+ *  - A number from 69 to 99, which means a year from 1969 to 1999, or
  *  - The actual year (>=100).
  * Returns the full year.
  */
@@ -674,7 +682,7 @@
     /* XXX Y2K */
     if (Year < 0)
        Year = -Year;
-    if (Year < 70)
+    if (Year < 69)     /* POSIX compliant, 0..68 is 2000's, 69-99 1900's */
        Year += 2000;
     else if (Year < 100)
        Year += 1900;



Home | Main Index | Thread Index | Old Index