1 /* A Bison parser, made by GNU Bison 2.3. */
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
39 /* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
46 /* Identify Bison output. */
50 #define YYBISON_VERSION "2.3"
53 #define YYSKELETON_NAME "yacc.c"
58 /* Using locations. */
59 #define YYLSP_NEEDED 0
66 /* Put the tokens into the symbol table, so that GDB and other debuggers
87 tSDECIMAL_NUMBER = 276,
88 tUDECIMAL_NUMBER = 277
94 #define tYEAR_UNIT 260
95 #define tMONTH_UNIT 261
96 #define tHOUR_UNIT 262
97 #define tMINUTE_UNIT 263
100 #define tDAY_SHIFT 266
103 #define tLOCAL_ZONE 269
104 #define tMERIDIAN 270
110 #define tSDECIMAL_NUMBER 276
111 #define tUDECIMAL_NUMBER 277
116 /* Copy the first part of user declarations. */
117 #line 1 "parse-datetime.y"
119 /* Parse a string into an internal time stamp.
121 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
122 2010 Free Software Foundation, Inc.
124 This program is free software: you can redistribute it and/or modify
125 it under the terms of the GNU General Public License as published by
126 the Free Software Foundation; either version 3 of the License, or
127 (at your option) any later version.
129 This program is distributed in the hope that it will be useful,
130 but WITHOUT ANY WARRANTY; without even the implied warranty of
131 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132 GNU General Public License for more details.
134 You should have received a copy of the GNU General Public License
135 along with this program. If not, see <http://www.gnu.org/licenses/>. */
137 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
138 at the University of North Carolina at Chapel Hill. Later tweaked by
139 a couple of people on Usenet. Completely overhauled by Rich $alz
140 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
142 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
143 the right thing about local DST. Also modified by Paul Eggert
144 <eggert@cs.ucla.edu> in February 2004 to support
145 nanosecond-resolution time stamps, and in October 2004 to support
146 TZ strings in dates. */
148 /* FIXME: Check for arithmetic overflow in all cases, not just
153 #include "parse-datetime.h"
155 #include "intprops.h"
156 #include "timespec.h"
159 /* There's no need to extend the stack, so there's no need to involve
161 #define YYSTACK_USE_ALLOCA 0
163 /* Tell Bison how much stack space is needed. 20 should be plenty for
164 this grammar, which is not right recursive. Beware setting it too
165 high, since that might cause problems on machines whose
166 implementations have lame stack-overflow checking. */
167 #define YYMAXDEPTH 20
168 #define YYINITDEPTH YYMAXDEPTH
170 /* Since the code of parse-datetime.y is not included in the Emacs executable
171 itself, there is no need to #define static in this file. Even if
172 the code were included in the Emacs executable, it probably
173 wouldn't do any harm to #undef it here; this will only cause
174 problems if we try to write to a static variable, which I don't
175 think this code needs to do. */
188 /* Bison's skeleton tests _STDLIB_H, while some stdlib.h headers
189 use _STDLIB_H_ as witness. Map the latter to the one bison uses. */
190 /* FIXME: this is temporary. Remove when we have a mechanism to ensure
191 that the version we're using is fixed, too. */
197 /* ISDIGIT differs from isdigit, as follows:
198 - Its arg may be any int or unsigned int; it need not be an unsigned char
200 - It's typically faster.
201 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
202 isdigit unless it's important to use the locale's definition
203 of `digit' even when the host does not conform to POSIX. */
204 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
206 /* Shift A right by B bits portably, by dividing A by 2**B and
207 truncating towards minus infinity. A and B should be free of side
208 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
209 INT_BITS is the number of useful bits in an int. GNU code can
210 assume that INT_BITS is at least 32.
212 ISO C99 says that A >> B is implementation-defined if A < 0. Some
213 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
214 right in the usual way when A < 0, so SHR falls back on division if
215 ordinary A >> B doesn't seem to be the usual signed shift. */
219 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
221 #define EPOCH_YEAR 1970
222 #define TM_YEAR_BASE 1900
224 #define HOUR(x) ((x) * 60)
226 /* long_time_t is a signed integer type that contains all time_t values. */
227 verify (TYPE_IS_INTEGER (time_t));
228 #if TIME_T_FITS_IN_LONG_INT
229 typedef long int long_time_t;
231 typedef time_t long_time_t;
234 /* Lots of this code assumes time_t and time_t-like values fit into
236 verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t)
237 && TYPE_MAXIMUM (time_t) <= TYPE_MAXIMUM (long_time_t));
239 /* FIXME: It also assumes that signed integer overflow silently wraps around,
240 but this is not true any more with recent versions of GCC 4. */
242 /* An integer value, and the number of digits in its textual
251 /* An entry in the lexical lookup table. */
259 /* Meridian: am, pm, or 24-hour style. */
260 enum { MERam, MERpm, MER24 };
262 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
264 /* Relative times. */
267 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
277 #if HAVE_COMPOUND_LITERALS
278 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
280 static relative_time const RELATIVE_TIME_0;
283 /* Information passed to and from the parser. */
286 /* The input string remaining to be parsed. */
289 /* N, if this is the Nth Tuesday. */
290 long int day_ordinal;
292 /* Day of week; Sunday is 0. */
295 /* tm_isdst flag for the local zone. */
298 /* Time zone, in minutes east of UTC. */
301 /* Style used for time. */
304 /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */
310 struct timespec seconds; /* includes nanoseconds */
312 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
315 /* Presence or counts of nonterminals of various flavors parsed so far. */
320 size_t local_zones_seen;
325 /* Table of local time zone abbrevations, terminated by a null entry. */
326 table local_time_zone_table[3];
330 static int yylex (union YYSTYPE *, parser_control *);
331 static int yyerror (parser_control const *, char const *);
332 static long int time_zone_hhmm (parser_control *, textint, long int);
334 /* Extract into *PC any date and time info from a string of digits
335 of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY,
338 digits_to_date_time (parser_control *pc, textint text_int)
340 if (pc->dates_seen && ! pc->year.digits
341 && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
345 if (4 < text_int.digits)
348 pc->day = text_int.value % 100;
349 pc->month = (text_int.value / 100) % 100;
350 pc->year.value = text_int.value / 10000;
351 pc->year.digits = text_int.digits - 4;
356 if (text_int.digits <= 2)
358 pc->hour = text_int.value;
363 pc->hour = text_int.value / 100;
364 pc->minutes = text_int.value % 100;
366 pc->seconds.tv_sec = 0;
367 pc->seconds.tv_nsec = 0;
368 pc->meridian = MER24;
373 /* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). */
375 apply_relative_time (parser_control *pc, relative_time rel, int factor)
377 pc->rel.ns += factor * rel.ns;
378 pc->rel.seconds += factor * rel.seconds;
379 pc->rel.minutes += factor * rel.minutes;
380 pc->rel.hour += factor * rel.hour;
381 pc->rel.day += factor * rel.day;
382 pc->rel.month += factor * rel.month;
383 pc->rel.year += factor * rel.year;
384 pc->rels_seen = true;
387 /* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */
389 set_hhmmss (parser_control *pc, long int hour, long int minutes,
390 time_t sec, long int nsec)
393 pc->minutes = minutes;
394 pc->seconds.tv_sec = sec;
395 pc->seconds.tv_nsec = nsec;
400 /* Enabling traces. */
405 /* Enabling verbose error messages. */
406 #ifdef YYERROR_VERBOSE
407 # undef YYERROR_VERBOSE
408 # define YYERROR_VERBOSE 1
410 # define YYERROR_VERBOSE 0
413 /* Enabling the token table. */
414 #ifndef YYTOKEN_TABLE
415 # define YYTOKEN_TABLE 0
418 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
419 typedef union YYSTYPE
420 #line 293 "parse-datetime.y"
424 struct timespec timespec;
427 /* Line 187 of yacc.c. */
428 #line 429 "parse-datetime.c"
430 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
431 # define YYSTYPE_IS_DECLARED 1
432 # define YYSTYPE_IS_TRIVIAL 1
437 /* Copy the second part of user declarations. */
440 /* Line 216 of yacc.c. */
441 #line 442 "parse-datetime.c"
448 typedef YYTYPE_UINT8 yytype_uint8;
450 typedef unsigned char yytype_uint8;
454 typedef YYTYPE_INT8 yytype_int8;
455 #elif (defined __STDC__ || defined __C99__FUNC__ \
456 || defined __cplusplus || defined _MSC_VER)
457 typedef signed char yytype_int8;
459 typedef short int yytype_int8;
463 typedef YYTYPE_UINT16 yytype_uint16;
465 typedef unsigned short int yytype_uint16;
469 typedef YYTYPE_INT16 yytype_int16;
471 typedef short int yytype_int16;
475 # ifdef __SIZE_TYPE__
476 # define YYSIZE_T __SIZE_TYPE__
477 # elif defined size_t
478 # define YYSIZE_T size_t
479 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
480 || defined __cplusplus || defined _MSC_VER)
481 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
482 # define YYSIZE_T size_t
484 # define YYSIZE_T unsigned int
488 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
493 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
494 # define YY_(msgid) dgettext ("bison-runtime", msgid)
498 # define YY_(msgid) msgid
502 /* Suppress unused-variable warnings by "using" E. */
503 #if ! defined lint || defined __GNUC__
504 # define YYUSE(e) ((void) (e))
506 # define YYUSE(e) /* empty */
509 /* Identity function, used to suppress warnings about constant conditions. */
513 #if (defined __STDC__ || defined __C99__FUNC__ \
514 || defined __cplusplus || defined _MSC_VER)
527 #if ! defined yyoverflow || YYERROR_VERBOSE
529 /* The parser invokes alloca or malloc; define the necessary symbols. */
531 # ifdef YYSTACK_USE_ALLOCA
532 # if YYSTACK_USE_ALLOCA
534 # define YYSTACK_ALLOC __builtin_alloca
535 # elif defined __BUILTIN_VA_ARG_INCR
536 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
538 # define YYSTACK_ALLOC __alloca
539 # elif defined _MSC_VER
540 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
541 # define alloca _alloca
543 # define YYSTACK_ALLOC alloca
544 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
545 || defined __cplusplus || defined _MSC_VER)
546 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
555 # ifdef YYSTACK_ALLOC
556 /* Pacify GCC's `empty if-body' warning. */
557 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
558 # ifndef YYSTACK_ALLOC_MAXIMUM
559 /* The OS might guarantee only one guard page at the bottom of the stack,
560 and a page size can be as small as 4096 bytes. So we cannot safely
561 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
562 to allow for a few compiler-allocated temporary stack slots. */
563 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
566 # define YYSTACK_ALLOC YYMALLOC
567 # define YYSTACK_FREE YYFREE
568 # ifndef YYSTACK_ALLOC_MAXIMUM
569 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
571 # if (defined __cplusplus && ! defined _STDLIB_H \
572 && ! ((defined YYMALLOC || defined malloc) \
573 && (defined YYFREE || defined free)))
574 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
580 # define YYMALLOC malloc
581 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
582 || defined __cplusplus || defined _MSC_VER)
583 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
588 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
589 || defined __cplusplus || defined _MSC_VER)
590 void free (void *); /* INFRINGES ON USER NAME SPACE */
594 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
597 #if (! defined yyoverflow \
598 && (! defined __cplusplus \
599 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
601 /* A type that is properly aligned for any stack member. */
608 /* The size of the maximum gap between one aligned stack and the next. */
609 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
611 /* The size of an array large to enough to hold all stacks, each with
613 # define YYSTACK_BYTES(N) \
614 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
615 + YYSTACK_GAP_MAXIMUM)
617 /* Copy COUNT objects from FROM to TO. The source and destination do
620 # if defined __GNUC__ && 1 < __GNUC__
621 # define YYCOPY(To, From, Count) \
622 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
624 # define YYCOPY(To, From, Count) \
628 for (yyi = 0; yyi < (Count); yyi++) \
629 (To)[yyi] = (From)[yyi]; \
635 /* Relocate STACK from its old location to the new one. The
636 local variables YYSIZE and YYSTACKSIZE give the old and new number of
637 elements in the stack, and YYPTR gives the new location of the
638 stack. Advance YYPTR to a properly aligned location for the next
640 # define YYSTACK_RELOCATE(Stack) \
643 YYSIZE_T yynewbytes; \
644 YYCOPY (&yyptr->Stack, Stack, yysize); \
645 Stack = &yyptr->Stack; \
646 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
647 yyptr += yynewbytes / sizeof (*yyptr); \
653 /* YYFINAL -- State number of the termination state. */
655 /* YYLAST -- Last index in YYTABLE. */
658 /* YYNTOKENS -- Number of terminals. */
660 /* YYNNTS -- Number of nonterminals. */
662 /* YYNRULES -- Number of rules. */
664 /* YYNRULES -- Number of states. */
665 #define YYNSTATES 100
667 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
669 #define YYMAXUTOK 277
671 #define YYTRANSLATE(YYX) \
672 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
674 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
675 static const yytype_uint8 yytranslate[] =
677 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
678 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
679 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
680 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
681 2, 2, 2, 2, 25, 2, 2, 26, 2, 2,
682 2, 2, 2, 2, 2, 2, 2, 2, 24, 2,
683 2, 2, 2, 2, 23, 2, 2, 2, 2, 2,
684 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
685 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
686 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
687 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
688 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
689 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
690 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
691 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
692 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
693 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
694 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
695 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
696 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
697 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
698 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
699 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
700 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
701 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
702 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
703 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
704 15, 16, 17, 18, 19, 20, 21, 22
708 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
710 static const yytype_uint8 yyprhs[] =
712 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
713 20, 22, 24, 26, 28, 30, 33, 38, 44, 51,
714 59, 61, 64, 66, 69, 73, 75, 78, 80, 83,
715 86, 89, 93, 99, 103, 107, 111, 114, 119, 122,
716 126, 129, 131, 133, 136, 139, 141, 144, 147, 149,
717 152, 155, 157, 160, 163, 165, 168, 171, 173, 176,
718 179, 182, 185, 187, 189, 192, 195, 198, 201, 204,
719 207, 209, 211, 213, 215, 217, 219, 221, 223, 226,
723 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
724 static const yytype_int8 yyrhs[] =
726 28, 0, -1, 29, -1, 30, -1, 23, 41, -1,
727 -1, 30, 31, -1, 32, -1, 33, -1, 34, -1,
728 36, -1, 35, -1, 37, -1, 44, -1, 45, -1,
729 20, 15, -1, 20, 24, 20, 47, -1, 20, 24,
730 20, 19, 46, -1, 20, 24, 20, 24, 43, 47,
731 -1, 20, 24, 20, 24, 43, 19, 46, -1, 14,
732 -1, 14, 4, -1, 18, -1, 18, 39, -1, 18,
733 19, 46, -1, 13, -1, 18, 4, -1, 12, -1,
734 12, 25, -1, 17, 12, -1, 20, 12, -1, 20,
735 26, 20, -1, 20, 26, 20, 26, 20, -1, 20,
736 19, 19, -1, 20, 16, 19, -1, 16, 19, 19,
737 -1, 16, 20, -1, 16, 20, 25, 20, -1, 20,
738 16, -1, 20, 16, 20, -1, 38, 3, -1, 38,
739 -1, 40, -1, 17, 5, -1, 20, 5, -1, 5,
740 -1, 17, 6, -1, 20, 6, -1, 6, -1, 17,
741 10, -1, 20, 10, -1, 10, -1, 17, 7, -1,
742 20, 7, -1, 7, -1, 17, 8, -1, 20, 8,
743 -1, 8, -1, 17, 9, -1, 20, 9, -1, 21,
744 9, -1, 22, 9, -1, 9, -1, 39, -1, 19,
745 5, -1, 19, 6, -1, 19, 10, -1, 19, 7,
746 -1, 19, 8, -1, 19, 9, -1, 11, -1, 42,
747 -1, 43, -1, 21, -1, 19, -1, 22, -1, 20,
748 -1, 20, -1, 20, 39, -1, -1, 24, 20, -1,
752 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
753 static const yytype_uint16 yyrline[] =
755 0, 319, 319, 320, 324, 331, 333, 337, 339, 341,
756 343, 345, 347, 348, 349, 353, 358, 363, 370, 375,
757 385, 390, 398, 400, 403, 405, 407, 412, 417, 422,
758 427, 435, 440, 460, 467, 475, 483, 488, 494, 499,
759 508, 510, 512, 517, 519, 521, 523, 525, 527, 529,
760 531, 533, 535, 537, 539, 541, 543, 545, 547, 549,
761 551, 553, 555, 557, 561, 563, 565, 567, 569, 571,
762 576, 580, 580, 583, 584, 589, 590, 595, 600, 611,
767 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
768 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
769 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
770 static const char *const yytname[] =
772 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
773 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
774 "tDAY_SHIFT", "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH",
775 "tORDINAL", "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER",
776 "tUDECIMAL_NUMBER", "'@'", "':'", "','", "'/'", "$accept", "spec",
777 "timespec", "items", "item", "time", "local_zone", "zone", "day", "date",
778 "rel", "relunit", "relunit_snumber", "dayshift", "seconds",
779 "signed_seconds", "unsigned_seconds", "number", "hybrid",
780 "o_colon_minutes", "o_merid", 0
785 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
787 static const yytype_uint16 yytoknum[] =
789 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
790 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
791 275, 276, 277, 64, 58, 44, 47
795 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
796 static const yytype_uint8 yyr1[] =
798 0, 27, 28, 28, 29, 30, 30, 31, 31, 31,
799 31, 31, 31, 31, 31, 32, 32, 32, 32, 32,
800 33, 33, 34, 34, 34, 34, 34, 35, 35, 35,
801 35, 36, 36, 36, 36, 36, 36, 36, 36, 36,
802 37, 37, 37, 38, 38, 38, 38, 38, 38, 38,
803 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
804 38, 38, 38, 38, 39, 39, 39, 39, 39, 39,
805 40, 41, 41, 42, 42, 43, 43, 44, 45, 46,
809 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
810 static const yytype_uint8 yyr2[] =
812 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
813 1, 1, 1, 1, 1, 2, 4, 5, 6, 7,
814 1, 2, 1, 2, 3, 1, 2, 1, 2, 2,
815 2, 3, 5, 3, 3, 3, 2, 4, 2, 3,
816 2, 1, 1, 2, 2, 1, 2, 2, 1, 2,
817 2, 1, 2, 2, 1, 2, 2, 1, 2, 2,
818 2, 2, 1, 1, 2, 2, 2, 2, 2, 2,
819 1, 1, 1, 1, 1, 1, 1, 1, 2, 0,
823 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
824 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
825 means the default is an error. */
826 static const yytype_uint8 yydefact[] =
828 5, 0, 0, 2, 3, 74, 76, 73, 75, 4,
829 71, 72, 1, 45, 48, 54, 57, 62, 51, 70,
830 27, 25, 20, 0, 0, 22, 0, 77, 0, 0,
831 6, 7, 8, 9, 11, 10, 12, 41, 63, 42,
832 13, 14, 28, 21, 0, 36, 43, 46, 52, 55,
833 58, 49, 29, 26, 79, 23, 64, 65, 67, 68,
834 69, 66, 44, 47, 53, 56, 59, 50, 30, 15,
835 38, 0, 0, 0, 78, 60, 61, 40, 35, 0,
836 0, 24, 34, 39, 33, 81, 31, 37, 80, 82,
837 79, 0, 16, 0, 17, 81, 32, 79, 18, 19
840 /* YYDEFGOTO[NTERM-NUM]. */
841 static const yytype_int8 yydefgoto[] =
843 -1, 2, 3, 4, 30, 31, 32, 33, 34, 35,
844 36, 37, 38, 39, 9, 10, 11, 40, 41, 81,
848 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
850 #define YYPACT_NINF -82
851 static const yytype_int8 yypact[] =
853 -17, 56, 15, -82, 26, -82, -82, -82, -82, -82,
854 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82,
855 36, -82, 68, 10, 50, 9, 59, -5, 72, 73,
856 -82, -82, -82, -82, -82, -82, -82, 80, -82, -82,
857 -82, -82, -82, -82, 65, 61, -82, -82, -82, -82,
858 -82, -82, -82, -82, 17, -82, -82, -82, -82, -82,
859 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82,
860 60, 44, 67, 69, -82, -82, -82, -82, -82, 70,
861 71, -82, -82, -82, -82, -7, 62, -82, -82, -82,
862 74, -2, -82, 75, -82, 55, -82, 74, -82, -82
865 /* YYPGOTO[NTERM-NUM]. */
866 static const yytype_int8 yypgoto[] =
868 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82,
869 -82, -82, 46, -82, -82, -82, -6, -82, -82, -81,
873 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
874 positive, shift that token. If negative, reduce the rule which
875 number is the opposite. If zero, do what YYDEFACT says.
876 If YYTABLE_NINF, syntax error. */
877 #define YYTABLE_NINF -1
878 static const yytype_uint8 yytable[] =
880 62, 63, 64, 65, 66, 67, 1, 68, 89, 94,
881 69, 70, 90, 53, 71, 12, 99, 91, 6, 72,
882 8, 73, 56, 57, 58, 59, 60, 61, 54, 44,
883 45, 13, 14, 15, 16, 17, 18, 19, 20, 21,
884 22, 80, 23, 24, 25, 26, 27, 28, 29, 56,
885 57, 58, 59, 60, 61, 46, 47, 48, 49, 50,
886 51, 42, 52, 84, 56, 57, 58, 59, 60, 61,
887 89, 55, 43, 74, 97, 5, 6, 7, 8, 82,
888 83, 75, 76, 77, 78, 95, 79, 85, 93, 86,
889 87, 88, 98, 0, 0, 96, 0, 0, 80
892 static const yytype_int8 yycheck[] =
894 5, 6, 7, 8, 9, 10, 23, 12, 15, 90,
895 15, 16, 19, 4, 19, 0, 97, 24, 20, 24,
896 22, 26, 5, 6, 7, 8, 9, 10, 19, 19,
897 20, 5, 6, 7, 8, 9, 10, 11, 12, 13,
898 14, 24, 16, 17, 18, 19, 20, 21, 22, 5,
899 6, 7, 8, 9, 10, 5, 6, 7, 8, 9,
900 10, 25, 12, 19, 5, 6, 7, 8, 9, 10,
901 15, 25, 4, 27, 19, 19, 20, 21, 22, 19,
902 20, 9, 9, 3, 19, 91, 25, 20, 26, 20,
903 20, 20, 95, -1, -1, 20, -1, -1, 24
906 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
907 symbol of state STATE-NUM. */
908 static const yytype_uint8 yystos[] =
910 0, 23, 28, 29, 30, 19, 20, 21, 22, 41,
911 42, 43, 0, 5, 6, 7, 8, 9, 10, 11,
912 12, 13, 14, 16, 17, 18, 19, 20, 21, 22,
913 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
914 44, 45, 25, 4, 19, 20, 5, 6, 7, 8,
915 9, 10, 12, 4, 19, 39, 5, 6, 7, 8,
916 9, 10, 5, 6, 7, 8, 9, 10, 12, 15,
917 16, 19, 24, 26, 39, 9, 9, 3, 19, 25,
918 24, 46, 19, 20, 19, 20, 20, 20, 20, 15,
919 19, 24, 47, 26, 46, 43, 20, 19, 47, 46
922 #define yyerrok (yyerrstatus = 0)
923 #define yyclearin (yychar = YYEMPTY)
927 #define YYACCEPT goto yyacceptlab
928 #define YYABORT goto yyabortlab
929 #define YYERROR goto yyerrorlab
932 /* Like YYERROR except do call yyerror. This remains here temporarily
933 to ease the transition to the new meaning of YYERROR, for GCC.
934 Once GCC version 2 has supplanted version 1, this can go. */
936 #define YYFAIL goto yyerrlab
938 #define YYRECOVERING() (!!yyerrstatus)
940 #define YYBACKUP(Token, Value) \
942 if (yychar == YYEMPTY && yylen == 1) \
946 yytoken = YYTRANSLATE (yychar); \
952 yyerror (pc, YY_("syntax error: cannot back up")); \
959 #define YYERRCODE 256
962 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
963 If N is 0, then set CURRENT to the empty location which ends
964 the previous symbol: RHS[0] (always defined). */
966 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
967 #ifndef YYLLOC_DEFAULT
968 # define YYLLOC_DEFAULT(Current, Rhs, N) \
972 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
973 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
974 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
975 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
979 (Current).first_line = (Current).last_line = \
980 YYRHSLOC (Rhs, 0).last_line; \
981 (Current).first_column = (Current).last_column = \
982 YYRHSLOC (Rhs, 0).last_column; \
988 /* YY_LOCATION_PRINT -- Print the location on the stream.
989 This macro was not mandated originally: define only if we know
990 we won't break user code: when these are the locations we know. */
992 #ifndef YY_LOCATION_PRINT
993 # if YYLTYPE_IS_TRIVIAL
994 # define YY_LOCATION_PRINT(File, Loc) \
995 fprintf (File, "%d.%d-%d.%d", \
996 (Loc).first_line, (Loc).first_column, \
997 (Loc).last_line, (Loc).last_column)
999 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1004 /* YYLEX -- calling `yylex' with the right arguments. */
1007 # define YYLEX yylex (&yylval, YYLEX_PARAM)
1009 # define YYLEX yylex (&yylval, pc)
1012 /* Enable debugging if requested. */
1016 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1017 # define YYFPRINTF fprintf
1020 # define YYDPRINTF(Args) \
1026 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1030 YYFPRINTF (stderr, "%s ", Title); \
1031 yy_symbol_print (stderr, \
1033 YYFPRINTF (stderr, "\n"); \
1038 /*--------------------------------.
1039 | Print this symbol on YYOUTPUT. |
1040 `--------------------------------*/
1043 #if (defined __STDC__ || defined __C99__FUNC__ \
1044 || defined __cplusplus || defined _MSC_VER)
1046 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1049 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
1052 YYSTYPE const * const yyvaluep;
1060 if (yytype < YYNTOKENS)
1061 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1073 /*--------------------------------.
1074 | Print this symbol on YYOUTPUT. |
1075 `--------------------------------*/
1077 #if (defined __STDC__ || defined __C99__FUNC__ \
1078 || defined __cplusplus || defined _MSC_VER)
1080 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1083 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1086 YYSTYPE const * const yyvaluep;
1090 if (yytype < YYNTOKENS)
1091 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1093 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1095 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1096 YYFPRINTF (yyoutput, ")");
1099 /*------------------------------------------------------------------.
1100 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1102 `------------------------------------------------------------------*/
1104 #if (defined __STDC__ || defined __C99__FUNC__ \
1105 || defined __cplusplus || defined _MSC_VER)
1107 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1110 yy_stack_print (bottom, top)
1111 yytype_int16 *bottom;
1115 YYFPRINTF (stderr, "Stack now");
1116 for (; bottom <= top; ++bottom)
1117 YYFPRINTF (stderr, " %d", *bottom);
1118 YYFPRINTF (stderr, "\n");
1121 # define YY_STACK_PRINT(Bottom, Top) \
1124 yy_stack_print ((Bottom), (Top)); \
1128 /*------------------------------------------------.
1129 | Report that the YYRULE is going to be reduced. |
1130 `------------------------------------------------*/
1132 #if (defined __STDC__ || defined __C99__FUNC__ \
1133 || defined __cplusplus || defined _MSC_VER)
1135 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1138 yy_reduce_print (yyvsp, yyrule, pc)
1144 int yynrhs = yyr2[yyrule];
1146 unsigned long int yylno = yyrline[yyrule];
1147 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1149 /* The symbols being reduced. */
1150 for (yyi = 0; yyi < yynrhs; yyi++)
1152 fprintf (stderr, " $%d = ", yyi + 1);
1153 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1154 &(yyvsp[(yyi + 1) - (yynrhs)])
1156 fprintf (stderr, "\n");
1160 # define YY_REDUCE_PRINT(Rule) \
1163 yy_reduce_print (yyvsp, Rule, pc); \
1166 /* Nonzero means print parse trace. It is left uninitialized so that
1167 multiple parsers can coexist. */
1169 #else /* !YYDEBUG */
1170 # define YYDPRINTF(Args)
1171 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1172 # define YY_STACK_PRINT(Bottom, Top)
1173 # define YY_REDUCE_PRINT(Rule)
1174 #endif /* !YYDEBUG */
1177 /* YYINITDEPTH -- initial size of the parser's stacks. */
1179 # define YYINITDEPTH 200
1182 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1183 if the built-in stack extension method is used).
1185 Do not make this value too large; the results are undefined if
1186 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1187 evaluated with infinite-precision integer arithmetic. */
1190 # define YYMAXDEPTH 10000
1198 # if defined __GLIBC__ && defined _STRING_H
1199 # define yystrlen strlen
1201 /* Return the length of YYSTR. */
1202 #if (defined __STDC__ || defined __C99__FUNC__ \
1203 || defined __cplusplus || defined _MSC_VER)
1205 yystrlen (const char *yystr)
1213 for (yylen = 0; yystr[yylen]; yylen++)
1221 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1222 # define yystpcpy stpcpy
1224 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1226 #if (defined __STDC__ || defined __C99__FUNC__ \
1227 || defined __cplusplus || defined _MSC_VER)
1229 yystpcpy (char *yydest, const char *yysrc)
1232 yystpcpy (yydest, yysrc)
1238 const char *yys = yysrc;
1240 while ((*yyd++ = *yys++) != '\0')
1249 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1250 quotes and backslashes, so that it's suitable for yyerror. The
1251 heuristic is that double-quoting is unnecessary unless the string
1252 contains an apostrophe, a comma, or backslash (other than
1253 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1254 null, do not copy; instead, return the length of what the result
1257 yytnamerr (char *yyres, const char *yystr)
1262 char const *yyp = yystr;
1269 goto do_not_strip_quotes;
1273 goto do_not_strip_quotes;
1286 do_not_strip_quotes: ;
1290 return yystrlen (yystr);
1292 return yystpcpy (yyres, yystr) - yyres;
1296 /* Copy into YYRESULT an error message about the unexpected token
1297 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1298 including the terminating null byte. If YYRESULT is null, do not
1299 copy anything; just return the number of bytes that would be
1300 copied. As a special case, return 0 if an ordinary "syntax error"
1301 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1302 size calculation. */
1304 yysyntax_error (char *yyresult, int yystate, int yychar)
1306 int yyn = yypact[yystate];
1308 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1312 int yytype = YYTRANSLATE (yychar);
1313 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1314 YYSIZE_T yysize = yysize0;
1316 int yysize_overflow = 0;
1317 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1318 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1322 /* This is so xgettext sees the translatable formats that are
1323 constructed on the fly. */
1324 YY_("syntax error, unexpected %s");
1325 YY_("syntax error, unexpected %s, expecting %s");
1326 YY_("syntax error, unexpected %s, expecting %s or %s");
1327 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1328 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1332 static char const yyunexpected[] = "syntax error, unexpected %s";
1333 static char const yyexpecting[] = ", expecting %s";
1334 static char const yyor[] = " or %s";
1335 char yyformat[sizeof yyunexpected
1336 + sizeof yyexpecting - 1
1337 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1338 * (sizeof yyor - 1))];
1339 char const *yyprefix = yyexpecting;
1341 /* Start YYX at -YYN if negative to avoid negative indexes in
1343 int yyxbegin = yyn < 0 ? -yyn : 0;
1345 /* Stay within bounds of both yycheck and yytname. */
1346 int yychecklim = YYLAST - yyn + 1;
1347 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1350 yyarg[0] = yytname[yytype];
1351 yyfmt = yystpcpy (yyformat, yyunexpected);
1353 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1354 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1356 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1360 yyformat[sizeof yyunexpected - 1] = '\0';
1363 yyarg[yycount++] = yytname[yyx];
1364 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1365 yysize_overflow |= (yysize1 < yysize);
1367 yyfmt = yystpcpy (yyfmt, yyprefix);
1371 yyf = YY_(yyformat);
1372 yysize1 = yysize + yystrlen (yyf);
1373 yysize_overflow |= (yysize1 < yysize);
1376 if (yysize_overflow)
1377 return YYSIZE_MAXIMUM;
1381 /* Avoid sprintf, as that infringes on the user's name space.
1382 Don't have undefined behavior even if the translation
1383 produced a string with the wrong number of "%s"s. */
1384 char *yyp = yyresult;
1386 while ((*yyp = *yyf) != '\0')
1388 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1390 yyp += yytnamerr (yyp, yyarg[yyi++]);
1403 #endif /* YYERROR_VERBOSE */
1406 /*-----------------------------------------------.
1407 | Release the memory associated to this symbol. |
1408 `-----------------------------------------------*/
1411 #if (defined __STDC__ || defined __C99__FUNC__ \
1412 || defined __cplusplus || defined _MSC_VER)
1414 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1417 yydestruct (yymsg, yytype, yyvaluep, pc)
1429 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1440 /* Prevent warnings from -Wmissing-prototypes. */
1442 #ifdef YYPARSE_PARAM
1443 #if defined __STDC__ || defined __cplusplus
1444 int yyparse (void *YYPARSE_PARAM);
1448 #else /* ! YYPARSE_PARAM */
1449 #if defined __STDC__ || defined __cplusplus
1450 int yyparse (parser_control *pc);
1454 #endif /* ! YYPARSE_PARAM */
1465 #ifdef YYPARSE_PARAM
1466 #if (defined __STDC__ || defined __C99__FUNC__ \
1467 || defined __cplusplus || defined _MSC_VER)
1469 yyparse (void *YYPARSE_PARAM)
1472 yyparse (YYPARSE_PARAM)
1473 void *YYPARSE_PARAM;
1475 #else /* ! YYPARSE_PARAM */
1476 #if (defined __STDC__ || defined __C99__FUNC__ \
1477 || defined __cplusplus || defined _MSC_VER)
1479 yyparse (parser_control *pc)
1487 /* The look-ahead symbol. */
1490 /* The semantic value of the look-ahead symbol. */
1493 /* Number of syntax errors so far. */
1499 /* Number of tokens to shift before error messages enabled. */
1501 /* Look-ahead token as an internal (translated) token number. */
1504 /* Buffer for error messages, and its allocated size. */
1506 char *yymsg = yymsgbuf;
1507 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1510 /* Three stacks and their tools:
1511 `yyss': related to states,
1512 `yyvs': related to semantic values,
1513 `yyls': related to locations.
1515 Refer to the stacks thru separate pointers, to allow yyoverflow
1516 to reallocate them elsewhere. */
1518 /* The state stack. */
1519 yytype_int16 yyssa[YYINITDEPTH];
1520 yytype_int16 *yyss = yyssa;
1521 yytype_int16 *yyssp;
1523 /* The semantic value stack. */
1524 YYSTYPE yyvsa[YYINITDEPTH];
1525 YYSTYPE *yyvs = yyvsa;
1530 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1532 YYSIZE_T yystacksize = YYINITDEPTH;
1534 /* The variables used to return semantic value and location from the
1539 /* The number of symbols on the RHS of the reduced rule.
1540 Keep to zero when no symbol should be popped. */
1543 YYDPRINTF ((stderr, "Starting parse\n"));
1548 yychar = YYEMPTY; /* Cause a token to be read. */
1550 /* Initialize stack pointers.
1551 Waste one element of value and location stack
1552 so that they stay on the same level as the state stack.
1553 The wasted elements are never initialized. */
1560 /*------------------------------------------------------------.
1561 | yynewstate -- Push a new state, which is found in yystate. |
1562 `------------------------------------------------------------*/
1564 /* In all cases, when you get here, the value and location stacks
1565 have just been pushed. So pushing a state here evens the stacks. */
1571 if (yyss + yystacksize - 1 <= yyssp)
1573 /* Get the current used size of the three stacks, in elements. */
1574 YYSIZE_T yysize = yyssp - yyss + 1;
1578 /* Give user a chance to reallocate the stack. Use copies of
1579 these so that the &'s don't force the real ones into
1581 YYSTYPE *yyvs1 = yyvs;
1582 yytype_int16 *yyss1 = yyss;
1585 /* Each stack pointer address is followed by the size of the
1586 data in use in that stack, in bytes. This used to be a
1587 conditional around just the two extra args, but that might
1588 be undefined if yyoverflow is a macro. */
1589 yyoverflow (YY_("memory exhausted"),
1590 &yyss1, yysize * sizeof (*yyssp),
1591 &yyvs1, yysize * sizeof (*yyvsp),
1598 #else /* no yyoverflow */
1599 # ifndef YYSTACK_RELOCATE
1600 goto yyexhaustedlab;
1602 /* Extend the stack our own way. */
1603 if (YYMAXDEPTH <= yystacksize)
1604 goto yyexhaustedlab;
1606 if (YYMAXDEPTH < yystacksize)
1607 yystacksize = YYMAXDEPTH;
1610 yytype_int16 *yyss1 = yyss;
1611 union yyalloc *yyptr =
1612 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1614 goto yyexhaustedlab;
1615 YYSTACK_RELOCATE (yyss);
1616 YYSTACK_RELOCATE (yyvs);
1618 # undef YYSTACK_RELOCATE
1620 YYSTACK_FREE (yyss1);
1623 #endif /* no yyoverflow */
1625 yyssp = yyss + yysize - 1;
1626 yyvsp = yyvs + yysize - 1;
1629 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1630 (unsigned long int) yystacksize));
1632 if (yyss + yystacksize - 1 <= yyssp)
1636 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1645 /* Do appropriate processing given the current state. Read a
1646 look-ahead token if we need one and don't already have one. */
1648 /* First try to decide what to do without reference to look-ahead token. */
1649 yyn = yypact[yystate];
1650 if (yyn == YYPACT_NINF)
1653 /* Not known => get a look-ahead token if don't already have one. */
1655 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1656 if (yychar == YYEMPTY)
1658 YYDPRINTF ((stderr, "Reading a token: "));
1662 if (yychar <= YYEOF)
1664 yychar = yytoken = YYEOF;
1665 YYDPRINTF ((stderr, "Now at end of input.\n"));
1669 yytoken = YYTRANSLATE (yychar);
1670 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1673 /* If the proper action on seeing token YYTOKEN is to reduce or to
1674 detect an error, take that action. */
1676 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1681 if (yyn == 0 || yyn == YYTABLE_NINF)
1690 /* Count tokens shifted since error; after three, turn off error
1695 /* Shift the look-ahead token. */
1696 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1698 /* Discard the shifted token unless it is eof. */
1699 if (yychar != YYEOF)
1708 /*-----------------------------------------------------------.
1709 | yydefault -- do the default action for the current state. |
1710 `-----------------------------------------------------------*/
1712 yyn = yydefact[yystate];
1718 /*-----------------------------.
1719 | yyreduce -- Do a reduction. |
1720 `-----------------------------*/
1722 /* yyn is the number of a rule to reduce with. */
1725 /* If YYLEN is nonzero, implement the default value of the action:
1728 Otherwise, the following line sets YYVAL to garbage.
1729 This behavior is undocumented and Bison
1730 users should not rely upon it. Assigning to YYVAL
1731 unconditionally makes the parser a bit smaller, and it avoids a
1732 GCC warning that YYVAL may be used uninitialized. */
1733 yyval = yyvsp[1-yylen];
1736 YY_REDUCE_PRINT (yyn);
1740 #line 325 "parse-datetime.y"
1742 pc->seconds = (yyvsp[(2) - (2)].timespec);
1743 pc->timespec_seen = true;
1748 #line 338 "parse-datetime.y"
1749 { pc->times_seen++; }
1753 #line 340 "parse-datetime.y"
1754 { pc->local_zones_seen++; }
1758 #line 342 "parse-datetime.y"
1759 { pc->zones_seen++; }
1763 #line 344 "parse-datetime.y"
1764 { pc->dates_seen++; }
1768 #line 346 "parse-datetime.y"
1769 { pc->days_seen++; }
1773 #line 354 "parse-datetime.y"
1775 set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1776 pc->meridian = (yyvsp[(2) - (2)].intval);
1781 #line 359 "parse-datetime.y"
1783 set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1784 pc->meridian = (yyvsp[(4) - (4)].intval);
1789 #line 364 "parse-datetime.y"
1791 set_hhmmss (pc, (yyvsp[(1) - (5)].textintval).value, (yyvsp[(3) - (5)].textintval).value, 0, 0);
1792 pc->meridian = MER24;
1794 pc->time_zone = time_zone_hhmm (pc, (yyvsp[(4) - (5)].textintval), (yyvsp[(5) - (5)].intval));
1799 #line 371 "parse-datetime.y"
1801 set_hhmmss (pc, (yyvsp[(1) - (6)].textintval).value, (yyvsp[(3) - (6)].textintval).value, (yyvsp[(5) - (6)].timespec).tv_sec, (yyvsp[(5) - (6)].timespec).tv_nsec);
1802 pc->meridian = (yyvsp[(6) - (6)].intval);
1807 #line 376 "parse-datetime.y"
1809 set_hhmmss (pc, (yyvsp[(1) - (7)].textintval).value, (yyvsp[(3) - (7)].textintval).value, (yyvsp[(5) - (7)].timespec).tv_sec, (yyvsp[(5) - (7)].timespec).tv_nsec);
1810 pc->meridian = MER24;
1812 pc->time_zone = time_zone_hhmm (pc, (yyvsp[(6) - (7)].textintval), (yyvsp[(7) - (7)].intval));
1817 #line 386 "parse-datetime.y"
1819 pc->local_isdst = (yyvsp[(1) - (1)].intval);
1820 pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1825 #line 391 "parse-datetime.y"
1827 pc->local_isdst = 1;
1828 pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1833 #line 399 "parse-datetime.y"
1834 { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1838 #line 401 "parse-datetime.y"
1839 { pc->time_zone = (yyvsp[(1) - (2)].intval);
1840 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1844 #line 404 "parse-datetime.y"
1845 { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1849 #line 406 "parse-datetime.y"
1850 { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
1854 #line 408 "parse-datetime.y"
1855 { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
1859 #line 413 "parse-datetime.y"
1861 pc->day_ordinal = 0;
1862 pc->day_number = (yyvsp[(1) - (1)].intval);
1867 #line 418 "parse-datetime.y"
1869 pc->day_ordinal = 0;
1870 pc->day_number = (yyvsp[(1) - (2)].intval);
1875 #line 423 "parse-datetime.y"
1877 pc->day_ordinal = (yyvsp[(1) - (2)].intval);
1878 pc->day_number = (yyvsp[(2) - (2)].intval);
1883 #line 428 "parse-datetime.y"
1885 pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
1886 pc->day_number = (yyvsp[(2) - (2)].intval);
1891 #line 436 "parse-datetime.y"
1893 pc->month = (yyvsp[(1) - (3)].textintval).value;
1894 pc->day = (yyvsp[(3) - (3)].textintval).value;
1899 #line 441 "parse-datetime.y"
1901 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1902 otherwise as MM/DD/YY.
1903 The goal in recognizing YYYY/MM/DD is solely to support legacy
1904 machine-generated dates like those in an RCS log listing. If
1905 you want portability, use the ISO 8601 format. */
1906 if (4 <= (yyvsp[(1) - (5)].textintval).digits)
1908 pc->year = (yyvsp[(1) - (5)].textintval);
1909 pc->month = (yyvsp[(3) - (5)].textintval).value;
1910 pc->day = (yyvsp[(5) - (5)].textintval).value;
1914 pc->month = (yyvsp[(1) - (5)].textintval).value;
1915 pc->day = (yyvsp[(3) - (5)].textintval).value;
1916 pc->year = (yyvsp[(5) - (5)].textintval);
1922 #line 461 "parse-datetime.y"
1924 /* ISO 8601 format. YYYY-MM-DD. */
1925 pc->year = (yyvsp[(1) - (3)].textintval);
1926 pc->month = -(yyvsp[(2) - (3)].textintval).value;
1927 pc->day = -(yyvsp[(3) - (3)].textintval).value;
1932 #line 468 "parse-datetime.y"
1934 /* e.g. 17-JUN-1992. */
1935 pc->day = (yyvsp[(1) - (3)].textintval).value;
1936 pc->month = (yyvsp[(2) - (3)].intval);
1937 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1938 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1943 #line 476 "parse-datetime.y"
1945 /* e.g. JUN-17-1992. */
1946 pc->month = (yyvsp[(1) - (3)].intval);
1947 pc->day = -(yyvsp[(2) - (3)].textintval).value;
1948 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1949 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1954 #line 484 "parse-datetime.y"
1956 pc->month = (yyvsp[(1) - (2)].intval);
1957 pc->day = (yyvsp[(2) - (2)].textintval).value;
1962 #line 489 "parse-datetime.y"
1964 pc->month = (yyvsp[(1) - (4)].intval);
1965 pc->day = (yyvsp[(2) - (4)].textintval).value;
1966 pc->year = (yyvsp[(4) - (4)].textintval);
1971 #line 495 "parse-datetime.y"
1973 pc->day = (yyvsp[(1) - (2)].textintval).value;
1974 pc->month = (yyvsp[(2) - (2)].intval);
1979 #line 500 "parse-datetime.y"
1981 pc->day = (yyvsp[(1) - (3)].textintval).value;
1982 pc->month = (yyvsp[(2) - (3)].intval);
1983 pc->year = (yyvsp[(3) - (3)].textintval);
1988 #line 509 "parse-datetime.y"
1989 { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), -1); }
1993 #line 511 "parse-datetime.y"
1994 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
1998 #line 513 "parse-datetime.y"
1999 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2003 #line 518 "parse-datetime.y"
2004 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
2008 #line 520 "parse-datetime.y"
2009 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2013 #line 522 "parse-datetime.y"
2014 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2018 #line 524 "parse-datetime.y"
2019 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2023 #line 526 "parse-datetime.y"
2024 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2028 #line 528 "parse-datetime.y"
2029 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2033 #line 530 "parse-datetime.y"
2034 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2038 #line 532 "parse-datetime.y"
2039 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2043 #line 534 "parse-datetime.y"
2044 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2048 #line 536 "parse-datetime.y"
2049 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2053 #line 538 "parse-datetime.y"
2054 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2058 #line 540 "parse-datetime.y"
2059 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2063 #line 542 "parse-datetime.y"
2064 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2068 #line 544 "parse-datetime.y"
2069 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2073 #line 546 "parse-datetime.y"
2074 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2078 #line 548 "parse-datetime.y"
2079 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2083 #line 550 "parse-datetime.y"
2084 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2088 #line 552 "parse-datetime.y"
2089 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2093 #line 554 "parse-datetime.y"
2094 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2098 #line 556 "parse-datetime.y"
2099 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2103 #line 562 "parse-datetime.y"
2104 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2108 #line 564 "parse-datetime.y"
2109 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2113 #line 566 "parse-datetime.y"
2114 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2118 #line 568 "parse-datetime.y"
2119 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2123 #line 570 "parse-datetime.y"
2124 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2128 #line 572 "parse-datetime.y"
2129 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2133 #line 577 "parse-datetime.y"
2134 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2138 #line 585 "parse-datetime.y"
2139 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2143 #line 591 "parse-datetime.y"
2144 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2148 #line 596 "parse-datetime.y"
2149 { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
2153 #line 601 "parse-datetime.y"
2155 /* Hybrid all-digit and relative offset, so that we accept e.g.,
2156 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */
2157 digits_to_date_time (pc, (yyvsp[(1) - (2)].textintval));
2158 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1);
2163 #line 611 "parse-datetime.y"
2164 { (yyval.intval) = -1; }
2168 #line 613 "parse-datetime.y"
2169 { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2173 #line 618 "parse-datetime.y"
2174 { (yyval.intval) = MER24; }
2178 #line 620 "parse-datetime.y"
2179 { (yyval.intval) = (yyvsp[(1) - (1)].intval); }
2183 /* Line 1267 of yacc.c. */
2184 #line 2185 "parse-datetime.c"
2187 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2191 YY_STACK_PRINT (yyss, yyssp);
2196 /* Now `shift' the result of the reduction. Determine what state
2197 that goes to, based on the state we popped back to and the rule
2198 number reduced by. */
2202 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2203 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2204 yystate = yytable[yystate];
2206 yystate = yydefgoto[yyn - YYNTOKENS];
2211 /*------------------------------------.
2212 | yyerrlab -- here on detecting error |
2213 `------------------------------------*/
2215 /* If not already recovering from an error, report this error. */
2219 #if ! YYERROR_VERBOSE
2220 yyerror (pc, YY_("syntax error"));
2223 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2224 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2226 YYSIZE_T yyalloc = 2 * yysize;
2227 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2228 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2229 if (yymsg != yymsgbuf)
2230 YYSTACK_FREE (yymsg);
2231 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2233 yymsg_alloc = yyalloc;
2237 yymsg_alloc = sizeof yymsgbuf;
2241 if (0 < yysize && yysize <= yymsg_alloc)
2243 (void) yysyntax_error (yymsg, yystate, yychar);
2244 yyerror (pc, yymsg);
2248 yyerror (pc, YY_("syntax error"));
2250 goto yyexhaustedlab;
2258 if (yyerrstatus == 3)
2260 /* If just tried and failed to reuse look-ahead token after an
2261 error, discard it. */
2263 if (yychar <= YYEOF)
2265 /* Return failure if at end of input. */
2266 if (yychar == YYEOF)
2271 yydestruct ("Error: discarding",
2272 yytoken, &yylval, pc);
2277 /* Else will try to reuse look-ahead token after shifting the error
2282 /*---------------------------------------------------.
2283 | yyerrorlab -- error raised explicitly by YYERROR. |
2284 `---------------------------------------------------*/
2287 /* Pacify compilers like GCC when the user code never invokes
2288 YYERROR and the label yyerrorlab therefore never appears in user
2290 if (/*CONSTCOND*/ 0)
2293 /* Do not reclaim the symbols of the rule which action triggered
2297 YY_STACK_PRINT (yyss, yyssp);
2302 /*-------------------------------------------------------------.
2303 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2304 `-------------------------------------------------------------*/
2306 yyerrstatus = 3; /* Each real token shifted decrements this. */
2310 yyn = yypact[yystate];
2311 if (yyn != YYPACT_NINF)
2314 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2322 /* Pop the current state because it cannot handle the error token. */
2327 yydestruct ("Error: popping",
2328 yystos[yystate], yyvsp, pc);
2331 YY_STACK_PRINT (yyss, yyssp);
2340 /* Shift the error token. */
2341 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2347 /*-------------------------------------.
2348 | yyacceptlab -- YYACCEPT comes here. |
2349 `-------------------------------------*/
2354 /*-----------------------------------.
2355 | yyabortlab -- YYABORT comes here. |
2356 `-----------------------------------*/
2362 /*-------------------------------------------------.
2363 | yyexhaustedlab -- memory exhaustion comes here. |
2364 `-------------------------------------------------*/
2366 yyerror (pc, YY_("memory exhausted"));
2372 if (yychar != YYEOF && yychar != YYEMPTY)
2373 yydestruct ("Cleanup: discarding lookahead",
2374 yytoken, &yylval, pc);
2375 /* Do not reclaim the symbols of the rule which action triggered
2376 this YYABORT or YYACCEPT. */
2378 YY_STACK_PRINT (yyss, yyssp);
2379 while (yyssp != yyss)
2381 yydestruct ("Cleanup: popping",
2382 yystos[*yyssp], yyvsp, pc);
2387 YYSTACK_FREE (yyss);
2390 if (yymsg != yymsgbuf)
2391 YYSTACK_FREE (yymsg);
2393 /* Make sure YYID is used. */
2394 return YYID (yyresult);
2398 #line 623 "parse-datetime.y"
2401 static table const meridian_table[] =
2403 { "AM", tMERIDIAN, MERam },
2404 { "A.M.", tMERIDIAN, MERam },
2405 { "PM", tMERIDIAN, MERpm },
2406 { "P.M.", tMERIDIAN, MERpm },
2410 static table const dst_table[] =
2415 static table const month_and_day_table[] =
2417 { "JANUARY", tMONTH, 1 },
2418 { "FEBRUARY", tMONTH, 2 },
2419 { "MARCH", tMONTH, 3 },
2420 { "APRIL", tMONTH, 4 },
2421 { "MAY", tMONTH, 5 },
2422 { "JUNE", tMONTH, 6 },
2423 { "JULY", tMONTH, 7 },
2424 { "AUGUST", tMONTH, 8 },
2425 { "SEPTEMBER",tMONTH, 9 },
2426 { "SEPT", tMONTH, 9 },
2427 { "OCTOBER", tMONTH, 10 },
2428 { "NOVEMBER", tMONTH, 11 },
2429 { "DECEMBER", tMONTH, 12 },
2430 { "SUNDAY", tDAY, 0 },
2431 { "MONDAY", tDAY, 1 },
2432 { "TUESDAY", tDAY, 2 },
2433 { "TUES", tDAY, 2 },
2434 { "WEDNESDAY",tDAY, 3 },
2435 { "WEDNES", tDAY, 3 },
2436 { "THURSDAY", tDAY, 4 },
2437 { "THUR", tDAY, 4 },
2438 { "THURS", tDAY, 4 },
2439 { "FRIDAY", tDAY, 5 },
2440 { "SATURDAY", tDAY, 6 },
2444 static table const time_units_table[] =
2446 { "YEAR", tYEAR_UNIT, 1 },
2447 { "MONTH", tMONTH_UNIT, 1 },
2448 { "FORTNIGHT",tDAY_UNIT, 14 },
2449 { "WEEK", tDAY_UNIT, 7 },
2450 { "DAY", tDAY_UNIT, 1 },
2451 { "HOUR", tHOUR_UNIT, 1 },
2452 { "MINUTE", tMINUTE_UNIT, 1 },
2453 { "MIN", tMINUTE_UNIT, 1 },
2454 { "SECOND", tSEC_UNIT, 1 },
2455 { "SEC", tSEC_UNIT, 1 },
2459 /* Assorted relative-time words. */
2460 static table const relative_time_table[] =
2462 { "TOMORROW", tDAY_SHIFT, 1 },
2463 { "YESTERDAY",tDAY_SHIFT, -1 },
2464 { "TODAY", tDAY_SHIFT, 0 },
2465 { "NOW", tDAY_SHIFT, 0 },
2466 { "LAST", tORDINAL, -1 },
2467 { "THIS", tORDINAL, 0 },
2468 { "NEXT", tORDINAL, 1 },
2469 { "FIRST", tORDINAL, 1 },
2470 /*{ "SECOND", tORDINAL, 2 }, */
2471 { "THIRD", tORDINAL, 3 },
2472 { "FOURTH", tORDINAL, 4 },
2473 { "FIFTH", tORDINAL, 5 },
2474 { "SIXTH", tORDINAL, 6 },
2475 { "SEVENTH", tORDINAL, 7 },
2476 { "EIGHTH", tORDINAL, 8 },
2477 { "NINTH", tORDINAL, 9 },
2478 { "TENTH", tORDINAL, 10 },
2479 { "ELEVENTH", tORDINAL, 11 },
2480 { "TWELFTH", tORDINAL, 12 },
2485 /* The universal time zone table. These labels can be used even for
2486 time stamps that would not otherwise be valid, e.g., GMT time
2487 stamps in London during summer. */
2488 static table const universal_time_zone_table[] =
2490 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2491 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2492 { "UTC", tZONE, HOUR ( 0) },
2496 /* The time zone table. This table is necessarily incomplete, as time
2497 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2498 as Eastern time in Australia, not as US Eastern Standard Time.
2499 You cannot rely on parse_datetime to handle arbitrary time zone
2500 abbreviations; use numeric abbreviations like `-0500' instead. */
2501 static table const time_zone_table[] =
2503 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2504 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2505 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2506 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2507 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2508 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2509 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2510 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2511 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2512 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2513 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2514 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2515 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2516 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2517 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2518 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2519 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2520 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2521 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2522 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2523 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2524 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2525 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2526 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2527 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2528 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2529 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2530 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2531 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2532 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2533 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2534 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2535 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2536 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2537 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2538 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2539 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2540 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2541 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2542 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2543 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2544 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2545 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2546 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2547 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2548 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2549 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2553 /* Military time zone table. */
2554 static table const military_table[] =
2556 { "A", tZONE, -HOUR ( 1) },
2557 { "B", tZONE, -HOUR ( 2) },
2558 { "C", tZONE, -HOUR ( 3) },
2559 { "D", tZONE, -HOUR ( 4) },
2560 { "E", tZONE, -HOUR ( 5) },
2561 { "F", tZONE, -HOUR ( 6) },
2562 { "G", tZONE, -HOUR ( 7) },
2563 { "H", tZONE, -HOUR ( 8) },
2564 { "I", tZONE, -HOUR ( 9) },
2565 { "K", tZONE, -HOUR (10) },
2566 { "L", tZONE, -HOUR (11) },
2567 { "M", tZONE, -HOUR (12) },
2568 { "N", tZONE, HOUR ( 1) },
2569 { "O", tZONE, HOUR ( 2) },
2570 { "P", tZONE, HOUR ( 3) },
2571 { "Q", tZONE, HOUR ( 4) },
2572 { "R", tZONE, HOUR ( 5) },
2573 { "S", tZONE, HOUR ( 6) },
2574 { "T", tZONE, HOUR ( 7) },
2575 { "U", tZONE, HOUR ( 8) },
2576 { "V", tZONE, HOUR ( 9) },
2577 { "W", tZONE, HOUR (10) },
2578 { "X", tZONE, HOUR (11) },
2579 { "Y", tZONE, HOUR (12) },
2580 { "Z", tZONE, HOUR ( 0) },
2586 /* Convert a time zone expressed as HH:MM into an integer count of
2587 minutes. If MM is negative, then S is of the form HHMM and needs
2588 to be picked apart; otherwise, S is of the form HH. As specified in
2589 http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow
2590 only valid TZ range, and consider first two digits as hours, if no
2591 minutes specified. */
2594 time_zone_hhmm (parser_control *pc, textint s, long int mm)
2598 /* If the length of S is 1 or 2 and no minutes are specified,
2599 interpret it as a number of hours. */
2600 if (s.digits <= 2 && mm < 0)
2604 n_minutes = (s.value / 100) * 60 + s.value % 100;
2606 n_minutes = s.value * 60 + (s.negative ? -mm : mm);
2608 /* If the absolute number of minutes is larger than 24 hours,
2609 arrange to reject it by incrementing pc->zones_seen. Thus,
2610 we allow only values in the range UTC-24:00 to UTC+24:00. */
2611 if (24 * 60 < abs (n_minutes))
2618 to_hour (long int hours, int meridian)
2622 default: /* Pacify GCC. */
2624 return 0 <= hours && hours < 24 ? hours : -1;
2626 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2628 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2633 to_year (textint textyear)
2635 long int year = textyear.value;
2640 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2641 years 69-99 map to 1969-1999. */
2642 else if (textyear.digits == 2)
2643 year += year < 69 ? 2000 : 1900;
2648 static table const *
2649 lookup_zone (parser_control const *pc, char const *name)
2653 for (tp = universal_time_zone_table; tp->name; tp++)
2654 if (strcmp (name, tp->name) == 0)
2657 /* Try local zone abbreviations before those in time_zone_table, as
2658 the local ones are more likely to be right. */
2659 for (tp = pc->local_time_zone_table; tp->name; tp++)
2660 if (strcmp (name, tp->name) == 0)
2663 for (tp = time_zone_table; tp->name; tp++)
2664 if (strcmp (name, tp->name) == 0)
2670 #if ! HAVE_TM_GMTOFF
2671 /* Yield the difference between *A and *B,
2672 measured in seconds, ignoring leap seconds.
2673 The body of this function is taken directly from the GNU C Library;
2674 see src/strftime.c. */
2676 tm_diff (struct tm const *a, struct tm const *b)
2678 /* Compute intervening leap days correctly even if year is negative.
2679 Take care to avoid int overflow in leap day calculations. */
2680 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2681 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2682 int a100 = a4 / 25 - (a4 % 25 < 0);
2683 int b100 = b4 / 25 - (b4 % 25 < 0);
2684 int a400 = SHR (a100, 2);
2685 int b400 = SHR (b100, 2);
2686 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2687 long int ayear = a->tm_year;
2688 long int years = ayear - b->tm_year;
2689 long int days = (365 * years + intervening_leap_days
2690 + (a->tm_yday - b->tm_yday));
2691 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2692 + (a->tm_min - b->tm_min))
2693 + (a->tm_sec - b->tm_sec));
2695 #endif /* ! HAVE_TM_GMTOFF */
2697 static table const *
2698 lookup_word (parser_control const *pc, char *word)
2707 /* Make it uppercase. */
2708 for (p = word; *p; p++)
2710 unsigned char ch = *p;
2711 *p = c_toupper (ch);
2714 for (tp = meridian_table; tp->name; tp++)
2715 if (strcmp (word, tp->name) == 0)
2718 /* See if we have an abbreviation for a month. */
2719 wordlen = strlen (word);
2720 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2722 for (tp = month_and_day_table; tp->name; tp++)
2723 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2726 if ((tp = lookup_zone (pc, word)))
2729 if (strcmp (word, dst_table[0].name) == 0)
2732 for (tp = time_units_table; tp->name; tp++)
2733 if (strcmp (word, tp->name) == 0)
2736 /* Strip off any plural and try the units table again. */
2737 if (word[wordlen - 1] == 'S')
2739 word[wordlen - 1] = '\0';
2740 for (tp = time_units_table; tp->name; tp++)
2741 if (strcmp (word, tp->name) == 0)
2743 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
2746 for (tp = relative_time_table; tp->name; tp++)
2747 if (strcmp (word, tp->name) == 0)
2750 /* Military time zones. */
2752 for (tp = military_table; tp->name; tp++)
2753 if (word[0] == tp->name[0])
2756 /* Drop out any periods and try the time zone table again. */
2757 for (period_found = false, p = q = word; (*p = *q); q++)
2759 period_found = true;
2762 if (period_found && (tp = lookup_zone (pc, word)))
2769 yylex (YYSTYPE *lvalp, parser_control *pc)
2776 while (c = *pc->input, c_isspace (c))
2779 if (ISDIGIT (c) || c == '-' || c == '+')
2783 unsigned long int value;
2784 if (c == '-' || c == '+')
2786 sign = c == '-' ? -1 : 1;
2787 while (c = *++pc->input, c_isspace (c))
2790 /* skip the '-' sign */
2796 for (value = 0; ; value *= 10)
2798 unsigned long int value1 = value + (c - '0');
2805 if (ULONG_MAX / 10 < value)
2808 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
2813 unsigned long int value1;
2815 /* Check for overflow when converting value to time_t. */
2830 if (value != value1)
2833 /* Accumulate fraction, to ns precision. */
2836 for (digits = 2; digits <= LOG10_BILLION; digits++)
2843 /* Skip excess digits, truncating toward -Infinity. */
2845 for (; ISDIGIT (*p); p++)
2851 while (ISDIGIT (*p))
2854 /* Adjust to the timespec convention, which is that
2855 tv_nsec is always a positive offset even if tv_sec is
2865 lvalp->timespec.tv_sec = s;
2866 lvalp->timespec.tv_nsec = ns;
2868 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
2872 lvalp->textintval.negative = sign < 0;
2875 lvalp->textintval.value = - value;
2876 if (0 < lvalp->textintval.value)
2881 lvalp->textintval.value = value;
2882 if (lvalp->textintval.value < 0)
2885 lvalp->textintval.digits = p - pc->input;
2887 return sign ? tSNUMBER : tUNUMBER;
2899 if (p < buff + sizeof buff - 1)
2903 while (c_isalpha (c) || c == '.');
2906 tp = lookup_word (pc, buff);
2909 lvalp->intval = tp->value;
2914 return *pc->input++;
2930 /* Do nothing if the parser reports an error. */
2932 yyerror (parser_control const *pc _GL_UNUSED,
2933 char const *s _GL_UNUSED)
2938 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
2939 passing it to mktime, return true if it's OK that mktime returned T.
2940 It's not OK if *TM0 has out-of-range members. */
2943 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
2945 if (t == (time_t) -1)
2947 /* Guard against falsely reporting an error when parsing a time
2948 stamp that happens to equal (time_t) -1, on a host that
2949 supports such a time stamp. */
2950 tm1 = localtime (&t);
2955 return ! ((tm0->tm_sec ^ tm1->tm_sec)
2956 | (tm0->tm_min ^ tm1->tm_min)
2957 | (tm0->tm_hour ^ tm1->tm_hour)
2958 | (tm0->tm_mday ^ tm1->tm_mday)
2959 | (tm0->tm_mon ^ tm1->tm_mon)
2960 | (tm0->tm_year ^ tm1->tm_year));
2963 /* A reasonable upper bound for the size of ordinary TZ strings.
2964 Use heap allocation if TZ's length exceeds this. */
2965 enum { TZBUFSIZE = 100 };
2967 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
2970 get_tz (char tzbuf[TZBUFSIZE])
2972 char *tz = getenv ("TZ");
2975 size_t tzsize = strlen (tz) + 1;
2976 tz = (tzsize <= TZBUFSIZE
2977 ? memcpy (tzbuf, tz, tzsize)
2978 : xmemdup (tz, tzsize));
2983 /* Parse a date/time string, storing the resulting time value into *RESULT.
2984 The string itself is pointed to by P. Return true if successful.
2985 P can be an incomplete or relative time specification; if so, use
2986 *NOW as the basis for the returned time. */
2988 parse_datetime (struct timespec *result, char const *p,
2989 struct timespec const *now)
2993 struct tm const *tmp;
2997 struct timespec gettime_buffer;
2999 bool tz_was_altered = false;
3001 char tz0buf[TZBUFSIZE];
3006 gettime (&gettime_buffer);
3007 now = &gettime_buffer;
3010 Start = now->tv_sec;
3011 Start_ns = now->tv_nsec;
3013 tmp = localtime (&now->tv_sec);
3017 while (c = *p, c_isspace (c))
3020 if (strncmp (p, "TZ=\"", 4) == 0)
3022 char const *tzbase = p + 4;
3026 for (s = tzbase; *s; s++, tzsize++)
3030 if (! (*s == '\\' || *s == '"'))
3037 char tz1buf[TZBUFSIZE];
3038 bool large_tz = TZBUFSIZE < tzsize;
3040 /* Free tz0, in case this is the 2nd or subsequent time through. */
3042 tz0 = get_tz (tz0buf);
3043 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3044 for (s = tzbase; *s != '"'; s++)
3045 *z++ = *(s += *s == '\\');
3047 setenv_ok = setenv ("TZ", tz1, 1) == 0;
3052 tz_was_altered = true;
3057 /* As documented, be careful to treat the empty string just like
3058 a date string of "0". Without this, an empty string would be
3059 declared invalid when parsed during a DST transition. */
3064 pc.year.value = tmp->tm_year;
3065 pc.year.value += TM_YEAR_BASE;
3067 pc.month = tmp->tm_mon + 1;
3068 pc.day = tmp->tm_mday;
3069 pc.hour = tmp->tm_hour;
3070 pc.minutes = tmp->tm_min;
3071 pc.seconds.tv_sec = tmp->tm_sec;
3072 pc.seconds.tv_nsec = Start_ns;
3073 tm.tm_isdst = tmp->tm_isdst;
3075 pc.meridian = MER24;
3076 pc.rel = RELATIVE_TIME_0;
3077 pc.timespec_seen = false;
3078 pc.rels_seen = false;
3082 pc.local_zones_seen = 0;
3086 #if HAVE_STRUCT_TM_TM_ZONE
3087 pc.local_time_zone_table[0].name = tmp->tm_zone;
3088 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3089 pc.local_time_zone_table[0].value = tmp->tm_isdst;
3090 pc.local_time_zone_table[1].name = NULL;
3092 /* Probe the names used in the next three calendar quarters, looking
3093 for a tm_isdst different from the one we already have. */
3096 for (quarter = 1; quarter <= 3; quarter++)
3098 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3099 struct tm const *probe_tm = localtime (&probe);
3100 if (probe_tm && probe_tm->tm_zone
3101 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3104 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3105 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3106 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3107 pc.local_time_zone_table[2].name = NULL;
3116 # if !HAVE_DECL_TZNAME
3117 extern char *tzname[];
3120 for (i = 0; i < 2; i++)
3122 pc.local_time_zone_table[i].name = tzname[i];
3123 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3124 pc.local_time_zone_table[i].value = i;
3126 pc.local_time_zone_table[i].name = NULL;
3129 pc.local_time_zone_table[0].name = NULL;
3133 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3134 && ! strcmp (pc.local_time_zone_table[0].name,
3135 pc.local_time_zone_table[1].name))
3137 /* This locale uses the same abbrevation for standard and
3138 daylight times. So if we see that abbreviation, we don't
3139 know whether it's daylight time. */
3140 pc.local_time_zone_table[0].value = -1;
3141 pc.local_time_zone_table[1].name = NULL;
3144 if (yyparse (&pc) != 0)
3147 if (pc.timespec_seen)
3148 *result = pc.seconds;
3151 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3152 | (pc.local_zones_seen + pc.zones_seen)))
3155 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3156 tm.tm_mon = pc.month - 1;
3157 tm.tm_mday = pc.day;
3158 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3160 tm.tm_hour = to_hour (pc.hour, pc.meridian);
3163 tm.tm_min = pc.minutes;
3164 tm.tm_sec = pc.seconds.tv_sec;
3168 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3169 pc.seconds.tv_nsec = 0;
3172 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
3173 if (pc.dates_seen | pc.days_seen | pc.times_seen)
3176 /* But if the input explicitly specifies local time with or without
3177 DST, give mktime that information. */
3178 if (pc.local_zones_seen)
3179 tm.tm_isdst = pc.local_isdst;
3183 Start = mktime (&tm);
3185 if (! mktime_ok (&tm0, &tm, Start))
3187 if (! pc.zones_seen)
3191 /* Guard against falsely reporting errors near the time_t
3192 boundaries when parsing times in other time zones. For
3193 example, suppose the input string "1969-12-31 23:00:00 -0100",
3194 the current time zone is 8 hours ahead of UTC, and the min
3195 time_t value is 1970-01-01 00:00:00 UTC. Then the min
3196 localtime value is 1970-01-01 08:00:00, and mktime will
3197 therefore fail on 1969-12-31 23:00:00. To work around the
3198 problem, set the time zone to 1 hour behind UTC temporarily
3199 by setting TZ="XXX1:00" and try mktime again. */
3201 long int time_zone = pc.time_zone;
3202 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3203 long int abs_time_zone_hour = abs_time_zone / 60;
3204 int abs_time_zone_min = abs_time_zone % 60;
3205 char tz1buf[sizeof "XXX+0:00"
3206 + sizeof pc.time_zone * CHAR_BIT / 3];
3207 if (!tz_was_altered)
3208 tz0 = get_tz (tz0buf);
3209 sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0),
3210 abs_time_zone_hour, abs_time_zone_min);
3211 if (setenv ("TZ", tz1buf, 1) != 0)
3213 tz_was_altered = true;
3215 Start = mktime (&tm);
3216 if (! mktime_ok (&tm0, &tm, Start))
3221 if (pc.days_seen && ! pc.dates_seen)
3223 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3224 + 7 * (pc.day_ordinal
3225 - (0 < pc.day_ordinal
3226 && tm.tm_wday != pc.day_number)));
3228 Start = mktime (&tm);
3229 if (Start == (time_t) -1)
3233 /* Add relative date. */
3234 if (pc.rel.year | pc.rel.month | pc.rel.day)
3236 int year = tm.tm_year + pc.rel.year;
3237 int month = tm.tm_mon + pc.rel.month;
3238 int day = tm.tm_mday + pc.rel.day;
3239 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3240 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3241 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3246 tm.tm_hour = tm0.tm_hour;
3247 tm.tm_min = tm0.tm_min;
3248 tm.tm_sec = tm0.tm_sec;
3249 tm.tm_isdst = tm0.tm_isdst;
3250 Start = mktime (&tm);
3251 if (Start == (time_t) -1)
3255 /* The only "output" of this if-block is an updated Start value,
3256 so this block must follow others that clobber Start. */
3259 long int delta = pc.time_zone * 60;
3261 #ifdef HAVE_TM_GMTOFF
3262 delta -= tm.tm_gmtoff;
3265 struct tm const *gmt = gmtime (&t);
3268 delta -= tm_diff (&tm, gmt);
3271 if ((Start < t1) != (delta < 0))
3272 goto fail; /* time_t overflow */
3276 /* Add relative hours, minutes, and seconds. On hosts that support
3277 leap seconds, ignore the possibility of leap seconds; e.g.,
3278 "+ 10 minutes" adds 600 seconds, even if one of them is a
3279 leap second. Typically this is not what the user wants, but it's
3280 too hard to do it the other way, because the time zone indicator
3281 must be applied before relative times, and if mktime is applied
3282 again the time zone will be lost. */
3284 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3285 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3287 long int d1 = 60 * 60 * pc.rel.hour;
3288 time_t t1 = t0 + d1;
3289 long int d2 = 60 * pc.rel.minutes;
3290 time_t t2 = t1 + d2;
3291 long_time_t d3 = pc.rel.seconds;
3292 long_time_t t3 = t2 + d3;
3293 long int d4 = (sum_ns - normalized_ns) / BILLION;
3294 long_time_t t4 = t3 + d4;
3297 if ((d1 / (60 * 60) ^ pc.rel.hour)
3298 | (d2 / 60 ^ pc.rel.minutes)
3299 | ((t1 < t0) ^ (d1 < 0))
3300 | ((t2 < t1) ^ (d2 < 0))
3301 | ((t3 < t2) ^ (d3 < 0))
3302 | ((t4 < t3) ^ (d4 < 0))
3306 result->tv_sec = t5;
3307 result->tv_nsec = normalized_ns;
3317 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3326 main (int ac, char **av)
3330 printf ("Enter date, or blank line to exit.\n\t> ");
3333 buff[BUFSIZ - 1] = '\0';
3334 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3337 struct tm const *tm;
3338 if (! parse_datetime (&d, buff, NULL))
3339 printf ("Bad format - couldn't convert.\n");
3340 else if (! (tm = localtime (&d.tv_sec)))
3342 long int sec = d.tv_sec;
3343 printf ("localtime (%ld) failed\n", sec);
3348 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3349 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3350 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);