3 ** Originally written by Steven M. Bellovin <smb@research.att.com> while
4 ** at the University of North Carolina at Chapel Hill. Later tweaked by
5 ** a couple of people on Usenet. Completely overhauled by Rich $alz
6 ** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
8 ** This code is in the public domain and has no copyright.
18 /* Since the code of getdate.y is not included in the Emacs executable
19 itself, there is no need to #define static in this file. Even if
20 the code were included in the Emacs executable, it probably
21 wouldn't do any harm to #undef it here; this will only cause
22 problems if we try to write to a static variable, which I don't
23 think this code needs to do. */
34 # include <stdlib.h> /* for `free'; used by Bison 1.27 */
37 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
38 # define IN_CTYPE_DOMAIN(c) 1
40 # define IN_CTYPE_DOMAIN(c) isascii(c)
43 #define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
44 #define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
45 #define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
46 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
48 /* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
49 - Its arg may be any int or unsigned int; it need not be an unsigned char.
50 - It's guaranteed to evaluate its argument exactly once.
51 - It's typically faster.
52 Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
53 only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
54 it's important to use the locale's definition of `digit' even when the
55 host does not conform to Posix. */
56 #define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
58 #if defined (STDC_HEADERS) || defined (USG)
62 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
63 # define __attribute__(x)
66 #ifndef ATTRIBUTE_UNUSED
67 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
70 /* Some old versions of bison generate parsers that use bcopy.
71 That loses on systems that don't provide the function, so we have
72 to redefine it here. */
73 #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
74 # define bcopy(from, to, len) memcpy ((to), (from), (len))
77 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
78 as well as gratuitiously global symbol names, so we can have multiple
79 yacc generated parsers in the same program. Note that these are only
80 the variables produced by yacc. If other parser generators (bison,
81 byacc, etc) produce additional global names that conflict at link time,
82 then those parser generators need to be fixed instead of adding those
83 names to this list. */
85 #define yymaxdepth gd_maxdepth
86 #define yyparse gd_parse
88 #define yyerror gd_error
89 #define yylval gd_lval
90 #define yychar gd_char
91 #define yydebug gd_debug
92 #define yypact gd_pact
99 #define yyexca gd_exca
100 #define yyerrflag gd_errflag
101 #define yynerrs gd_nerrs
105 #define yy_yys gd_yys
106 #define yystate gd_state
109 #define yy_yyv gd_yyv
111 #define yylloc gd_lloc
112 #define yyreds gd_reds /* With YYDEBUG defined */
113 #define yytoks gd_toks /* With YYDEBUG defined */
114 #define yylhs gd_yylhs
115 #define yylen gd_yylen
116 #define yydefred gd_yydefred
117 #define yydgoto gd_yydgoto
118 #define yysindex gd_yysindex
119 #define yyrindex gd_yyrindex
120 #define yygindex gd_yygindex
121 #define yytable gd_yytable
122 #define yycheck gd_yycheck
125 static int yyerror ();
128 #define HOUR(x) ((x) * 60)
130 #define MAX_BUFF_LEN 128 /* size of buffer to read the date into */
133 ** An entry in the lexical lookup table.
135 typedef struct _TABLE {
143 ** Meridian: am, pm, or 24-hour style.
145 typedef enum _MERIDIAN {
151 ** Global variables. We could get rid of most of these by using a good
152 ** union as the yacc stack. (This routine was originally written before
153 ** yacc had the %union construct.) Maybe someday; right now we only use
154 ** the %union very rarely.
156 static const char *yyInput;
157 static int yyDayOrdinal;
158 static int yyDayNumber;
159 static int yyHaveDate;
160 static int yyHaveDay;
161 static int yyHaveRel;
162 static int yyHaveTime;
163 static int yyHaveZone;
164 static int yyTimezone;
167 static int yyMinutes;
169 static int yySeconds;
171 static MERIDIAN yyMeridian;
173 static int yyRelHour;
174 static int yyRelMinutes;
175 static int yyRelMonth;
176 static int yyRelSeconds;
177 static int yyRelYear;
181 /* This grammar has 13 shift/reduce conflicts. */
186 enum _MERIDIAN Meridian;
189 %token tAGO tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID
190 %token tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
191 %token tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE
193 %type <Number> tDAY tDAY_UNIT tDAYZONE tHOUR_UNIT tMINUTE_UNIT
194 %type <Number> tMONTH tMONTH_UNIT
195 %type <Number> tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE
196 %type <Meridian> tMERIDIAN o_merid
222 time : tUNUMBER tMERIDIAN {
228 | tUNUMBER ':' tUNUMBER o_merid {
234 | tUNUMBER ':' tUNUMBER tSNUMBER {
240 ? -$4 % 100 + (-$4 / 100) * 60
241 : - ($4 % 100 + ($4 / 100) * 60));
243 | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
249 | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
256 ? -$6 % 100 + (-$6 / 100) * 60
257 : - ($6 % 100 + ($6 / 100) * 60));
265 yyTimezone = $1 - 60;
269 yyTimezone = $1 - 60;
287 date : tUNUMBER '/' tUNUMBER {
291 | tUNUMBER '/' tUNUMBER '/' tUNUMBER {
292 /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
293 The goal in recognizing YYYY/MM/DD is solely to support legacy
294 machine-generated dates like those in an RCS log listing. If
295 you want portability, use the ISO 8601 format. */
309 | tUNUMBER tSNUMBER tSNUMBER {
310 /* ISO 8601 format. yyyy-mm-dd. */
315 | tUNUMBER tMONTH tSNUMBER {
316 /* e.g. 17-JUN-1992. */
325 | tMONTH tUNUMBER ',' tUNUMBER {
334 | tUNUMBER tMONTH tUNUMBER {
342 yyRelSeconds = -yyRelSeconds;
343 yyRelMinutes = -yyRelMinutes;
344 yyRelHour = -yyRelHour;
345 yyRelDay = -yyRelDay;
346 yyRelMonth = -yyRelMonth;
347 yyRelYear = -yyRelYear;
352 relunit : tUNUMBER tYEAR_UNIT {
353 yyRelYear += $1 * $2;
355 | tSNUMBER tYEAR_UNIT {
356 yyRelYear += $1 * $2;
361 | tUNUMBER tMONTH_UNIT {
362 yyRelMonth += $1 * $2;
364 | tSNUMBER tMONTH_UNIT {
365 yyRelMonth += $1 * $2;
370 | tUNUMBER tDAY_UNIT {
373 | tSNUMBER tDAY_UNIT {
379 | tUNUMBER tHOUR_UNIT {
380 yyRelHour += $1 * $2;
382 | tSNUMBER tHOUR_UNIT {
383 yyRelHour += $1 * $2;
388 | tUNUMBER tMINUTE_UNIT {
389 yyRelMinutes += $1 * $2;
391 | tSNUMBER tMINUTE_UNIT {
392 yyRelMinutes += $1 * $2;
397 | tUNUMBER tSEC_UNIT {
398 yyRelSeconds += $1 * $2;
400 | tSNUMBER tSEC_UNIT {
401 yyRelSeconds += $1 * $2;
410 if (yyHaveTime && yyHaveDate && !yyHaveRel)
418 yyMonth= ($1/100)%100;
432 yyMinutes = $1 % 100;
453 /* Include this file down here because bison inserts code above which
454 may define-away `const'. We want the prototype for get_date to have
455 the same signature as the function definition does. */
458 extern struct tm *gmtime ();
459 extern struct tm *localtime ();
460 extern time_t mktime ();
462 /* Month and day table. */
463 static TABLE const MonthDayTable[] = {
464 { "january", tMONTH, 1 },
465 { "february", tMONTH, 2 },
466 { "march", tMONTH, 3 },
467 { "april", tMONTH, 4 },
468 { "may", tMONTH, 5 },
469 { "june", tMONTH, 6 },
470 { "july", tMONTH, 7 },
471 { "august", tMONTH, 8 },
472 { "september", tMONTH, 9 },
473 { "sept", tMONTH, 9 },
474 { "october", tMONTH, 10 },
475 { "november", tMONTH, 11 },
476 { "december", tMONTH, 12 },
477 { "sunday", tDAY, 0 },
478 { "monday", tDAY, 1 },
479 { "tuesday", tDAY, 2 },
481 { "wednesday", tDAY, 3 },
482 { "wednes", tDAY, 3 },
483 { "thursday", tDAY, 4 },
485 { "thurs", tDAY, 4 },
486 { "friday", tDAY, 5 },
487 { "saturday", tDAY, 6 },
491 /* Time units table. */
492 static TABLE const UnitsTable[] = {
493 { "year", tYEAR_UNIT, 1 },
494 { "month", tMONTH_UNIT, 1 },
495 { "fortnight", tDAY_UNIT, 14 },
496 { "week", tDAY_UNIT, 7 },
497 { "day", tDAY_UNIT, 1 },
498 { "hour", tHOUR_UNIT, 1 },
499 { "minute", tMINUTE_UNIT, 1 },
500 { "min", tMINUTE_UNIT, 1 },
501 { "second", tSEC_UNIT, 1 },
502 { "sec", tSEC_UNIT, 1 },
506 /* Assorted relative-time words. */
507 static TABLE const OtherTable[] = {
508 { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 },
509 { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 },
510 { "today", tMINUTE_UNIT, 0 },
511 { "now", tMINUTE_UNIT, 0 },
512 { "last", tUNUMBER, -1 },
513 { "this", tMINUTE_UNIT, 0 },
514 { "next", tUNUMBER, 1 },
515 { "first", tUNUMBER, 1 },
516 /* { "second", tUNUMBER, 2 }, */
517 { "third", tUNUMBER, 3 },
518 { "fourth", tUNUMBER, 4 },
519 { "fifth", tUNUMBER, 5 },
520 { "sixth", tUNUMBER, 6 },
521 { "seventh", tUNUMBER, 7 },
522 { "eighth", tUNUMBER, 8 },
523 { "ninth", tUNUMBER, 9 },
524 { "tenth", tUNUMBER, 10 },
525 { "eleventh", tUNUMBER, 11 },
526 { "twelfth", tUNUMBER, 12 },
531 /* The timezone table. */
532 static TABLE const TimezoneTable[] = {
533 { "gmt", tZONE, HOUR ( 0) }, /* Greenwich Mean */
534 { "ut", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
535 { "utc", tZONE, HOUR ( 0) },
536 { "wet", tZONE, HOUR ( 0) }, /* Western European */
537 { "bst", tDAYZONE, HOUR ( 0) }, /* British Summer */
538 { "wat", tZONE, HOUR ( 1) }, /* West Africa */
539 { "at", tZONE, HOUR ( 2) }, /* Azores */
541 /* For completeness. BST is also British Summer, and GST is
542 * also Guam Standard. */
543 { "bst", tZONE, HOUR ( 3) }, /* Brazil Standard */
544 { "gst", tZONE, HOUR ( 3) }, /* Greenland Standard */
547 { "nft", tZONE, HOUR (3.5) }, /* Newfoundland */
548 { "nst", tZONE, HOUR (3.5) }, /* Newfoundland Standard */
549 { "ndt", tDAYZONE, HOUR (3.5) }, /* Newfoundland Daylight */
551 { "ast", tZONE, HOUR ( 4) }, /* Atlantic Standard */
552 { "adt", tDAYZONE, HOUR ( 4) }, /* Atlantic Daylight */
553 { "est", tZONE, HOUR ( 5) }, /* Eastern Standard */
554 { "edt", tDAYZONE, HOUR ( 5) }, /* Eastern Daylight */
555 { "cst", tZONE, HOUR ( 6) }, /* Central Standard */
556 { "cdt", tDAYZONE, HOUR ( 6) }, /* Central Daylight */
557 { "mst", tZONE, HOUR ( 7) }, /* Mountain Standard */
558 { "mdt", tDAYZONE, HOUR ( 7) }, /* Mountain Daylight */
559 { "pst", tZONE, HOUR ( 8) }, /* Pacific Standard */
560 { "pdt", tDAYZONE, HOUR ( 8) }, /* Pacific Daylight */
561 { "yst", tZONE, HOUR ( 9) }, /* Yukon Standard */
562 { "ydt", tDAYZONE, HOUR ( 9) }, /* Yukon Daylight */
563 { "hst", tZONE, HOUR (10) }, /* Hawaii Standard */
564 { "hdt", tDAYZONE, HOUR (10) }, /* Hawaii Daylight */
565 { "cat", tZONE, HOUR (10) }, /* Central Alaska */
566 { "ahst", tZONE, HOUR (10) }, /* Alaska-Hawaii Standard */
567 { "nt", tZONE, HOUR (11) }, /* Nome */
568 { "idlw", tZONE, HOUR (12) }, /* International Date Line West */
569 { "cet", tZONE, -HOUR (1) }, /* Central European */
570 { "met", tZONE, -HOUR (1) }, /* Middle European */
571 { "mewt", tZONE, -HOUR (1) }, /* Middle European Winter */
572 { "mest", tDAYZONE, -HOUR (1) }, /* Middle European Summer */
573 { "mesz", tDAYZONE, -HOUR (1) }, /* Middle European Summer */
574 { "swt", tZONE, -HOUR (1) }, /* Swedish Winter */
575 { "sst", tDAYZONE, -HOUR (1) }, /* Swedish Summer */
576 { "fwt", tZONE, -HOUR (1) }, /* French Winter */
577 { "fst", tDAYZONE, -HOUR (1) }, /* French Summer */
578 { "eet", tZONE, -HOUR (2) }, /* Eastern Europe, USSR Zone 1 */
579 { "bt", tZONE, -HOUR (3) }, /* Baghdad, USSR Zone 2 */
581 { "it", tZONE, -HOUR (3.5) },/* Iran */
583 { "zp4", tZONE, -HOUR (4) }, /* USSR Zone 3 */
584 { "zp5", tZONE, -HOUR (5) }, /* USSR Zone 4 */
586 { "ist", tZONE, -HOUR (5.5) },/* Indian Standard */
588 { "zp6", tZONE, -HOUR (6) }, /* USSR Zone 5 */
590 /* For completeness. NST is also Newfoundland Standard, and SST is
591 * also Swedish Summer. */
592 { "nst", tZONE, -HOUR (6.5) },/* North Sumatra */
593 { "sst", tZONE, -HOUR (7) }, /* South Sumatra, USSR Zone 6 */
595 { "wast", tZONE, -HOUR (7) }, /* West Australian Standard */
596 { "wadt", tDAYZONE, -HOUR (7) }, /* West Australian Daylight */
598 { "jt", tZONE, -HOUR (7.5) },/* Java (3pm in Cronusland!) */
600 { "cct", tZONE, -HOUR (8) }, /* China Coast, USSR Zone 7 */
601 { "jst", tZONE, -HOUR (9) }, /* Japan Standard, USSR Zone 8 */
603 { "cast", tZONE, -HOUR (9.5) },/* Central Australian Standard */
604 { "cadt", tDAYZONE, -HOUR (9.5) },/* Central Australian Daylight */
606 { "east", tZONE, -HOUR (10) }, /* Eastern Australian Standard */
607 { "eadt", tDAYZONE, -HOUR (10) }, /* Eastern Australian Daylight */
608 { "gst", tZONE, -HOUR (10) }, /* Guam Standard, USSR Zone 9 */
609 { "nzt", tZONE, -HOUR (12) }, /* New Zealand */
610 { "nzst", tZONE, -HOUR (12) }, /* New Zealand Standard */
611 { "nzdt", tDAYZONE, -HOUR (12) }, /* New Zealand Daylight */
612 { "idle", tZONE, -HOUR (12) }, /* International Date Line East */
616 /* Military timezone table. */
617 static TABLE const MilitaryTable[] = {
618 { "a", tZONE, HOUR ( 1) },
619 { "b", tZONE, HOUR ( 2) },
620 { "c", tZONE, HOUR ( 3) },
621 { "d", tZONE, HOUR ( 4) },
622 { "e", tZONE, HOUR ( 5) },
623 { "f", tZONE, HOUR ( 6) },
624 { "g", tZONE, HOUR ( 7) },
625 { "h", tZONE, HOUR ( 8) },
626 { "i", tZONE, HOUR ( 9) },
627 { "k", tZONE, HOUR ( 10) },
628 { "l", tZONE, HOUR ( 11) },
629 { "m", tZONE, HOUR ( 12) },
630 { "n", tZONE, HOUR (- 1) },
631 { "o", tZONE, HOUR (- 2) },
632 { "p", tZONE, HOUR (- 3) },
633 { "q", tZONE, HOUR (- 4) },
634 { "r", tZONE, HOUR (- 5) },
635 { "s", tZONE, HOUR (- 6) },
636 { "t", tZONE, HOUR (- 7) },
637 { "u", tZONE, HOUR (- 8) },
638 { "v", tZONE, HOUR (- 9) },
639 { "w", tZONE, HOUR (-10) },
640 { "x", tZONE, HOUR (-11) },
641 { "y", tZONE, HOUR (-12) },
642 { "z", tZONE, HOUR ( 0) },
652 char *s ATTRIBUTE_UNUSED;
658 ToHour (Hours, Meridian)
665 if (Hours < 0 || Hours > 23)
669 if (Hours < 1 || Hours > 12)
675 if (Hours < 1 || Hours > 12)
693 /* XPG4 suggests that years 00-68 map to 2000-2068, and
694 years 69-99 map to 1969-1999. */
709 register const TABLE *tp;
713 /* Make it lowercase. */
714 for (p = buff; *p; p++)
715 if (ISUPPER ((unsigned char) *p))
718 if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
720 yylval.Meridian = MERam;
723 if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
725 yylval.Meridian = MERpm;
729 /* See if we have an abbreviation for a month. */
730 if (strlen (buff) == 3)
732 else if (strlen (buff) == 4 && buff[3] == '.')
740 for (tp = MonthDayTable; tp->name; tp++)
744 if (strncmp (buff, tp->name, 3) == 0)
746 yylval.Number = tp->value;
750 else if (strcmp (buff, tp->name) == 0)
752 yylval.Number = tp->value;
757 for (tp = TimezoneTable; tp->name; tp++)
758 if (strcmp (buff, tp->name) == 0)
760 yylval.Number = tp->value;
764 if (strcmp (buff, "dst") == 0)
767 for (tp = UnitsTable; tp->name; tp++)
768 if (strcmp (buff, tp->name) == 0)
770 yylval.Number = tp->value;
774 /* Strip off any plural and try the units table again. */
775 i = strlen (buff) - 1;
779 for (tp = UnitsTable; tp->name; tp++)
780 if (strcmp (buff, tp->name) == 0)
782 yylval.Number = tp->value;
785 buff[i] = 's'; /* Put back for "this" in OtherTable. */
788 for (tp = OtherTable; tp->name; tp++)
789 if (strcmp (buff, tp->name) == 0)
791 yylval.Number = tp->value;
795 /* Military timezones. */
796 if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff))
798 for (tp = MilitaryTable; tp->name; tp++)
799 if (strcmp (buff, tp->name) == 0)
801 yylval.Number = tp->value;
806 /* Drop out any periods and try the timezone table again. */
807 for (i = 0, p = q = buff; *q; q++)
814 for (tp = TimezoneTable; tp->name; tp++)
815 if (strcmp (buff, tp->name) == 0)
817 yylval.Number = tp->value;
827 register unsigned char c;
835 while (ISSPACE ((unsigned char) *yyInput))
838 if (ISDIGIT (c = *yyInput) || c == '-' || c == '+')
840 if (c == '-' || c == '+')
842 sign = c == '-' ? -1 : 1;
843 if (!ISDIGIT (*++yyInput))
844 /* skip the '-' sign */
849 for (yylval.Number = 0; ISDIGIT (c = *yyInput++);)
850 yylval.Number = 10 * yylval.Number + c - '0';
853 yylval.Number = -yylval.Number;
854 return sign ? tSNUMBER : tUNUMBER;
858 for (p = buff; (c = *yyInput++, ISALPHA (c)) || c == '.';)
859 if (p < &buff[sizeof buff - 1])
863 return LookupWord (buff);
882 #define TM_YEAR_ORIGIN 1900
884 /* Yield A - B, measured in seconds. */
886 difftm (struct tm *a, struct tm *b)
888 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
889 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
891 /* difference in day of year */
892 a->tm_yday - b->tm_yday
893 /* + intervening leap days */
894 + ((ay >> 2) - (by >> 2))
895 - (ay / 100 - by / 100)
896 + ((ay / 100 >> 2) - (by / 100 >> 2))
897 /* + difference in years * 365 */
898 + (long) (ay - by) * 365
900 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
901 + (a->tm_min - b->tm_min))
902 + (a->tm_sec - b->tm_sec));
906 get_date (const char *p, const time_t *now)
908 struct tm tm, tm0, *tmp;
912 Start = now ? *now : time ((time_t *) NULL);
913 tmp = localtime (&Start);
916 yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
917 yyMonth = tmp->tm_mon + 1;
918 yyDay = tmp->tm_mday;
919 yyHour = tmp->tm_hour;
920 yyMinutes = tmp->tm_min;
921 yySeconds = tmp->tm_sec;
922 tm.tm_isdst = tmp->tm_isdst;
937 || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
940 tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN + yyRelYear;
941 tm.tm_mon = yyMonth - 1 + yyRelMonth;
942 tm.tm_mday = yyDay + yyRelDay;
943 if (yyHaveTime || (yyHaveRel && !yyHaveDate && !yyHaveDay))
945 tm.tm_hour = ToHour (yyHour, yyMeridian);
948 tm.tm_min = yyMinutes;
949 tm.tm_sec = yySeconds;
953 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
955 tm.tm_hour += yyRelHour;
956 tm.tm_min += yyRelMinutes;
957 tm.tm_sec += yyRelSeconds;
959 /* Let mktime deduce tm_isdst if we have an absolute timestamp,
960 or if the relative timestamp mentions days, months, or years. */
961 if (yyHaveDate | yyHaveDay | yyHaveTime | yyRelDay | yyRelMonth | yyRelYear)
966 Start = mktime (&tm);
968 if (Start == (time_t) -1)
971 /* Guard against falsely reporting errors near the time_t boundaries
972 when parsing times in other time zones. For example, if the min
973 time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
974 of UTC, then the min localtime value is 1970-01-01 08:00:00; if
975 we apply mktime to 1970-01-01 00:00:00 we will get an error, so
976 we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
977 zone by 24 hours to compensate. This algorithm assumes that
978 there is no DST transition within a day of the time_t boundaries. */
982 if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
985 yyTimezone -= 24 * 60;
990 yyTimezone += 24 * 60;
992 Start = mktime (&tm);
995 if (Start == (time_t) -1)
999 if (yyHaveDay && !yyHaveDate)
1001 tm.tm_mday += ((yyDayNumber - tm.tm_wday + 7) % 7
1002 + 7 * (yyDayOrdinal - (0 < yyDayOrdinal)));
1003 Start = mktime (&tm);
1004 if (Start == (time_t) -1)
1011 struct tm *gmt = gmtime (&Start);
1014 delta = yyTimezone * 60L + difftm (&tm, gmt);
1015 if ((Start + delta < Start) != (delta < 0))
1016 return -1; /* time_t overflow */
1031 char buff[MAX_BUFF_LEN + 1];
1034 (void) printf ("Enter date, or blank line to exit.\n\t> ");
1035 (void) fflush (stdout);
1037 buff[MAX_BUFF_LEN] = 0;
1038 while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0])
1040 d = get_date (buff, (time_t *) NULL);
1042 (void) printf ("Bad format - couldn't convert.\n");
1044 (void) printf ("%s", ctime (&d));
1045 (void) printf ("\t> ");
1046 (void) fflush (stdout);
1051 #endif /* defined (TEST) */