X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetdate.y;h=cc53fde59ddf8d35d42959320a1328550b63a848;hb=692c4b6ea764fd34a53142b53c53a2d54b33ae6a;hp=851bd9a92faf108acb23215dfbb182cc853d3e0d;hpb=1be7ab665dc2df5a419dfc04445b5a98b16666ca;p=gnulib.git diff --git a/lib/getdate.y b/lib/getdate.y index 851bd9a92..cc53fde59 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -14,10 +14,10 @@ /* SUPPRESS 288 on yyerrlab *//* Label unused */ #ifdef HAVE_CONFIG_H -#if defined (emacs) || defined (CONFIG_BROKETS) #include -#else -#include "config.h" + +#ifdef FORCE_ALLOCA_H +#include #endif #endif @@ -34,20 +34,11 @@ #include #include -/* The code at the top of get_date which figures out the offset of the - current time zone checks various CPP symbols to see if special - tricks are need, but defaults to using the gettimeofday system call. - Include if that will be used. */ - #if defined (vms) - #include #include - #else - #include - #ifdef TIME_WITH_SYS_TIME #include #include @@ -66,12 +57,12 @@ #if defined (HAVE_SYS_TIMEB_H) #include #else -/* -** We use the obsolete `struct timeb' as part of our interface! -** Since the system doesn't have it, we define it here; -** our callers must do likewise. -*/ -struct timeb { + +/* get_date uses the obsolete `struct timeb' in its interface! FIXME. + Since some systems don't have it, we define it here; + callers must do likewise. */ +struct timeb + { time_t time; /* Seconds since the epoch */ unsigned short millitm; /* Field not used */ short timezone; /* Minutes west of GMT */ @@ -103,6 +94,7 @@ static int yylex (); static int yyerror (); #define EPOCH 1970 +#define DOOMSDAY 2038 #define HOUR(x) ((time_t)(x) * 60) #define SECSPERDAY (24L * 60L * 60L) @@ -589,10 +581,14 @@ ToSeconds (Hours, Minutes, Seconds, Meridian) case MERam: if (Hours < 1 || Hours > 12) return -1; + if (Hours == 12) + Hours = 0; return (Hours * 60L + Minutes) * 60L + Seconds; case MERpm: if (Hours < 1 || Hours > 12) return -1; + if (Hours == 12) + Hours = 0; return ((Hours + 12) * 60L + Minutes) * 60L + Seconds; default: abort (); @@ -621,11 +617,13 @@ Convert (Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) if (Year < 0) Year = -Year; - if (Year < 100) + if (Year < DOOMSDAY-2000) + Year += 2000; + else if (Year < 100) Year += 1900; DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 29 : 28; - if (Year < EPOCH || Year > 1999 + if (Year < EPOCH || Year >= DOOMSDAY || Month < 1 || Month > 12 /* Lint fluff: "conversion from long may lose accuracy" */ || Day < 1 || Day > DaysInMonth[(int)--Month]) @@ -690,7 +688,7 @@ RelativeMonth (Start, RelMonth) if (RelMonth == 0) return 0; tm = localtime (&Start); - Month = 12 * tm->tm_year + tm->tm_mon + RelMonth; + Month = 12 * (1900 + tm->tm_year) + tm->tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; return DSTcorrect (Start, @@ -753,7 +751,7 @@ LookupWord (buff) return tp->type; } - if (strcmp (buff, "dst") == 0) + if (strcmp (buff, "dst") == 0) return tDST; for (tp = UnitsTable; tp->name; tp++) @@ -904,7 +902,7 @@ get_date (p, now) if (! (tm = localtime (&ftz.time))) return -1; - + ftz.timezone = difftm (&gmt, tm) / 60; if (tm->tm_isdst) ftz.timezone += 60; @@ -966,11 +964,13 @@ main (ac, av) int ac; char *av[]; { - char buff[128]; - time_t d; + char buff[MAX_BUFF_LEN + 1]; + time_t d; (void)printf ("Enter date, or blank line to exit.\n\t> "); (void)fflush (stdout); + + buff[MAX_BUFF_LEN] = 0; while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0]) { d = get_date (buff, (struct timeb *)NULL); if (d == -1)