summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorkre <kre@NetBSD.org>2020-10-19 15:05:53 +0000
committerkre <kre@NetBSD.org>2020-10-19 15:05:53 +0000
commit536d2ed15c90b726abab9514526bbf35d730c93f (patch)
tree65e1af7310399cada0b7b93801cc975a4563f15b /lib/libutil
parentee78b14a73fbc274898f0ef38c6213375e25dafb (diff)
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 (limited to 'lib/libutil')
-rw-r--r--lib/libutil/parsedate.y16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/libutil/parsedate.y b/lib/libutil/parsedate.y
index 92f3b4b5e8b..b872707c745 100644
--- a/lib/libutil/parsedate.y
+++ b/lib/libutil/parsedate.y
@@ -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 @@ time:
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 @@ RelVal(struct dateinfo *param, time_t v, int type)
* 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 @@ AdjustYear(time_t Year)
/* 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;