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-2011 Free Software Foundation, Inc.
123 This program is free software: you can redistribute it and/or modify
124 it under the terms of the GNU General Public License as published by
125 the Free Software Foundation; either version 3 of the License, or
126 (at your option) any later version.
128 This program is distributed in the hope that it will be useful,
129 but WITHOUT ANY WARRANTY; without even the implied warranty of
130 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131 GNU General Public License for more details.
133 You should have received a copy of the GNU General Public License
134 along with this program. If not, see <http://www.gnu.org/licenses/>. */
136 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
137 at the University of North Carolina at Chapel Hill. Later tweaked by
138 a couple of people on Usenet. Completely overhauled by Rich $alz
139 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
141 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
142 the right thing about local DST. Also modified by Paul Eggert
143 <eggert@cs.ucla.edu> in February 2004 to support
144 nanosecond-resolution time stamps, and in October 2004 to support
145 TZ strings in dates. */
147 /* FIXME: Check for arithmetic overflow in all cases, not just
152 #include "parse-datetime.h"
154 #include "intprops.h"
155 #include "timespec.h"
158 /* There's no need to extend the stack, so there's no need to involve
160 #define YYSTACK_USE_ALLOCA 0
162 /* Tell Bison how much stack space is needed. 20 should be plenty for
163 this grammar, which is not right recursive. Beware setting it too
164 high, since that might cause problems on machines whose
165 implementations have lame stack-overflow checking. */
166 #define YYMAXDEPTH 20
167 #define YYINITDEPTH YYMAXDEPTH
169 /* Since the code of parse-datetime.y is not included in the Emacs executable
170 itself, there is no need to #define static in this file. Even if
171 the code were included in the Emacs executable, it probably
172 wouldn't do any harm to #undef it here; this will only cause
173 problems if we try to write to a static variable, which I don't
174 think this code needs to do. */
187 /* Bison's skeleton tests _STDLIB_H, while some stdlib.h headers
188 use _STDLIB_H_ as witness. Map the latter to the one bison uses. */
189 /* FIXME: this is temporary. Remove when we have a mechanism to ensure
190 that the version we're using is fixed, too. */
196 /* ISDIGIT differs from isdigit, as follows:
197 - Its arg may be any int or unsigned int; it need not be an unsigned char
199 - It's typically faster.
200 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
201 isdigit unless it's important to use the locale's definition
202 of `digit' even when the host does not conform to POSIX. */
203 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
205 /* Shift A right by B bits portably, by dividing A by 2**B and
206 truncating towards minus infinity. A and B should be free of side
207 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
208 INT_BITS is the number of useful bits in an int. GNU code can
209 assume that INT_BITS is at least 32.
211 ISO C99 says that A >> B is implementation-defined if A < 0. Some
212 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
213 right in the usual way when A < 0, so SHR falls back on division if
214 ordinary A >> B doesn't seem to be the usual signed shift. */
218 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
220 #define EPOCH_YEAR 1970
221 #define TM_YEAR_BASE 1900
223 #define HOUR(x) ((x) * 60)
225 /* long_time_t is a signed integer type that contains all time_t values. */
226 verify (TYPE_IS_INTEGER (time_t));
227 #if TIME_T_FITS_IN_LONG_INT
228 typedef long int long_time_t;
230 typedef time_t long_time_t;
233 /* Lots of this code assumes time_t and time_t-like values fit into
235 verify (TYPE_MINIMUM (long_time_t) <= TYPE_MINIMUM (time_t)
236 && TYPE_MAXIMUM (time_t) <= TYPE_MAXIMUM (long_time_t));
238 /* FIXME: It also assumes that signed integer overflow silently wraps around,
239 but this is not true any more with recent versions of GCC 4. */
241 /* An integer value, and the number of digits in its textual
250 /* An entry in the lexical lookup table. */
258 /* Meridian: am, pm, or 24-hour style. */
259 enum { MERam, MERpm, MER24 };
261 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
263 /* Relative times. */
266 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
276 #if HAVE_COMPOUND_LITERALS
277 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
279 static relative_time const RELATIVE_TIME_0;
282 /* Information passed to and from the parser. */
285 /* The input string remaining to be parsed. */
288 /* N, if this is the Nth Tuesday. */
289 long int day_ordinal;
291 /* Day of week; Sunday is 0. */
294 /* tm_isdst flag for the local zone. */
297 /* Time zone, in minutes east of UTC. */
300 /* Style used for time. */
303 /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */
309 struct timespec seconds; /* includes nanoseconds */
311 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
314 /* Presence or counts of nonterminals of various flavors parsed so far. */
319 size_t local_zones_seen;
324 /* Table of local time zone abbrevations, terminated by a null entry. */
325 table local_time_zone_table[3];
329 static int yylex (union YYSTYPE *, parser_control *);
330 static int yyerror (parser_control const *, char const *);
331 static long int time_zone_hhmm (parser_control *, textint, long int);
333 /* Extract into *PC any date and time info from a string of digits
334 of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY,
337 digits_to_date_time (parser_control *pc, textint text_int)
339 if (pc->dates_seen && ! pc->year.digits
340 && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
344 if (4 < text_int.digits)
347 pc->day = text_int.value % 100;
348 pc->month = (text_int.value / 100) % 100;
349 pc->year.value = text_int.value / 10000;
350 pc->year.digits = text_int.digits - 4;
355 if (text_int.digits <= 2)
357 pc->hour = text_int.value;
362 pc->hour = text_int.value / 100;
363 pc->minutes = text_int.value % 100;
365 pc->seconds.tv_sec = 0;
366 pc->seconds.tv_nsec = 0;
367 pc->meridian = MER24;
372 /* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). */
374 apply_relative_time (parser_control *pc, relative_time rel, int factor)
376 pc->rel.ns += factor * rel.ns;
377 pc->rel.seconds += factor * rel.seconds;
378 pc->rel.minutes += factor * rel.minutes;
379 pc->rel.hour += factor * rel.hour;
380 pc->rel.day += factor * rel.day;
381 pc->rel.month += factor * rel.month;
382 pc->rel.year += factor * rel.year;
383 pc->rels_seen = true;
386 /* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */
388 set_hhmmss (parser_control *pc, long int hour, long int minutes,
389 time_t sec, long int nsec)
392 pc->minutes = minutes;
393 pc->seconds.tv_sec = sec;
394 pc->seconds.tv_nsec = nsec;
399 /* Enabling traces. */
404 /* Enabling verbose error messages. */
405 #ifdef YYERROR_VERBOSE
406 # undef YYERROR_VERBOSE
407 # define YYERROR_VERBOSE 1
409 # define YYERROR_VERBOSE 0
412 /* Enabling the token table. */
413 #ifndef YYTOKEN_TABLE
414 # define YYTOKEN_TABLE 0
417 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
418 typedef union YYSTYPE
419 #line 292 "parse-datetime.y"
423 struct timespec timespec;
426 /* Line 187 of yacc.c. */
427 #line 428 "parse-datetime.c"
429 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
430 # define YYSTYPE_IS_DECLARED 1
431 # define YYSTYPE_IS_TRIVIAL 1
436 /* Copy the second part of user declarations. */
439 /* Line 216 of yacc.c. */
440 #line 441 "parse-datetime.c"
447 typedef YYTYPE_UINT8 yytype_uint8;
449 typedef unsigned char yytype_uint8;
453 typedef YYTYPE_INT8 yytype_int8;
454 #elif (defined __STDC__ || defined __C99__FUNC__ \
455 || defined __cplusplus || defined _MSC_VER)
456 typedef signed char yytype_int8;
458 typedef short int yytype_int8;
462 typedef YYTYPE_UINT16 yytype_uint16;
464 typedef unsigned short int yytype_uint16;
468 typedef YYTYPE_INT16 yytype_int16;
470 typedef short int yytype_int16;
474 # ifdef __SIZE_TYPE__
475 # define YYSIZE_T __SIZE_TYPE__
476 # elif defined size_t
477 # define YYSIZE_T size_t
478 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
479 || defined __cplusplus || defined _MSC_VER)
480 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
481 # define YYSIZE_T size_t
483 # define YYSIZE_T unsigned int
487 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
492 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
493 # define YY_(msgid) dgettext ("bison-runtime", msgid)
497 # define YY_(msgid) msgid
501 /* Suppress unused-variable warnings by "using" E. */
502 #if ! defined lint || defined __GNUC__
503 # define YYUSE(e) ((void) (e))
505 # define YYUSE(e) /* empty */
508 /* Identity function, used to suppress warnings about constant conditions. */
512 #if (defined __STDC__ || defined __C99__FUNC__ \
513 || defined __cplusplus || defined _MSC_VER)
526 #if ! defined yyoverflow || YYERROR_VERBOSE
528 /* The parser invokes alloca or malloc; define the necessary symbols. */
530 # ifdef YYSTACK_USE_ALLOCA
531 # if YYSTACK_USE_ALLOCA
533 # define YYSTACK_ALLOC __builtin_alloca
534 # elif defined __BUILTIN_VA_ARG_INCR
535 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
537 # define YYSTACK_ALLOC __alloca
538 # elif defined _MSC_VER
539 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
540 # define alloca _alloca
542 # define YYSTACK_ALLOC alloca
543 # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
544 || defined __cplusplus || defined _MSC_VER)
545 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
554 # ifdef YYSTACK_ALLOC
555 /* Pacify GCC's `empty if-body' warning. */
556 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
557 # ifndef YYSTACK_ALLOC_MAXIMUM
558 /* The OS might guarantee only one guard page at the bottom of the stack,
559 and a page size can be as small as 4096 bytes. So we cannot safely
560 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
561 to allow for a few compiler-allocated temporary stack slots. */
562 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
565 # define YYSTACK_ALLOC YYMALLOC
566 # define YYSTACK_FREE YYFREE
567 # ifndef YYSTACK_ALLOC_MAXIMUM
568 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
570 # if (defined __cplusplus && ! defined _STDLIB_H \
571 && ! ((defined YYMALLOC || defined malloc) \
572 && (defined YYFREE || defined free)))
573 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
579 # define YYMALLOC malloc
580 # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
581 || defined __cplusplus || defined _MSC_VER)
582 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
587 # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
588 || defined __cplusplus || defined _MSC_VER)
589 void free (void *); /* INFRINGES ON USER NAME SPACE */
593 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
596 #if (! defined yyoverflow \
597 && (! defined __cplusplus \
598 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
600 /* A type that is properly aligned for any stack member. */
607 /* The size of the maximum gap between one aligned stack and the next. */
608 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
610 /* The size of an array large to enough to hold all stacks, each with
612 # define YYSTACK_BYTES(N) \
613 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
614 + YYSTACK_GAP_MAXIMUM)
616 /* Copy COUNT objects from FROM to TO. The source and destination do
619 # if defined __GNUC__ && 1 < __GNUC__
620 # define YYCOPY(To, From, Count) \
621 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
623 # define YYCOPY(To, From, Count) \
627 for (yyi = 0; yyi < (Count); yyi++) \
628 (To)[yyi] = (From)[yyi]; \
634 /* Relocate STACK from its old location to the new one. The
635 local variables YYSIZE and YYSTACKSIZE give the old and new number of
636 elements in the stack, and YYPTR gives the new location of the
637 stack. Advance YYPTR to a properly aligned location for the next
639 # define YYSTACK_RELOCATE(Stack) \
642 YYSIZE_T yynewbytes; \
643 YYCOPY (&yyptr->Stack, Stack, yysize); \
644 Stack = &yyptr->Stack; \
645 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
646 yyptr += yynewbytes / sizeof (*yyptr); \
652 /* YYFINAL -- State number of the termination state. */
654 /* YYLAST -- Last index in YYTABLE. */
657 /* YYNTOKENS -- Number of terminals. */
659 /* YYNNTS -- Number of nonterminals. */
661 /* YYNRULES -- Number of rules. */
663 /* YYNRULES -- Number of states. */
664 #define YYNSTATES 100
666 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
668 #define YYMAXUTOK 277
670 #define YYTRANSLATE(YYX) \
671 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
673 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
674 static const yytype_uint8 yytranslate[] =
676 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
677 2, 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, 25, 2, 2, 26, 2, 2,
681 2, 2, 2, 2, 2, 2, 2, 2, 24, 2,
682 2, 2, 2, 2, 23, 2, 2, 2, 2, 2,
683 2, 2, 2, 2, 2, 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, 1, 2, 3, 4,
702 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
703 15, 16, 17, 18, 19, 20, 21, 22
707 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
709 static const yytype_uint8 yyprhs[] =
711 0, 0, 3, 5, 7, 10, 11, 14, 16, 18,
712 20, 22, 24, 26, 28, 30, 33, 38, 44, 51,
713 59, 61, 64, 66, 69, 73, 75, 78, 80, 83,
714 86, 89, 93, 99, 103, 107, 111, 114, 119, 122,
715 126, 129, 131, 133, 136, 139, 141, 144, 147, 149,
716 152, 155, 157, 160, 163, 165, 168, 171, 173, 176,
717 179, 182, 185, 187, 189, 192, 195, 198, 201, 204,
718 207, 209, 211, 213, 215, 217, 219, 221, 223, 226,
722 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
723 static const yytype_int8 yyrhs[] =
725 28, 0, -1, 29, -1, 30, -1, 23, 41, -1,
726 -1, 30, 31, -1, 32, -1, 33, -1, 34, -1,
727 36, -1, 35, -1, 37, -1, 44, -1, 45, -1,
728 20, 15, -1, 20, 24, 20, 47, -1, 20, 24,
729 20, 19, 46, -1, 20, 24, 20, 24, 43, 47,
730 -1, 20, 24, 20, 24, 43, 19, 46, -1, 14,
731 -1, 14, 4, -1, 18, -1, 18, 39, -1, 18,
732 19, 46, -1, 13, -1, 18, 4, -1, 12, -1,
733 12, 25, -1, 17, 12, -1, 20, 12, -1, 20,
734 26, 20, -1, 20, 26, 20, 26, 20, -1, 20,
735 19, 19, -1, 20, 16, 19, -1, 16, 19, 19,
736 -1, 16, 20, -1, 16, 20, 25, 20, -1, 20,
737 16, -1, 20, 16, 20, -1, 38, 3, -1, 38,
738 -1, 40, -1, 17, 5, -1, 20, 5, -1, 5,
739 -1, 17, 6, -1, 20, 6, -1, 6, -1, 17,
740 10, -1, 20, 10, -1, 10, -1, 17, 7, -1,
741 20, 7, -1, 7, -1, 17, 8, -1, 20, 8,
742 -1, 8, -1, 17, 9, -1, 20, 9, -1, 21,
743 9, -1, 22, 9, -1, 9, -1, 39, -1, 19,
744 5, -1, 19, 6, -1, 19, 10, -1, 19, 7,
745 -1, 19, 8, -1, 19, 9, -1, 11, -1, 42,
746 -1, 43, -1, 21, -1, 19, -1, 22, -1, 20,
747 -1, 20, -1, 20, 39, -1, -1, 24, 20, -1,
751 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
752 static const yytype_uint16 yyrline[] =
754 0, 318, 318, 319, 323, 330, 332, 336, 338, 340,
755 342, 344, 346, 347, 348, 352, 357, 362, 369, 374,
756 384, 389, 397, 399, 402, 404, 406, 411, 416, 421,
757 426, 434, 439, 459, 466, 474, 482, 487, 493, 498,
758 507, 509, 511, 516, 518, 520, 522, 524, 526, 528,
759 530, 532, 534, 536, 538, 540, 542, 544, 546, 548,
760 550, 552, 554, 556, 560, 562, 564, 566, 568, 570,
761 575, 579, 579, 582, 583, 588, 589, 594, 599, 610,
766 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
767 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
768 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
769 static const char *const yytname[] =
771 "$end", "error", "$undefined", "tAGO", "tDST", "tYEAR_UNIT",
772 "tMONTH_UNIT", "tHOUR_UNIT", "tMINUTE_UNIT", "tSEC_UNIT", "tDAY_UNIT",
773 "tDAY_SHIFT", "tDAY", "tDAYZONE", "tLOCAL_ZONE", "tMERIDIAN", "tMONTH",
774 "tORDINAL", "tZONE", "tSNUMBER", "tUNUMBER", "tSDECIMAL_NUMBER",
775 "tUDECIMAL_NUMBER", "'@'", "':'", "','", "'/'", "$accept", "spec",
776 "timespec", "items", "item", "time", "local_zone", "zone", "day", "date",
777 "rel", "relunit", "relunit_snumber", "dayshift", "seconds",
778 "signed_seconds", "unsigned_seconds", "number", "hybrid",
779 "o_colon_minutes", "o_merid", 0
784 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
786 static const yytype_uint16 yytoknum[] =
788 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
789 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
790 275, 276, 277, 64, 58, 44, 47
794 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
795 static const yytype_uint8 yyr1[] =
797 0, 27, 28, 28, 29, 30, 30, 31, 31, 31,
798 31, 31, 31, 31, 31, 32, 32, 32, 32, 32,
799 33, 33, 34, 34, 34, 34, 34, 35, 35, 35,
800 35, 36, 36, 36, 36, 36, 36, 36, 36, 36,
801 37, 37, 37, 38, 38, 38, 38, 38, 38, 38,
802 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
803 38, 38, 38, 38, 39, 39, 39, 39, 39, 39,
804 40, 41, 41, 42, 42, 43, 43, 44, 45, 46,
808 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
809 static const yytype_uint8 yyr2[] =
811 0, 2, 1, 1, 2, 0, 2, 1, 1, 1,
812 1, 1, 1, 1, 1, 2, 4, 5, 6, 7,
813 1, 2, 1, 2, 3, 1, 2, 1, 2, 2,
814 2, 3, 5, 3, 3, 3, 2, 4, 2, 3,
815 2, 1, 1, 2, 2, 1, 2, 2, 1, 2,
816 2, 1, 2, 2, 1, 2, 2, 1, 2, 2,
817 2, 2, 1, 1, 2, 2, 2, 2, 2, 2,
818 1, 1, 1, 1, 1, 1, 1, 1, 2, 0,
822 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
823 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
824 means the default is an error. */
825 static const yytype_uint8 yydefact[] =
827 5, 0, 0, 2, 3, 74, 76, 73, 75, 4,
828 71, 72, 1, 45, 48, 54, 57, 62, 51, 70,
829 27, 25, 20, 0, 0, 22, 0, 77, 0, 0,
830 6, 7, 8, 9, 11, 10, 12, 41, 63, 42,
831 13, 14, 28, 21, 0, 36, 43, 46, 52, 55,
832 58, 49, 29, 26, 79, 23, 64, 65, 67, 68,
833 69, 66, 44, 47, 53, 56, 59, 50, 30, 15,
834 38, 0, 0, 0, 78, 60, 61, 40, 35, 0,
835 0, 24, 34, 39, 33, 81, 31, 37, 80, 82,
836 79, 0, 16, 0, 17, 81, 32, 79, 18, 19
839 /* YYDEFGOTO[NTERM-NUM]. */
840 static const yytype_int8 yydefgoto[] =
842 -1, 2, 3, 4, 30, 31, 32, 33, 34, 35,
843 36, 37, 38, 39, 9, 10, 11, 40, 41, 81,
847 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
849 #define YYPACT_NINF -82
850 static const yytype_int8 yypact[] =
852 -17, 56, 15, -82, 26, -82, -82, -82, -82, -82,
853 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82,
854 36, -82, 68, 10, 50, 9, 59, -5, 72, 73,
855 -82, -82, -82, -82, -82, -82, -82, 80, -82, -82,
856 -82, -82, -82, -82, 65, 61, -82, -82, -82, -82,
857 -82, -82, -82, -82, 17, -82, -82, -82, -82, -82,
858 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82,
859 60, 44, 67, 69, -82, -82, -82, -82, -82, 70,
860 71, -82, -82, -82, -82, -7, 62, -82, -82, -82,
861 74, -2, -82, 75, -82, 55, -82, 74, -82, -82
864 /* YYPGOTO[NTERM-NUM]. */
865 static const yytype_int8 yypgoto[] =
867 -82, -82, -82, -82, -82, -82, -82, -82, -82, -82,
868 -82, -82, 46, -82, -82, -82, -6, -82, -82, -81,
872 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
873 positive, shift that token. If negative, reduce the rule which
874 number is the opposite. If zero, do what YYDEFACT says.
875 If YYTABLE_NINF, syntax error. */
876 #define YYTABLE_NINF -1
877 static const yytype_uint8 yytable[] =
879 62, 63, 64, 65, 66, 67, 1, 68, 89, 94,
880 69, 70, 90, 53, 71, 12, 99, 91, 6, 72,
881 8, 73, 56, 57, 58, 59, 60, 61, 54, 44,
882 45, 13, 14, 15, 16, 17, 18, 19, 20, 21,
883 22, 80, 23, 24, 25, 26, 27, 28, 29, 56,
884 57, 58, 59, 60, 61, 46, 47, 48, 49, 50,
885 51, 42, 52, 84, 56, 57, 58, 59, 60, 61,
886 89, 55, 43, 74, 97, 5, 6, 7, 8, 82,
887 83, 75, 76, 77, 78, 95, 79, 85, 93, 86,
888 87, 88, 98, 0, 0, 96, 0, 0, 80
891 static const yytype_int8 yycheck[] =
893 5, 6, 7, 8, 9, 10, 23, 12, 15, 90,
894 15, 16, 19, 4, 19, 0, 97, 24, 20, 24,
895 22, 26, 5, 6, 7, 8, 9, 10, 19, 19,
896 20, 5, 6, 7, 8, 9, 10, 11, 12, 13,
897 14, 24, 16, 17, 18, 19, 20, 21, 22, 5,
898 6, 7, 8, 9, 10, 5, 6, 7, 8, 9,
899 10, 25, 12, 19, 5, 6, 7, 8, 9, 10,
900 15, 25, 4, 27, 19, 19, 20, 21, 22, 19,
901 20, 9, 9, 3, 19, 91, 25, 20, 26, 20,
902 20, 20, 95, -1, -1, 20, -1, -1, 24
905 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
906 symbol of state STATE-NUM. */
907 static const yytype_uint8 yystos[] =
909 0, 23, 28, 29, 30, 19, 20, 21, 22, 41,
910 42, 43, 0, 5, 6, 7, 8, 9, 10, 11,
911 12, 13, 14, 16, 17, 18, 19, 20, 21, 22,
912 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
913 44, 45, 25, 4, 19, 20, 5, 6, 7, 8,
914 9, 10, 12, 4, 19, 39, 5, 6, 7, 8,
915 9, 10, 5, 6, 7, 8, 9, 10, 12, 15,
916 16, 19, 24, 26, 39, 9, 9, 3, 19, 25,
917 24, 46, 19, 20, 19, 20, 20, 20, 20, 15,
918 19, 24, 47, 26, 46, 43, 20, 19, 47, 46
921 #define yyerrok (yyerrstatus = 0)
922 #define yyclearin (yychar = YYEMPTY)
926 #define YYACCEPT goto yyacceptlab
927 #define YYABORT goto yyabortlab
928 #define YYERROR goto yyerrorlab
931 /* Like YYERROR except do call yyerror. This remains here temporarily
932 to ease the transition to the new meaning of YYERROR, for GCC.
933 Once GCC version 2 has supplanted version 1, this can go. */
935 #define YYFAIL goto yyerrlab
937 #define YYRECOVERING() (!!yyerrstatus)
939 #define YYBACKUP(Token, Value) \
941 if (yychar == YYEMPTY && yylen == 1) \
945 yytoken = YYTRANSLATE (yychar); \
951 yyerror (pc, YY_("syntax error: cannot back up")); \
958 #define YYERRCODE 256
961 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
962 If N is 0, then set CURRENT to the empty location which ends
963 the previous symbol: RHS[0] (always defined). */
965 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
966 #ifndef YYLLOC_DEFAULT
967 # define YYLLOC_DEFAULT(Current, Rhs, N) \
971 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
972 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
973 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
974 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
978 (Current).first_line = (Current).last_line = \
979 YYRHSLOC (Rhs, 0).last_line; \
980 (Current).first_column = (Current).last_column = \
981 YYRHSLOC (Rhs, 0).last_column; \
987 /* YY_LOCATION_PRINT -- Print the location on the stream.
988 This macro was not mandated originally: define only if we know
989 we won't break user code: when these are the locations we know. */
991 #ifndef YY_LOCATION_PRINT
992 # if YYLTYPE_IS_TRIVIAL
993 # define YY_LOCATION_PRINT(File, Loc) \
994 fprintf (File, "%d.%d-%d.%d", \
995 (Loc).first_line, (Loc).first_column, \
996 (Loc).last_line, (Loc).last_column)
998 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1003 /* YYLEX -- calling `yylex' with the right arguments. */
1006 # define YYLEX yylex (&yylval, YYLEX_PARAM)
1008 # define YYLEX yylex (&yylval, pc)
1011 /* Enable debugging if requested. */
1015 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1016 # define YYFPRINTF fprintf
1019 # define YYDPRINTF(Args) \
1025 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1029 YYFPRINTF (stderr, "%s ", Title); \
1030 yy_symbol_print (stderr, \
1032 YYFPRINTF (stderr, "\n"); \
1037 /*--------------------------------.
1038 | Print this symbol on YYOUTPUT. |
1039 `--------------------------------*/
1042 #if (defined __STDC__ || defined __C99__FUNC__ \
1043 || defined __cplusplus || defined _MSC_VER)
1045 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1048 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc)
1051 YYSTYPE const * const yyvaluep;
1059 if (yytype < YYNTOKENS)
1060 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1072 /*--------------------------------.
1073 | Print this symbol on YYOUTPUT. |
1074 `--------------------------------*/
1076 #if (defined __STDC__ || defined __C99__FUNC__ \
1077 || defined __cplusplus || defined _MSC_VER)
1079 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, parser_control *pc)
1082 yy_symbol_print (yyoutput, yytype, yyvaluep, pc)
1085 YYSTYPE const * const yyvaluep;
1089 if (yytype < YYNTOKENS)
1090 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
1092 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
1094 yy_symbol_value_print (yyoutput, yytype, yyvaluep, pc);
1095 YYFPRINTF (yyoutput, ")");
1098 /*------------------------------------------------------------------.
1099 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1101 `------------------------------------------------------------------*/
1103 #if (defined __STDC__ || defined __C99__FUNC__ \
1104 || defined __cplusplus || defined _MSC_VER)
1106 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
1109 yy_stack_print (bottom, top)
1110 yytype_int16 *bottom;
1114 YYFPRINTF (stderr, "Stack now");
1115 for (; bottom <= top; ++bottom)
1116 YYFPRINTF (stderr, " %d", *bottom);
1117 YYFPRINTF (stderr, "\n");
1120 # define YY_STACK_PRINT(Bottom, Top) \
1123 yy_stack_print ((Bottom), (Top)); \
1127 /*------------------------------------------------.
1128 | Report that the YYRULE is going to be reduced. |
1129 `------------------------------------------------*/
1131 #if (defined __STDC__ || defined __C99__FUNC__ \
1132 || defined __cplusplus || defined _MSC_VER)
1134 yy_reduce_print (YYSTYPE *yyvsp, int yyrule, parser_control *pc)
1137 yy_reduce_print (yyvsp, yyrule, pc)
1143 int yynrhs = yyr2[yyrule];
1145 unsigned long int yylno = yyrline[yyrule];
1146 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1148 /* The symbols being reduced. */
1149 for (yyi = 0; yyi < yynrhs; yyi++)
1151 fprintf (stderr, " $%d = ", yyi + 1);
1152 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1153 &(yyvsp[(yyi + 1) - (yynrhs)])
1155 fprintf (stderr, "\n");
1159 # define YY_REDUCE_PRINT(Rule) \
1162 yy_reduce_print (yyvsp, Rule, pc); \
1165 /* Nonzero means print parse trace. It is left uninitialized so that
1166 multiple parsers can coexist. */
1168 #else /* !YYDEBUG */
1169 # define YYDPRINTF(Args)
1170 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1171 # define YY_STACK_PRINT(Bottom, Top)
1172 # define YY_REDUCE_PRINT(Rule)
1173 #endif /* !YYDEBUG */
1176 /* YYINITDEPTH -- initial size of the parser's stacks. */
1178 # define YYINITDEPTH 200
1181 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1182 if the built-in stack extension method is used).
1184 Do not make this value too large; the results are undefined if
1185 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1186 evaluated with infinite-precision integer arithmetic. */
1189 # define YYMAXDEPTH 10000
1197 # if defined __GLIBC__ && defined _STRING_H
1198 # define yystrlen strlen
1200 /* Return the length of YYSTR. */
1201 #if (defined __STDC__ || defined __C99__FUNC__ \
1202 || defined __cplusplus || defined _MSC_VER)
1204 yystrlen (const char *yystr)
1212 for (yylen = 0; yystr[yylen]; yylen++)
1220 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1221 # define yystpcpy stpcpy
1223 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1225 #if (defined __STDC__ || defined __C99__FUNC__ \
1226 || defined __cplusplus || defined _MSC_VER)
1228 yystpcpy (char *yydest, const char *yysrc)
1231 yystpcpy (yydest, yysrc)
1237 const char *yys = yysrc;
1239 while ((*yyd++ = *yys++) != '\0')
1248 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1249 quotes and backslashes, so that it's suitable for yyerror. The
1250 heuristic is that double-quoting is unnecessary unless the string
1251 contains an apostrophe, a comma, or backslash (other than
1252 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1253 null, do not copy; instead, return the length of what the result
1256 yytnamerr (char *yyres, const char *yystr)
1261 char const *yyp = yystr;
1268 goto do_not_strip_quotes;
1272 goto do_not_strip_quotes;
1285 do_not_strip_quotes: ;
1289 return yystrlen (yystr);
1291 return yystpcpy (yyres, yystr) - yyres;
1295 /* Copy into YYRESULT an error message about the unexpected token
1296 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1297 including the terminating null byte. If YYRESULT is null, do not
1298 copy anything; just return the number of bytes that would be
1299 copied. As a special case, return 0 if an ordinary "syntax error"
1300 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1301 size calculation. */
1303 yysyntax_error (char *yyresult, int yystate, int yychar)
1305 int yyn = yypact[yystate];
1307 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1311 int yytype = YYTRANSLATE (yychar);
1312 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1313 YYSIZE_T yysize = yysize0;
1315 int yysize_overflow = 0;
1316 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1317 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1321 /* This is so xgettext sees the translatable formats that are
1322 constructed on the fly. */
1323 YY_("syntax error, unexpected %s");
1324 YY_("syntax error, unexpected %s, expecting %s");
1325 YY_("syntax error, unexpected %s, expecting %s or %s");
1326 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1327 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1331 static char const yyunexpected[] = "syntax error, unexpected %s";
1332 static char const yyexpecting[] = ", expecting %s";
1333 static char const yyor[] = " or %s";
1334 char yyformat[sizeof yyunexpected
1335 + sizeof yyexpecting - 1
1336 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1337 * (sizeof yyor - 1))];
1338 char const *yyprefix = yyexpecting;
1340 /* Start YYX at -YYN if negative to avoid negative indexes in
1342 int yyxbegin = yyn < 0 ? -yyn : 0;
1344 /* Stay within bounds of both yycheck and yytname. */
1345 int yychecklim = YYLAST - yyn + 1;
1346 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1349 yyarg[0] = yytname[yytype];
1350 yyfmt = yystpcpy (yyformat, yyunexpected);
1352 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1353 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1355 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1359 yyformat[sizeof yyunexpected - 1] = '\0';
1362 yyarg[yycount++] = yytname[yyx];
1363 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1364 yysize_overflow |= (yysize1 < yysize);
1366 yyfmt = yystpcpy (yyfmt, yyprefix);
1370 yyf = YY_(yyformat);
1371 yysize1 = yysize + yystrlen (yyf);
1372 yysize_overflow |= (yysize1 < yysize);
1375 if (yysize_overflow)
1376 return YYSIZE_MAXIMUM;
1380 /* Avoid sprintf, as that infringes on the user's name space.
1381 Don't have undefined behavior even if the translation
1382 produced a string with the wrong number of "%s"s. */
1383 char *yyp = yyresult;
1385 while ((*yyp = *yyf) != '\0')
1387 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1389 yyp += yytnamerr (yyp, yyarg[yyi++]);
1402 #endif /* YYERROR_VERBOSE */
1405 /*-----------------------------------------------.
1406 | Release the memory associated to this symbol. |
1407 `-----------------------------------------------*/
1410 #if (defined __STDC__ || defined __C99__FUNC__ \
1411 || defined __cplusplus || defined _MSC_VER)
1413 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, parser_control *pc)
1416 yydestruct (yymsg, yytype, yyvaluep, pc)
1428 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1439 /* Prevent warnings from -Wmissing-prototypes. */
1441 #ifdef YYPARSE_PARAM
1442 #if defined __STDC__ || defined __cplusplus
1443 int yyparse (void *YYPARSE_PARAM);
1447 #else /* ! YYPARSE_PARAM */
1448 #if defined __STDC__ || defined __cplusplus
1449 int yyparse (parser_control *pc);
1453 #endif /* ! YYPARSE_PARAM */
1464 #ifdef YYPARSE_PARAM
1465 #if (defined __STDC__ || defined __C99__FUNC__ \
1466 || defined __cplusplus || defined _MSC_VER)
1468 yyparse (void *YYPARSE_PARAM)
1471 yyparse (YYPARSE_PARAM)
1472 void *YYPARSE_PARAM;
1474 #else /* ! YYPARSE_PARAM */
1475 #if (defined __STDC__ || defined __C99__FUNC__ \
1476 || defined __cplusplus || defined _MSC_VER)
1478 yyparse (parser_control *pc)
1486 /* The look-ahead symbol. */
1489 /* The semantic value of the look-ahead symbol. */
1492 /* Number of syntax errors so far. */
1498 /* Number of tokens to shift before error messages enabled. */
1500 /* Look-ahead token as an internal (translated) token number. */
1503 /* Buffer for error messages, and its allocated size. */
1505 char *yymsg = yymsgbuf;
1506 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1509 /* Three stacks and their tools:
1510 `yyss': related to states,
1511 `yyvs': related to semantic values,
1512 `yyls': related to locations.
1514 Refer to the stacks thru separate pointers, to allow yyoverflow
1515 to reallocate them elsewhere. */
1517 /* The state stack. */
1518 yytype_int16 yyssa[YYINITDEPTH];
1519 yytype_int16 *yyss = yyssa;
1520 yytype_int16 *yyssp;
1522 /* The semantic value stack. */
1523 YYSTYPE yyvsa[YYINITDEPTH];
1524 YYSTYPE *yyvs = yyvsa;
1529 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1531 YYSIZE_T yystacksize = YYINITDEPTH;
1533 /* The variables used to return semantic value and location from the
1538 /* The number of symbols on the RHS of the reduced rule.
1539 Keep to zero when no symbol should be popped. */
1542 YYDPRINTF ((stderr, "Starting parse\n"));
1547 yychar = YYEMPTY; /* Cause a token to be read. */
1549 /* Initialize stack pointers.
1550 Waste one element of value and location stack
1551 so that they stay on the same level as the state stack.
1552 The wasted elements are never initialized. */
1559 /*------------------------------------------------------------.
1560 | yynewstate -- Push a new state, which is found in yystate. |
1561 `------------------------------------------------------------*/
1563 /* In all cases, when you get here, the value and location stacks
1564 have just been pushed. So pushing a state here evens the stacks. */
1570 if (yyss + yystacksize - 1 <= yyssp)
1572 /* Get the current used size of the three stacks, in elements. */
1573 YYSIZE_T yysize = yyssp - yyss + 1;
1577 /* Give user a chance to reallocate the stack. Use copies of
1578 these so that the &'s don't force the real ones into
1580 YYSTYPE *yyvs1 = yyvs;
1581 yytype_int16 *yyss1 = yyss;
1584 /* Each stack pointer address is followed by the size of the
1585 data in use in that stack, in bytes. This used to be a
1586 conditional around just the two extra args, but that might
1587 be undefined if yyoverflow is a macro. */
1588 yyoverflow (YY_("memory exhausted"),
1589 &yyss1, yysize * sizeof (*yyssp),
1590 &yyvs1, yysize * sizeof (*yyvsp),
1597 #else /* no yyoverflow */
1598 # ifndef YYSTACK_RELOCATE
1599 goto yyexhaustedlab;
1601 /* Extend the stack our own way. */
1602 if (YYMAXDEPTH <= yystacksize)
1603 goto yyexhaustedlab;
1605 if (YYMAXDEPTH < yystacksize)
1606 yystacksize = YYMAXDEPTH;
1609 yytype_int16 *yyss1 = yyss;
1610 union yyalloc *yyptr =
1611 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1613 goto yyexhaustedlab;
1614 YYSTACK_RELOCATE (yyss);
1615 YYSTACK_RELOCATE (yyvs);
1617 # undef YYSTACK_RELOCATE
1619 YYSTACK_FREE (yyss1);
1622 #endif /* no yyoverflow */
1624 yyssp = yyss + yysize - 1;
1625 yyvsp = yyvs + yysize - 1;
1628 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1629 (unsigned long int) yystacksize));
1631 if (yyss + yystacksize - 1 <= yyssp)
1635 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1644 /* Do appropriate processing given the current state. Read a
1645 look-ahead token if we need one and don't already have one. */
1647 /* First try to decide what to do without reference to look-ahead token. */
1648 yyn = yypact[yystate];
1649 if (yyn == YYPACT_NINF)
1652 /* Not known => get a look-ahead token if don't already have one. */
1654 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1655 if (yychar == YYEMPTY)
1657 YYDPRINTF ((stderr, "Reading a token: "));
1661 if (yychar <= YYEOF)
1663 yychar = yytoken = YYEOF;
1664 YYDPRINTF ((stderr, "Now at end of input.\n"));
1668 yytoken = YYTRANSLATE (yychar);
1669 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1672 /* If the proper action on seeing token YYTOKEN is to reduce or to
1673 detect an error, take that action. */
1675 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1680 if (yyn == 0 || yyn == YYTABLE_NINF)
1689 /* Count tokens shifted since error; after three, turn off error
1694 /* Shift the look-ahead token. */
1695 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1697 /* Discard the shifted token unless it is eof. */
1698 if (yychar != YYEOF)
1707 /*-----------------------------------------------------------.
1708 | yydefault -- do the default action for the current state. |
1709 `-----------------------------------------------------------*/
1711 yyn = yydefact[yystate];
1717 /*-----------------------------.
1718 | yyreduce -- Do a reduction. |
1719 `-----------------------------*/
1721 /* yyn is the number of a rule to reduce with. */
1724 /* If YYLEN is nonzero, implement the default value of the action:
1727 Otherwise, the following line sets YYVAL to garbage.
1728 This behavior is undocumented and Bison
1729 users should not rely upon it. Assigning to YYVAL
1730 unconditionally makes the parser a bit smaller, and it avoids a
1731 GCC warning that YYVAL may be used uninitialized. */
1732 yyval = yyvsp[1-yylen];
1735 YY_REDUCE_PRINT (yyn);
1739 #line 324 "parse-datetime.y"
1741 pc->seconds = (yyvsp[(2) - (2)].timespec);
1742 pc->timespec_seen = true;
1747 #line 337 "parse-datetime.y"
1748 { pc->times_seen++; }
1752 #line 339 "parse-datetime.y"
1753 { pc->local_zones_seen++; }
1757 #line 341 "parse-datetime.y"
1758 { pc->zones_seen++; }
1762 #line 343 "parse-datetime.y"
1763 { pc->dates_seen++; }
1767 #line 345 "parse-datetime.y"
1768 { pc->days_seen++; }
1772 #line 353 "parse-datetime.y"
1774 set_hhmmss (pc, (yyvsp[(1) - (2)].textintval).value, 0, 0, 0);
1775 pc->meridian = (yyvsp[(2) - (2)].intval);
1780 #line 358 "parse-datetime.y"
1782 set_hhmmss (pc, (yyvsp[(1) - (4)].textintval).value, (yyvsp[(3) - (4)].textintval).value, 0, 0);
1783 pc->meridian = (yyvsp[(4) - (4)].intval);
1788 #line 363 "parse-datetime.y"
1790 set_hhmmss (pc, (yyvsp[(1) - (5)].textintval).value, (yyvsp[(3) - (5)].textintval).value, 0, 0);
1791 pc->meridian = MER24;
1793 pc->time_zone = time_zone_hhmm (pc, (yyvsp[(4) - (5)].textintval), (yyvsp[(5) - (5)].intval));
1798 #line 370 "parse-datetime.y"
1800 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);
1801 pc->meridian = (yyvsp[(6) - (6)].intval);
1806 #line 375 "parse-datetime.y"
1808 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);
1809 pc->meridian = MER24;
1811 pc->time_zone = time_zone_hhmm (pc, (yyvsp[(6) - (7)].textintval), (yyvsp[(7) - (7)].intval));
1816 #line 385 "parse-datetime.y"
1818 pc->local_isdst = (yyvsp[(1) - (1)].intval);
1819 pc->dsts_seen += (0 < (yyvsp[(1) - (1)].intval));
1824 #line 390 "parse-datetime.y"
1826 pc->local_isdst = 1;
1827 pc->dsts_seen += (0 < (yyvsp[(1) - (2)].intval)) + 1;
1832 #line 398 "parse-datetime.y"
1833 { pc->time_zone = (yyvsp[(1) - (1)].intval); }
1837 #line 400 "parse-datetime.y"
1838 { pc->time_zone = (yyvsp[(1) - (2)].intval);
1839 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1); }
1843 #line 403 "parse-datetime.y"
1844 { pc->time_zone = (yyvsp[(1) - (3)].intval) + time_zone_hhmm (pc, (yyvsp[(2) - (3)].textintval), (yyvsp[(3) - (3)].intval)); }
1848 #line 405 "parse-datetime.y"
1849 { pc->time_zone = (yyvsp[(1) - (1)].intval) + 60; }
1853 #line 407 "parse-datetime.y"
1854 { pc->time_zone = (yyvsp[(1) - (2)].intval) + 60; }
1858 #line 412 "parse-datetime.y"
1860 pc->day_ordinal = 0;
1861 pc->day_number = (yyvsp[(1) - (1)].intval);
1866 #line 417 "parse-datetime.y"
1868 pc->day_ordinal = 0;
1869 pc->day_number = (yyvsp[(1) - (2)].intval);
1874 #line 422 "parse-datetime.y"
1876 pc->day_ordinal = (yyvsp[(1) - (2)].intval);
1877 pc->day_number = (yyvsp[(2) - (2)].intval);
1882 #line 427 "parse-datetime.y"
1884 pc->day_ordinal = (yyvsp[(1) - (2)].textintval).value;
1885 pc->day_number = (yyvsp[(2) - (2)].intval);
1890 #line 435 "parse-datetime.y"
1892 pc->month = (yyvsp[(1) - (3)].textintval).value;
1893 pc->day = (yyvsp[(3) - (3)].textintval).value;
1898 #line 440 "parse-datetime.y"
1900 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
1901 otherwise as MM/DD/YY.
1902 The goal in recognizing YYYY/MM/DD is solely to support legacy
1903 machine-generated dates like those in an RCS log listing. If
1904 you want portability, use the ISO 8601 format. */
1905 if (4 <= (yyvsp[(1) - (5)].textintval).digits)
1907 pc->year = (yyvsp[(1) - (5)].textintval);
1908 pc->month = (yyvsp[(3) - (5)].textintval).value;
1909 pc->day = (yyvsp[(5) - (5)].textintval).value;
1913 pc->month = (yyvsp[(1) - (5)].textintval).value;
1914 pc->day = (yyvsp[(3) - (5)].textintval).value;
1915 pc->year = (yyvsp[(5) - (5)].textintval);
1921 #line 460 "parse-datetime.y"
1923 /* ISO 8601 format. YYYY-MM-DD. */
1924 pc->year = (yyvsp[(1) - (3)].textintval);
1925 pc->month = -(yyvsp[(2) - (3)].textintval).value;
1926 pc->day = -(yyvsp[(3) - (3)].textintval).value;
1931 #line 467 "parse-datetime.y"
1933 /* e.g. 17-JUN-1992. */
1934 pc->day = (yyvsp[(1) - (3)].textintval).value;
1935 pc->month = (yyvsp[(2) - (3)].intval);
1936 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1937 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1942 #line 475 "parse-datetime.y"
1944 /* e.g. JUN-17-1992. */
1945 pc->month = (yyvsp[(1) - (3)].intval);
1946 pc->day = -(yyvsp[(2) - (3)].textintval).value;
1947 pc->year.value = -(yyvsp[(3) - (3)].textintval).value;
1948 pc->year.digits = (yyvsp[(3) - (3)].textintval).digits;
1953 #line 483 "parse-datetime.y"
1955 pc->month = (yyvsp[(1) - (2)].intval);
1956 pc->day = (yyvsp[(2) - (2)].textintval).value;
1961 #line 488 "parse-datetime.y"
1963 pc->month = (yyvsp[(1) - (4)].intval);
1964 pc->day = (yyvsp[(2) - (4)].textintval).value;
1965 pc->year = (yyvsp[(4) - (4)].textintval);
1970 #line 494 "parse-datetime.y"
1972 pc->day = (yyvsp[(1) - (2)].textintval).value;
1973 pc->month = (yyvsp[(2) - (2)].intval);
1978 #line 499 "parse-datetime.y"
1980 pc->day = (yyvsp[(1) - (3)].textintval).value;
1981 pc->month = (yyvsp[(2) - (3)].intval);
1982 pc->year = (yyvsp[(3) - (3)].textintval);
1987 #line 508 "parse-datetime.y"
1988 { apply_relative_time (pc, (yyvsp[(1) - (2)].rel), -1); }
1992 #line 510 "parse-datetime.y"
1993 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
1997 #line 512 "parse-datetime.y"
1998 { apply_relative_time (pc, (yyvsp[(1) - (1)].rel), 1); }
2002 #line 517 "parse-datetime.y"
2003 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].intval); }
2007 #line 519 "parse-datetime.y"
2008 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2012 #line 521 "parse-datetime.y"
2013 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = 1; }
2017 #line 523 "parse-datetime.y"
2018 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].intval); }
2022 #line 525 "parse-datetime.y"
2023 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2027 #line 527 "parse-datetime.y"
2028 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = 1; }
2032 #line 529 "parse-datetime.y"
2033 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].intval) * (yyvsp[(2) - (2)].intval); }
2037 #line 531 "parse-datetime.y"
2038 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2042 #line 533 "parse-datetime.y"
2043 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2047 #line 535 "parse-datetime.y"
2048 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].intval); }
2052 #line 537 "parse-datetime.y"
2053 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2057 #line 539 "parse-datetime.y"
2058 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = 1; }
2062 #line 541 "parse-datetime.y"
2063 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].intval); }
2067 #line 543 "parse-datetime.y"
2068 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2072 #line 545 "parse-datetime.y"
2073 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = 1; }
2077 #line 547 "parse-datetime.y"
2078 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].intval); }
2082 #line 549 "parse-datetime.y"
2083 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2087 #line 551 "parse-datetime.y"
2088 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2092 #line 553 "parse-datetime.y"
2093 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].timespec).tv_sec; (yyval.rel).ns = (yyvsp[(1) - (2)].timespec).tv_nsec; }
2097 #line 555 "parse-datetime.y"
2098 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = 1; }
2102 #line 561 "parse-datetime.y"
2103 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).year = (yyvsp[(1) - (2)].textintval).value; }
2107 #line 563 "parse-datetime.y"
2108 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).month = (yyvsp[(1) - (2)].textintval).value; }
2112 #line 565 "parse-datetime.y"
2113 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (2)].textintval).value * (yyvsp[(2) - (2)].intval); }
2117 #line 567 "parse-datetime.y"
2118 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).hour = (yyvsp[(1) - (2)].textintval).value; }
2122 #line 569 "parse-datetime.y"
2123 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).minutes = (yyvsp[(1) - (2)].textintval).value; }
2127 #line 571 "parse-datetime.y"
2128 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).seconds = (yyvsp[(1) - (2)].textintval).value; }
2132 #line 576 "parse-datetime.y"
2133 { (yyval.rel) = RELATIVE_TIME_0; (yyval.rel).day = (yyvsp[(1) - (1)].intval); }
2137 #line 584 "parse-datetime.y"
2138 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2142 #line 590 "parse-datetime.y"
2143 { (yyval.timespec).tv_sec = (yyvsp[(1) - (1)].textintval).value; (yyval.timespec).tv_nsec = 0; }
2147 #line 595 "parse-datetime.y"
2148 { digits_to_date_time (pc, (yyvsp[(1) - (1)].textintval)); }
2152 #line 600 "parse-datetime.y"
2154 /* Hybrid all-digit and relative offset, so that we accept e.g.,
2155 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */
2156 digits_to_date_time (pc, (yyvsp[(1) - (2)].textintval));
2157 apply_relative_time (pc, (yyvsp[(2) - (2)].rel), 1);
2162 #line 610 "parse-datetime.y"
2163 { (yyval.intval) = -1; }
2167 #line 612 "parse-datetime.y"
2168 { (yyval.intval) = (yyvsp[(2) - (2)].textintval).value; }
2172 #line 617 "parse-datetime.y"
2173 { (yyval.intval) = MER24; }
2177 #line 619 "parse-datetime.y"
2178 { (yyval.intval) = (yyvsp[(1) - (1)].intval); }
2182 /* Line 1267 of yacc.c. */
2183 #line 2184 "parse-datetime.c"
2186 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2190 YY_STACK_PRINT (yyss, yyssp);
2195 /* Now `shift' the result of the reduction. Determine what state
2196 that goes to, based on the state we popped back to and the rule
2197 number reduced by. */
2201 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2202 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2203 yystate = yytable[yystate];
2205 yystate = yydefgoto[yyn - YYNTOKENS];
2210 /*------------------------------------.
2211 | yyerrlab -- here on detecting error |
2212 `------------------------------------*/
2214 /* If not already recovering from an error, report this error. */
2218 #if ! YYERROR_VERBOSE
2219 yyerror (pc, YY_("syntax error"));
2222 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2223 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2225 YYSIZE_T yyalloc = 2 * yysize;
2226 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2227 yyalloc = YYSTACK_ALLOC_MAXIMUM;
2228 if (yymsg != yymsgbuf)
2229 YYSTACK_FREE (yymsg);
2230 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2232 yymsg_alloc = yyalloc;
2236 yymsg_alloc = sizeof yymsgbuf;
2240 if (0 < yysize && yysize <= yymsg_alloc)
2242 (void) yysyntax_error (yymsg, yystate, yychar);
2243 yyerror (pc, yymsg);
2247 yyerror (pc, YY_("syntax error"));
2249 goto yyexhaustedlab;
2257 if (yyerrstatus == 3)
2259 /* If just tried and failed to reuse look-ahead token after an
2260 error, discard it. */
2262 if (yychar <= YYEOF)
2264 /* Return failure if at end of input. */
2265 if (yychar == YYEOF)
2270 yydestruct ("Error: discarding",
2271 yytoken, &yylval, pc);
2276 /* Else will try to reuse look-ahead token after shifting the error
2281 /*---------------------------------------------------.
2282 | yyerrorlab -- error raised explicitly by YYERROR. |
2283 `---------------------------------------------------*/
2286 /* Pacify compilers like GCC when the user code never invokes
2287 YYERROR and the label yyerrorlab therefore never appears in user
2289 if (/*CONSTCOND*/ 0)
2292 /* Do not reclaim the symbols of the rule which action triggered
2296 YY_STACK_PRINT (yyss, yyssp);
2301 /*-------------------------------------------------------------.
2302 | yyerrlab1 -- common code for both syntax error and YYERROR. |
2303 `-------------------------------------------------------------*/
2305 yyerrstatus = 3; /* Each real token shifted decrements this. */
2309 yyn = yypact[yystate];
2310 if (yyn != YYPACT_NINF)
2313 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2321 /* Pop the current state because it cannot handle the error token. */
2326 yydestruct ("Error: popping",
2327 yystos[yystate], yyvsp, pc);
2330 YY_STACK_PRINT (yyss, yyssp);
2339 /* Shift the error token. */
2340 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2346 /*-------------------------------------.
2347 | yyacceptlab -- YYACCEPT comes here. |
2348 `-------------------------------------*/
2353 /*-----------------------------------.
2354 | yyabortlab -- YYABORT comes here. |
2355 `-----------------------------------*/
2361 /*-------------------------------------------------.
2362 | yyexhaustedlab -- memory exhaustion comes here. |
2363 `-------------------------------------------------*/
2365 yyerror (pc, YY_("memory exhausted"));
2371 if (yychar != YYEOF && yychar != YYEMPTY)
2372 yydestruct ("Cleanup: discarding lookahead",
2373 yytoken, &yylval, pc);
2374 /* Do not reclaim the symbols of the rule which action triggered
2375 this YYABORT or YYACCEPT. */
2377 YY_STACK_PRINT (yyss, yyssp);
2378 while (yyssp != yyss)
2380 yydestruct ("Cleanup: popping",
2381 yystos[*yyssp], yyvsp, pc);
2386 YYSTACK_FREE (yyss);
2389 if (yymsg != yymsgbuf)
2390 YYSTACK_FREE (yymsg);
2392 /* Make sure YYID is used. */
2393 return YYID (yyresult);
2397 #line 622 "parse-datetime.y"
2400 static table const meridian_table[] =
2402 { "AM", tMERIDIAN, MERam },
2403 { "A.M.", tMERIDIAN, MERam },
2404 { "PM", tMERIDIAN, MERpm },
2405 { "P.M.", tMERIDIAN, MERpm },
2409 static table const dst_table[] =
2414 static table const month_and_day_table[] =
2416 { "JANUARY", tMONTH, 1 },
2417 { "FEBRUARY", tMONTH, 2 },
2418 { "MARCH", tMONTH, 3 },
2419 { "APRIL", tMONTH, 4 },
2420 { "MAY", tMONTH, 5 },
2421 { "JUNE", tMONTH, 6 },
2422 { "JULY", tMONTH, 7 },
2423 { "AUGUST", tMONTH, 8 },
2424 { "SEPTEMBER",tMONTH, 9 },
2425 { "SEPT", tMONTH, 9 },
2426 { "OCTOBER", tMONTH, 10 },
2427 { "NOVEMBER", tMONTH, 11 },
2428 { "DECEMBER", tMONTH, 12 },
2429 { "SUNDAY", tDAY, 0 },
2430 { "MONDAY", tDAY, 1 },
2431 { "TUESDAY", tDAY, 2 },
2432 { "TUES", tDAY, 2 },
2433 { "WEDNESDAY",tDAY, 3 },
2434 { "WEDNES", tDAY, 3 },
2435 { "THURSDAY", tDAY, 4 },
2436 { "THUR", tDAY, 4 },
2437 { "THURS", tDAY, 4 },
2438 { "FRIDAY", tDAY, 5 },
2439 { "SATURDAY", tDAY, 6 },
2443 static table const time_units_table[] =
2445 { "YEAR", tYEAR_UNIT, 1 },
2446 { "MONTH", tMONTH_UNIT, 1 },
2447 { "FORTNIGHT",tDAY_UNIT, 14 },
2448 { "WEEK", tDAY_UNIT, 7 },
2449 { "DAY", tDAY_UNIT, 1 },
2450 { "HOUR", tHOUR_UNIT, 1 },
2451 { "MINUTE", tMINUTE_UNIT, 1 },
2452 { "MIN", tMINUTE_UNIT, 1 },
2453 { "SECOND", tSEC_UNIT, 1 },
2454 { "SEC", tSEC_UNIT, 1 },
2458 /* Assorted relative-time words. */
2459 static table const relative_time_table[] =
2461 { "TOMORROW", tDAY_SHIFT, 1 },
2462 { "YESTERDAY",tDAY_SHIFT, -1 },
2463 { "TODAY", tDAY_SHIFT, 0 },
2464 { "NOW", tDAY_SHIFT, 0 },
2465 { "LAST", tORDINAL, -1 },
2466 { "THIS", tORDINAL, 0 },
2467 { "NEXT", tORDINAL, 1 },
2468 { "FIRST", tORDINAL, 1 },
2469 /*{ "SECOND", tORDINAL, 2 }, */
2470 { "THIRD", tORDINAL, 3 },
2471 { "FOURTH", tORDINAL, 4 },
2472 { "FIFTH", tORDINAL, 5 },
2473 { "SIXTH", tORDINAL, 6 },
2474 { "SEVENTH", tORDINAL, 7 },
2475 { "EIGHTH", tORDINAL, 8 },
2476 { "NINTH", tORDINAL, 9 },
2477 { "TENTH", tORDINAL, 10 },
2478 { "ELEVENTH", tORDINAL, 11 },
2479 { "TWELFTH", tORDINAL, 12 },
2484 /* The universal time zone table. These labels can be used even for
2485 time stamps that would not otherwise be valid, e.g., GMT time
2486 stamps in London during summer. */
2487 static table const universal_time_zone_table[] =
2489 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
2490 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
2491 { "UTC", tZONE, HOUR ( 0) },
2495 /* The time zone table. This table is necessarily incomplete, as time
2496 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
2497 as Eastern time in Australia, not as US Eastern Standard Time.
2498 You cannot rely on parse_datetime to handle arbitrary time zone
2499 abbreviations; use numeric abbreviations like `-0500' instead. */
2500 static table const time_zone_table[] =
2502 { "WET", tZONE, HOUR ( 0) }, /* Western European */
2503 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
2504 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
2505 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
2506 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
2507 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
2508 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
2509 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
2510 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
2511 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
2512 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
2513 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
2514 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
2515 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
2516 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
2517 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
2518 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
2519 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
2520 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
2521 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
2522 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
2523 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
2524 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
2525 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
2526 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
2527 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
2528 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
2529 { "CET", tZONE, HOUR ( 1) }, /* Central European */
2530 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
2531 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
2532 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
2533 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2534 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
2535 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
2536 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
2537 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
2538 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
2539 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
2540 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
2541 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
2542 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
2543 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
2544 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
2545 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
2546 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
2547 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
2548 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
2552 /* Military time zone table. */
2553 static table const military_table[] =
2555 { "A", tZONE, -HOUR ( 1) },
2556 { "B", tZONE, -HOUR ( 2) },
2557 { "C", tZONE, -HOUR ( 3) },
2558 { "D", tZONE, -HOUR ( 4) },
2559 { "E", tZONE, -HOUR ( 5) },
2560 { "F", tZONE, -HOUR ( 6) },
2561 { "G", tZONE, -HOUR ( 7) },
2562 { "H", tZONE, -HOUR ( 8) },
2563 { "I", tZONE, -HOUR ( 9) },
2564 { "K", tZONE, -HOUR (10) },
2565 { "L", tZONE, -HOUR (11) },
2566 { "M", tZONE, -HOUR (12) },
2567 { "N", tZONE, HOUR ( 1) },
2568 { "O", tZONE, HOUR ( 2) },
2569 { "P", tZONE, HOUR ( 3) },
2570 { "Q", tZONE, HOUR ( 4) },
2571 { "R", tZONE, HOUR ( 5) },
2572 { "S", tZONE, HOUR ( 6) },
2573 { "T", tZONE, HOUR ( 7) },
2574 { "U", tZONE, HOUR ( 8) },
2575 { "V", tZONE, HOUR ( 9) },
2576 { "W", tZONE, HOUR (10) },
2577 { "X", tZONE, HOUR (11) },
2578 { "Y", tZONE, HOUR (12) },
2579 { "Z", tZONE, HOUR ( 0) },
2585 /* Convert a time zone expressed as HH:MM into an integer count of
2586 minutes. If MM is negative, then S is of the form HHMM and needs
2587 to be picked apart; otherwise, S is of the form HH. As specified in
2588 http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow
2589 only valid TZ range, and consider first two digits as hours, if no
2590 minutes specified. */
2593 time_zone_hhmm (parser_control *pc, textint s, long int mm)
2597 /* If the length of S is 1 or 2 and no minutes are specified,
2598 interpret it as a number of hours. */
2599 if (s.digits <= 2 && mm < 0)
2603 n_minutes = (s.value / 100) * 60 + s.value % 100;
2605 n_minutes = s.value * 60 + (s.negative ? -mm : mm);
2607 /* If the absolute number of minutes is larger than 24 hours,
2608 arrange to reject it by incrementing pc->zones_seen. Thus,
2609 we allow only values in the range UTC-24:00 to UTC+24:00. */
2610 if (24 * 60 < abs (n_minutes))
2617 to_hour (long int hours, int meridian)
2621 default: /* Pacify GCC. */
2623 return 0 <= hours && hours < 24 ? hours : -1;
2625 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
2627 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
2632 to_year (textint textyear)
2634 long int year = textyear.value;
2639 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2640 years 69-99 map to 1969-1999. */
2641 else if (textyear.digits == 2)
2642 year += year < 69 ? 2000 : 1900;
2647 static table const *
2648 lookup_zone (parser_control const *pc, char const *name)
2652 for (tp = universal_time_zone_table; tp->name; tp++)
2653 if (strcmp (name, tp->name) == 0)
2656 /* Try local zone abbreviations before those in time_zone_table, as
2657 the local ones are more likely to be right. */
2658 for (tp = pc->local_time_zone_table; tp->name; tp++)
2659 if (strcmp (name, tp->name) == 0)
2662 for (tp = time_zone_table; tp->name; tp++)
2663 if (strcmp (name, tp->name) == 0)
2669 #if ! HAVE_TM_GMTOFF
2670 /* Yield the difference between *A and *B,
2671 measured in seconds, ignoring leap seconds.
2672 The body of this function is taken directly from the GNU C Library;
2673 see src/strftime.c. */
2675 tm_diff (struct tm const *a, struct tm const *b)
2677 /* Compute intervening leap days correctly even if year is negative.
2678 Take care to avoid int overflow in leap day calculations. */
2679 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
2680 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2681 int a100 = a4 / 25 - (a4 % 25 < 0);
2682 int b100 = b4 / 25 - (b4 % 25 < 0);
2683 int a400 = SHR (a100, 2);
2684 int b400 = SHR (b100, 2);
2685 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
2686 long int ayear = a->tm_year;
2687 long int years = ayear - b->tm_year;
2688 long int days = (365 * years + intervening_leap_days
2689 + (a->tm_yday - b->tm_yday));
2690 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
2691 + (a->tm_min - b->tm_min))
2692 + (a->tm_sec - b->tm_sec));
2694 #endif /* ! HAVE_TM_GMTOFF */
2696 static table const *
2697 lookup_word (parser_control const *pc, char *word)
2706 /* Make it uppercase. */
2707 for (p = word; *p; p++)
2709 unsigned char ch = *p;
2710 *p = c_toupper (ch);
2713 for (tp = meridian_table; tp->name; tp++)
2714 if (strcmp (word, tp->name) == 0)
2717 /* See if we have an abbreviation for a month. */
2718 wordlen = strlen (word);
2719 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
2721 for (tp = month_and_day_table; tp->name; tp++)
2722 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
2725 if ((tp = lookup_zone (pc, word)))
2728 if (strcmp (word, dst_table[0].name) == 0)
2731 for (tp = time_units_table; tp->name; tp++)
2732 if (strcmp (word, tp->name) == 0)
2735 /* Strip off any plural and try the units table again. */
2736 if (word[wordlen - 1] == 'S')
2738 word[wordlen - 1] = '\0';
2739 for (tp = time_units_table; tp->name; tp++)
2740 if (strcmp (word, tp->name) == 0)
2742 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
2745 for (tp = relative_time_table; tp->name; tp++)
2746 if (strcmp (word, tp->name) == 0)
2749 /* Military time zones. */
2751 for (tp = military_table; tp->name; tp++)
2752 if (word[0] == tp->name[0])
2755 /* Drop out any periods and try the time zone table again. */
2756 for (period_found = false, p = q = word; (*p = *q); q++)
2758 period_found = true;
2761 if (period_found && (tp = lookup_zone (pc, word)))
2768 yylex (YYSTYPE *lvalp, parser_control *pc)
2775 while (c = *pc->input, c_isspace (c))
2778 if (ISDIGIT (c) || c == '-' || c == '+')
2782 unsigned long int value;
2783 if (c == '-' || c == '+')
2785 sign = c == '-' ? -1 : 1;
2786 while (c = *++pc->input, c_isspace (c))
2789 /* skip the '-' sign */
2795 for (value = 0; ; value *= 10)
2797 unsigned long int value1 = value + (c - '0');
2804 if (ULONG_MAX / 10 < value)
2807 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
2812 unsigned long int value1;
2814 /* Check for overflow when converting value to time_t. */
2829 if (value != value1)
2832 /* Accumulate fraction, to ns precision. */
2835 for (digits = 2; digits <= LOG10_BILLION; digits++)
2842 /* Skip excess digits, truncating toward -Infinity. */
2844 for (; ISDIGIT (*p); p++)
2850 while (ISDIGIT (*p))
2853 /* Adjust to the timespec convention, which is that
2854 tv_nsec is always a positive offset even if tv_sec is
2864 lvalp->timespec.tv_sec = s;
2865 lvalp->timespec.tv_nsec = ns;
2867 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
2871 lvalp->textintval.negative = sign < 0;
2874 lvalp->textintval.value = - value;
2875 if (0 < lvalp->textintval.value)
2880 lvalp->textintval.value = value;
2881 if (lvalp->textintval.value < 0)
2884 lvalp->textintval.digits = p - pc->input;
2886 return sign ? tSNUMBER : tUNUMBER;
2898 if (p < buff + sizeof buff - 1)
2902 while (c_isalpha (c) || c == '.');
2905 tp = lookup_word (pc, buff);
2908 lvalp->intval = tp->value;
2913 return *pc->input++;
2929 /* Do nothing if the parser reports an error. */
2931 yyerror (parser_control const *pc _GL_UNUSED,
2932 char const *s _GL_UNUSED)
2937 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
2938 passing it to mktime, return true if it's OK that mktime returned T.
2939 It's not OK if *TM0 has out-of-range members. */
2942 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
2944 if (t == (time_t) -1)
2946 /* Guard against falsely reporting an error when parsing a time
2947 stamp that happens to equal (time_t) -1, on a host that
2948 supports such a time stamp. */
2949 tm1 = localtime (&t);
2954 return ! ((tm0->tm_sec ^ tm1->tm_sec)
2955 | (tm0->tm_min ^ tm1->tm_min)
2956 | (tm0->tm_hour ^ tm1->tm_hour)
2957 | (tm0->tm_mday ^ tm1->tm_mday)
2958 | (tm0->tm_mon ^ tm1->tm_mon)
2959 | (tm0->tm_year ^ tm1->tm_year));
2962 /* A reasonable upper bound for the size of ordinary TZ strings.
2963 Use heap allocation if TZ's length exceeds this. */
2964 enum { TZBUFSIZE = 100 };
2966 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
2969 get_tz (char tzbuf[TZBUFSIZE])
2971 char *tz = getenv ("TZ");
2974 size_t tzsize = strlen (tz) + 1;
2975 tz = (tzsize <= TZBUFSIZE
2976 ? memcpy (tzbuf, tz, tzsize)
2977 : xmemdup (tz, tzsize));
2982 /* Parse a date/time string, storing the resulting time value into *RESULT.
2983 The string itself is pointed to by P. Return true if successful.
2984 P can be an incomplete or relative time specification; if so, use
2985 *NOW as the basis for the returned time. */
2987 parse_datetime (struct timespec *result, char const *p,
2988 struct timespec const *now)
2992 struct tm const *tmp;
2996 struct timespec gettime_buffer;
2998 bool tz_was_altered = false;
3000 char tz0buf[TZBUFSIZE];
3005 gettime (&gettime_buffer);
3006 now = &gettime_buffer;
3009 Start = now->tv_sec;
3010 Start_ns = now->tv_nsec;
3012 tmp = localtime (&now->tv_sec);
3016 while (c = *p, c_isspace (c))
3019 if (strncmp (p, "TZ=\"", 4) == 0)
3021 char const *tzbase = p + 4;
3025 for (s = tzbase; *s; s++, tzsize++)
3029 if (! (*s == '\\' || *s == '"'))
3036 char tz1buf[TZBUFSIZE];
3037 bool large_tz = TZBUFSIZE < tzsize;
3039 /* Free tz0, in case this is the 2nd or subsequent time through. */
3041 tz0 = get_tz (tz0buf);
3042 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
3043 for (s = tzbase; *s != '"'; s++)
3044 *z++ = *(s += *s == '\\');
3046 setenv_ok = setenv ("TZ", tz1, 1) == 0;
3051 tz_was_altered = true;
3056 /* As documented, be careful to treat the empty string just like
3057 a date string of "0". Without this, an empty string would be
3058 declared invalid when parsed during a DST transition. */
3063 pc.year.value = tmp->tm_year;
3064 pc.year.value += TM_YEAR_BASE;
3066 pc.month = tmp->tm_mon + 1;
3067 pc.day = tmp->tm_mday;
3068 pc.hour = tmp->tm_hour;
3069 pc.minutes = tmp->tm_min;
3070 pc.seconds.tv_sec = tmp->tm_sec;
3071 pc.seconds.tv_nsec = Start_ns;
3072 tm.tm_isdst = tmp->tm_isdst;
3074 pc.meridian = MER24;
3075 pc.rel = RELATIVE_TIME_0;
3076 pc.timespec_seen = false;
3077 pc.rels_seen = false;
3081 pc.local_zones_seen = 0;
3085 #if HAVE_STRUCT_TM_TM_ZONE
3086 pc.local_time_zone_table[0].name = tmp->tm_zone;
3087 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3088 pc.local_time_zone_table[0].value = tmp->tm_isdst;
3089 pc.local_time_zone_table[1].name = NULL;
3091 /* Probe the names used in the next three calendar quarters, looking
3092 for a tm_isdst different from the one we already have. */
3095 for (quarter = 1; quarter <= 3; quarter++)
3097 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
3098 struct tm const *probe_tm = localtime (&probe);
3099 if (probe_tm && probe_tm->tm_zone
3100 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
3103 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
3104 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
3105 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
3106 pc.local_time_zone_table[2].name = NULL;
3115 # if !HAVE_DECL_TZNAME
3116 extern char *tzname[];
3119 for (i = 0; i < 2; i++)
3121 pc.local_time_zone_table[i].name = tzname[i];
3122 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3123 pc.local_time_zone_table[i].value = i;
3125 pc.local_time_zone_table[i].name = NULL;
3128 pc.local_time_zone_table[0].name = NULL;
3132 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3133 && ! strcmp (pc.local_time_zone_table[0].name,
3134 pc.local_time_zone_table[1].name))
3136 /* This locale uses the same abbrevation for standard and
3137 daylight times. So if we see that abbreviation, we don't
3138 know whether it's daylight time. */
3139 pc.local_time_zone_table[0].value = -1;
3140 pc.local_time_zone_table[1].name = NULL;
3143 if (yyparse (&pc) != 0)
3146 if (pc.timespec_seen)
3147 *result = pc.seconds;
3150 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
3151 | (pc.local_zones_seen + pc.zones_seen)))
3154 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
3155 tm.tm_mon = pc.month - 1;
3156 tm.tm_mday = pc.day;
3157 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
3159 tm.tm_hour = to_hour (pc.hour, pc.meridian);
3162 tm.tm_min = pc.minutes;
3163 tm.tm_sec = pc.seconds.tv_sec;
3167 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
3168 pc.seconds.tv_nsec = 0;
3171 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
3172 if (pc.dates_seen | pc.days_seen | pc.times_seen)
3175 /* But if the input explicitly specifies local time with or without
3176 DST, give mktime that information. */
3177 if (pc.local_zones_seen)
3178 tm.tm_isdst = pc.local_isdst;
3182 Start = mktime (&tm);
3184 if (! mktime_ok (&tm0, &tm, Start))
3186 if (! pc.zones_seen)
3190 /* Guard against falsely reporting errors near the time_t
3191 boundaries when parsing times in other time zones. For
3192 example, suppose the input string "1969-12-31 23:00:00 -0100",
3193 the current time zone is 8 hours ahead of UTC, and the min
3194 time_t value is 1970-01-01 00:00:00 UTC. Then the min
3195 localtime value is 1970-01-01 08:00:00, and mktime will
3196 therefore fail on 1969-12-31 23:00:00. To work around the
3197 problem, set the time zone to 1 hour behind UTC temporarily
3198 by setting TZ="XXX1:00" and try mktime again. */
3200 long int time_zone = pc.time_zone;
3201 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
3202 long int abs_time_zone_hour = abs_time_zone / 60;
3203 int abs_time_zone_min = abs_time_zone % 60;
3204 char tz1buf[sizeof "XXX+0:00"
3205 + sizeof pc.time_zone * CHAR_BIT / 3];
3206 if (!tz_was_altered)
3207 tz0 = get_tz (tz0buf);
3208 sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0),
3209 abs_time_zone_hour, abs_time_zone_min);
3210 if (setenv ("TZ", tz1buf, 1) != 0)
3212 tz_was_altered = true;
3214 Start = mktime (&tm);
3215 if (! mktime_ok (&tm0, &tm, Start))
3220 if (pc.days_seen && ! pc.dates_seen)
3222 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
3223 + 7 * (pc.day_ordinal
3224 - (0 < pc.day_ordinal
3225 && tm.tm_wday != pc.day_number)));
3227 Start = mktime (&tm);
3228 if (Start == (time_t) -1)
3232 /* Add relative date. */
3233 if (pc.rel.year | pc.rel.month | pc.rel.day)
3235 int year = tm.tm_year + pc.rel.year;
3236 int month = tm.tm_mon + pc.rel.month;
3237 int day = tm.tm_mday + pc.rel.day;
3238 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
3239 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
3240 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
3245 tm.tm_hour = tm0.tm_hour;
3246 tm.tm_min = tm0.tm_min;
3247 tm.tm_sec = tm0.tm_sec;
3248 tm.tm_isdst = tm0.tm_isdst;
3249 Start = mktime (&tm);
3250 if (Start == (time_t) -1)
3254 /* The only "output" of this if-block is an updated Start value,
3255 so this block must follow others that clobber Start. */
3258 long int delta = pc.time_zone * 60;
3260 #ifdef HAVE_TM_GMTOFF
3261 delta -= tm.tm_gmtoff;
3264 struct tm const *gmt = gmtime (&t);
3267 delta -= tm_diff (&tm, gmt);
3270 if ((Start < t1) != (delta < 0))
3271 goto fail; /* time_t overflow */
3275 /* Add relative hours, minutes, and seconds. On hosts that support
3276 leap seconds, ignore the possibility of leap seconds; e.g.,
3277 "+ 10 minutes" adds 600 seconds, even if one of them is a
3278 leap second. Typically this is not what the user wants, but it's
3279 too hard to do it the other way, because the time zone indicator
3280 must be applied before relative times, and if mktime is applied
3281 again the time zone will be lost. */
3283 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
3284 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
3286 long int d1 = 60 * 60 * pc.rel.hour;
3287 time_t t1 = t0 + d1;
3288 long int d2 = 60 * pc.rel.minutes;
3289 time_t t2 = t1 + d2;
3290 long_time_t d3 = pc.rel.seconds;
3291 long_time_t t3 = t2 + d3;
3292 long int d4 = (sum_ns - normalized_ns) / BILLION;
3293 long_time_t t4 = t3 + d4;
3296 if ((d1 / (60 * 60) ^ pc.rel.hour)
3297 | (d2 / 60 ^ pc.rel.minutes)
3298 | ((t1 < t0) ^ (d1 < 0))
3299 | ((t2 < t1) ^ (d2 < 0))
3300 | ((t3 < t2) ^ (d3 < 0))
3301 | ((t4 < t3) ^ (d4 < 0))
3305 result->tv_sec = t5;
3306 result->tv_nsec = normalized_ns;
3316 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
3325 main (int ac, char **av)
3329 printf ("Enter date, or blank line to exit.\n\t> ");
3332 buff[BUFSIZ - 1] = '\0';
3333 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
3336 struct tm const *tm;
3337 if (! parse_datetime (&d, buff, NULL))
3338 printf ("Bad format - couldn't convert.\n");
3339 else if (! (tm = localtime (&d.tv_sec)))
3341 long int sec = d.tv_sec;
3342 printf ("localtime (%ld) failed\n", sec);
3347 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
3348 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
3349 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);