annotate lib/getdate.y @ 10531:e83a90adf243

Override fopen more carefully.
author Bruno Haible <bruno@clisp.org>
date Sun, 28 Sep 2008 16:12:20 +0200
parents c640552acc85
children 3adf94551b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1 %{
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
2 /* Parse a string into an internal time stamp.
5662
42df9db003cc * modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5548
diff changeset
3
10256
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
4 Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
5 Free Software Foundation, Inc.
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
6
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8987
diff changeset
7 This program is free software: you can redistribute it and/or modify
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
8 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8987
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8987
diff changeset
10 (at your option) any later version.
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
11
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
12 This program is distributed in the hope that it will be useful,
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
15 GNU General Public License for more details.
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
16
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
17 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8987
diff changeset
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
19
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
20 /* Originally written by Steven M. Bellovin <smb@research.att.com> while
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
21 at the University of North Carolina at Chapel Hill. Later tweaked by
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
22 a couple of people on Usenet. Completely overhauled by Rich $alz
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
23 <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
24
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
25 Modified by Paul Eggert <eggert@twinsun.com> in August 1999 to do
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
26 the right thing about local DST. Also modified by Paul Eggert
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
27 <eggert@cs.ucla.edu> in February 2004 to support
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
28 nanosecond-resolution time stamps, and in October 2004 to support
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
29 TZ strings in dates. */
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
30
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
31 /* FIXME: Check for arithmetic overflow in all cases, not just
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
32 some of them. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
33
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6932
diff changeset
34 #include <config.h>
48
e5f368fdc8c2 update from fsf
Jim Meyering <jim@meyering.net>
parents: 16
diff changeset
35
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
36 #include "getdate.h"
8987
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
37
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
38 #include "intprops.h"
8223
ca249819379f * lib/getdate.h (includes): Include <time.h>, not "timespec.h".
Eric Blake <ebb9@byu.net>
parents: 7558
diff changeset
39 #include "timespec.h"
8987
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
40 #include "verify.h"
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
41
5548
b8dd75cdd3a8 (YYSTACK_USE_ALLOCA): Define to 0, since there's no need to extend the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5546
diff changeset
42 /* There's no need to extend the stack, so there's no need to involve
b8dd75cdd3a8 (YYSTACK_USE_ALLOCA): Define to 0, since there's no need to extend the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5546
diff changeset
43 alloca. */
b8dd75cdd3a8 (YYSTACK_USE_ALLOCA): Define to 0, since there's no need to extend the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5546
diff changeset
44 #define YYSTACK_USE_ALLOCA 0
5538
87bc9c0d52d4 * alloca_.h: Conditionalize on _GNULIB_ALLOCA_H, not _ALLOCA_H.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5520
diff changeset
45
5543
96b72280d322 Fix typo in comment in previous change.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5538
diff changeset
46 /* Tell Bison how much stack space is needed. 20 should be plenty for
5538
87bc9c0d52d4 * alloca_.h: Conditionalize on _GNULIB_ALLOCA_H, not _ALLOCA_H.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5520
diff changeset
47 this grammar, which is not right recursive. Beware setting it too
5548
b8dd75cdd3a8 (YYSTACK_USE_ALLOCA): Define to 0, since there's no need to extend the
Paul Eggert <eggert@cs.ucla.edu>
parents: 5546
diff changeset
48 high, since that might cause problems on machines whose
5538
87bc9c0d52d4 * alloca_.h: Conditionalize on _GNULIB_ALLOCA_H, not _ALLOCA_H.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5520
diff changeset
49 implementations have lame stack-overflow checking. */
87bc9c0d52d4 * alloca_.h: Conditionalize on _GNULIB_ALLOCA_H, not _ALLOCA_H.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5520
diff changeset
50 #define YYMAXDEPTH 20
5546
b45cd12ab00f (YYINITDEPTH): New macro, so that the initial stack is small too.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5543
diff changeset
51 #define YYINITDEPTH YYMAXDEPTH
4156
99ea86c79f44 Make it possibly to simply write: #include <alloca.h>.
Bruno Haible <bruno@clisp.org>
parents: 4102
diff changeset
52
100
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
53 /* Since the code of getdate.y is not included in the Emacs executable
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
54 itself, there is no need to #define static in this file. Even if
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
55 the code were included in the Emacs executable, it probably
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
56 wouldn't do any harm to #undef it here; this will only cause
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
57 problems if we try to write to a static variable, which I don't
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
58 think this code needs to do. */
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
59 #ifdef emacs
855
9c89b90524b8 (get_date): Change prototype to reflect const'ness of parameters.
Jim Meyering <jim@meyering.net>
parents: 852
diff changeset
60 # undef static
100
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
61 #endif
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
62
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
63 #include <c-ctype.h>
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
64 #include <limits.h>
5382
72833e3704a0 * getdate.y [!TEST]: Include <stdio.h>, since we use sprintf now.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5373
diff changeset
65 #include <stdio.h>
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
66 #include <stdlib.h>
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
67 #include <string.h>
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
68
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
69 #include "xalloc.h"
1785
197f4bdf9a3d <stdlib.h>: Include if HAVE_STDLIB_H, since bison 1.27 invokes "free".
Jim Meyering <jim@meyering.net>
parents: 1777
diff changeset
70
814
3976dc4f68dd add blank line.
Jim Meyering <jim@meyering.net>
parents: 811
diff changeset
71
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
72 /* ISDIGIT differs from isdigit, as follows:
6932
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6927
diff changeset
73 - Its arg may be any int or unsigned int; it need not be an unsigned char
6aeb4d6c28d9 * lib/.cppi-disable: Add wcwidth.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6927
diff changeset
74 or EOF.
811
193f7d202848 (IN_CTYPE_DOMAIN): Rename from ISASCII.
Jim Meyering <jim@meyering.net>
parents: 805
diff changeset
75 - It's typically faster.
3697
cdfc99b9cf86 (ISDIGIT): Comment fix.
Jim Meyering <jim@meyering.net>
parents: 3618
diff changeset
76 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
77 isdigit unless it's important to use the locale's definition
3697
cdfc99b9cf86 (ISDIGIT): Comment fix.
Jim Meyering <jim@meyering.net>
parents: 3618
diff changeset
78 of `digit' even when the host does not conform to POSIX. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
79 #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
688
cc4dbb9f5f58 Define and use upper case variants of ctype.h IS* macros.
Jim Meyering <jim@meyering.net>
parents: 562
diff changeset
80
6819
3449832bdc37 * getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6755
diff changeset
81 #ifndef __attribute__
3449832bdc37 * getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6755
diff changeset
82 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
3449832bdc37 * getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6755
diff changeset
83 # define __attribute__(x)
3449832bdc37 * getdate.y (__attribute__): Don't define if already defined.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6755
diff changeset
84 # endif
1584
0f1daf1810b4 Fix warnings from gcc -W -Wall
Jim Meyering <jim@meyering.net>
parents: 1265
diff changeset
85 #endif
0f1daf1810b4 Fix warnings from gcc -W -Wall
Jim Meyering <jim@meyering.net>
parents: 1265
diff changeset
86
0f1daf1810b4 Fix warnings from gcc -W -Wall
Jim Meyering <jim@meyering.net>
parents: 1265
diff changeset
87 #ifndef ATTRIBUTE_UNUSED
0f1daf1810b4 Fix warnings from gcc -W -Wall
Jim Meyering <jim@meyering.net>
parents: 1265
diff changeset
88 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
0f1daf1810b4 Fix warnings from gcc -W -Wall
Jim Meyering <jim@meyering.net>
parents: 1265
diff changeset
89 #endif
0f1daf1810b4 Fix warnings from gcc -W -Wall
Jim Meyering <jim@meyering.net>
parents: 1265
diff changeset
90
5414
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
91 /* Shift A right by B bits portably, by dividing A by 2**B and
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
92 truncating towards minus infinity. A and B should be free of side
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
93 effects, and B should be in the range 0 <= B <= INT_BITS - 2, where
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
94 INT_BITS is the number of useful bits in an int. GNU code can
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
95 assume that INT_BITS is at least 32.
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
96
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
97 ISO C99 says that A >> B is implementation-defined if A < 0. Some
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
98 implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
99 right in the usual way when A < 0, so SHR falls back on division if
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
100 ordinary A >> B doesn't seem to be the usual signed shift. */
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
101 #define SHR(a, b) \
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
102 (-1 >> 1 == -1 \
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
103 ? (a) >> (b) \
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
104 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
105
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
106 #define EPOCH_YEAR 1970
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
107 #define TM_YEAR_BASE 1900
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
108
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
109 #define HOUR(x) ((x) * 60)
2588
17f2ecbac01c (get_date): Apply relative times after time zone indicator, not before.
Jim Meyering <jim@meyering.net>
parents: 2280
diff changeset
110
8987
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
111 /* Lots of this code assumes time_t and time_t-like values fit into
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
112 long int. It also assumes that signed integer overflow silently
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
113 wraps around, but there's no portable way to check for that at
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
114 compile-time. */
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
115 verify (TYPE_IS_INTEGER (time_t));
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
116 verify (LONG_MIN <= TYPE_MINIMUM (time_t) && TYPE_MAXIMUM (time_t) <= LONG_MAX);
9d7e51011293 Detect porting problems to FreeBSD/arm, which has time_t wider than
Paul Eggert <eggert@cs.ucla.edu>
parents: 8223
diff changeset
117
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
118 /* An integer value, and the number of digits in its textual
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
119 representation. */
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
120 typedef struct
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
121 {
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
122 bool negative;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
123 long int value;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
124 size_t digits;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
125 } textint;
100
4d645beabfa4 merge with 1.8.1 + partial --version and --help
Jim Meyering <jim@meyering.net>
parents: 49
diff changeset
126
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
127 /* An entry in the lexical lookup table. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
128 typedef struct
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
129 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
130 char const *name;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
131 int type;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
132 int value;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
133 } table;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
134
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
135 /* Meridian: am, pm, or 24-hour style. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
136 enum { MERam, MERpm, MER24 };
769
c906850e724f Remap yacc globals to have gd_ prefix.
Jim Meyering <jim@meyering.net>
parents: 688
diff changeset
137
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
138 enum { BILLION = 1000000000, LOG10_BILLION = 9 };
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
139
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
140 /* Relative times. */
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
141 typedef struct
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
142 {
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
143 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
144 long int year;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
145 long int month;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
146 long int day;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
147 long int hour;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
148 long int minutes;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
149 long int seconds;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
150 long int ns;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
151 } relative_time;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
152
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
153 #if HAVE_COMPOUND_LITERALS
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
154 # define RELATIVE_TIME_0 ((relative_time) { 0, 0, 0, 0, 0, 0, 0 })
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
155 #else
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
156 static relative_time const RELATIVE_TIME_0;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
157 #endif
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
158
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
159 /* Information passed to and from the parser. */
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
160 typedef struct
2047
626ebcce50a3 (get_date): Fix typo in time_t overflow test.
Jim Meyering <jim@meyering.net>
parents: 1986
diff changeset
161 {
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
162 /* The input string remaining to be parsed. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
163 const char *input;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
164
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
165 /* N, if this is the Nth Tuesday. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
166 long int day_ordinal;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
167
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
168 /* Day of week; Sunday is 0. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
169 int day_number;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
170
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
171 /* tm_isdst flag for the local zone. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
172 int local_isdst;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
173
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
174 /* Time zone, in minutes east of UTC. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
175 long int time_zone;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
176
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
177 /* Style used for time. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
178 int meridian;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
179
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
180 /* Gregorian year, month, day, hour, minutes, seconds, and nanoseconds. */
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
181 textint year;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
182 long int month;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
183 long int day;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
184 long int hour;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
185 long int minutes;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
186 struct timespec seconds; /* includes nanoseconds */
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
187
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
188 /* Relative year, month, day, hour, minutes, seconds, and nanoseconds. */
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
189 relative_time rel;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
190
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
191 /* Presence or counts of nonterminals of various flavors parsed so far. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
192 bool timespec_seen;
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
193 bool rels_seen;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
194 size_t dates_seen;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
195 size_t days_seen;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
196 size_t local_zones_seen;
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
197 size_t dsts_seen;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
198 size_t times_seen;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
199 size_t zones_seen;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
200
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
201 /* Table of local time zone abbrevations, terminated by a null entry. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
202 table local_time_zone_table[3];
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
203 } parser_control;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
204
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
205 union YYSTYPE;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
206 static int yylex (union YYSTYPE *, parser_control *);
7558
c778aa6236a8 * lib/getdate.y (yyerror): Make the arguments pointer-to-const,
Paul Eggert <eggert@cs.ucla.edu>
parents: 7302
diff changeset
207 static int yyerror (parser_control const *, char const *);
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
208 static long int time_zone_hhmm (parser_control *, textint, long int);
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
209
9484
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
210 /* Extract into *PC any date and time info from a string of digits
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
211 of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY,
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
212 YYYY, ...). */
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
213 static void
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
214 digits_to_date_time (parser_control *pc, textint text_int)
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
215 {
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
216 if (pc->dates_seen && ! pc->year.digits
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
217 && ! pc->rels_seen && (pc->times_seen || 2 < text_int.digits))
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
218 pc->year = text_int;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
219 else
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
220 {
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
221 if (4 < text_int.digits)
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
222 {
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
223 pc->dates_seen++;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
224 pc->day = text_int.value % 100;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
225 pc->month = (text_int.value / 100) % 100;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
226 pc->year.value = text_int.value / 10000;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
227 pc->year.digits = text_int.digits - 4;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
228 }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
229 else
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
230 {
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
231 pc->times_seen++;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
232 if (text_int.digits <= 2)
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
233 {
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
234 pc->hour = text_int.value;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
235 pc->minutes = 0;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
236 }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
237 else
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
238 {
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
239 pc->hour = text_int.value / 100;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
240 pc->minutes = text_int.value % 100;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
241 }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
242 pc->seconds.tv_sec = 0;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
243 pc->seconds.tv_nsec = 0;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
244 pc->meridian = MER24;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
245 }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
246 }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
247 }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
248
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
249 /* Increment PC->rel by FACTOR * REL (FACTOR is 1 or -1). */
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
250 static void
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
251 apply_relative_time (parser_control *pc, relative_time rel, int factor)
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
252 {
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
253 pc->rel.ns += factor * rel.ns;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
254 pc->rel.seconds += factor * rel.seconds;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
255 pc->rel.minutes += factor * rel.minutes;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
256 pc->rel.hour += factor * rel.hour;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
257 pc->rel.day += factor * rel.day;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
258 pc->rel.month += factor * rel.month;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
259 pc->rel.year += factor * rel.year;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
260 pc->rels_seen = true;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
261 }
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
262
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
263 /* Set PC-> hour, minutes, seconds and nanoseconds members from arguments. */
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
264 static void
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
265 set_hhmmss (parser_control *pc, long int hour, long int minutes,
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
266 time_t sec, long int nsec)
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
267 {
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
268 pc->hour = hour;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
269 pc->minutes = minutes;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
270 pc->seconds.tv_sec = sec;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
271 pc->seconds.tv_nsec = nsec;
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
272 }
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
273
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
274 %}
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
275
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
276 /* We want a reentrant parser, even if the TZ manipulation and the calls to
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
277 localtime and gmtime are not reentrant. */
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
278 %pure-parser
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
279 %parse-param { parser_control *pc }
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
280 %lex-param { parser_control *pc }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
281
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
282 /* This grammar has 20 shift/reduce conflicts. */
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
283 %expect 20
2588
17f2ecbac01c (get_date): Apply relative times after time zone indicator, not before.
Jim Meyering <jim@meyering.net>
parents: 2280
diff changeset
284
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
285 %union
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
286 {
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
287 long int intval;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
288 textint textintval;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
289 struct timespec timespec;
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
290 relative_time rel;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
291 }
1203
2b6373ef4d3b Add %expect directive.
Jim Meyering <jim@meyering.net>
parents: 932
diff changeset
292
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
293 %token tAGO tDST
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
294
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
295 %token tYEAR_UNIT tMONTH_UNIT tHOUR_UNIT tMINUTE_UNIT tSEC_UNIT
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
296 %token <intval> tDAY_UNIT
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
297
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
298 %token <intval> tDAY tDAYZONE tLOCAL_ZONE tMERIDIAN
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
299 %token <intval> tMONTH tORDINAL tZONE
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
300
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
301 %token <textintval> tSNUMBER tUNUMBER
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
302 %token <timespec> tSDECIMAL_NUMBER tUDECIMAL_NUMBER
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
303
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
304 %type <intval> o_colon_minutes o_merid
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
305 %type <timespec> seconds signed_seconds unsigned_seconds
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
306
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
307 %type <rel> relunit relunit_snumber
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
308
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
309 %%
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
310
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
311 spec:
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
312 timespec
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
313 | items
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
314 ;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
315
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
316 timespec:
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
317 '@' seconds
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
318 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
319 pc->seconds = $2;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
320 pc->timespec_seen = true;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
321 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
322 ;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
323
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
324 items:
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
325 /* empty */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
326 | items item
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
327 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
328
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
329 item:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
330 time
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
331 { pc->times_seen++; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
332 | local_zone
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
333 { pc->local_zones_seen++; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
334 | zone
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
335 { pc->zones_seen++; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
336 | date
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
337 { pc->dates_seen++; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
338 | day
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
339 { pc->days_seen++; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
340 | rel
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
341 | number
9484
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
342 | hybrid
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
343 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
344
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
345 time:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
346 tUNUMBER tMERIDIAN
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
347 {
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
348 set_hhmmss (pc, $1.value, 0, 0, 0);
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
349 pc->meridian = $2;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
350 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
351 | tUNUMBER ':' tUNUMBER o_merid
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
352 {
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
353 set_hhmmss (pc, $1.value, $3.value, 0, 0);
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
354 pc->meridian = $4;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
355 }
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
356 | tUNUMBER ':' tUNUMBER tSNUMBER o_colon_minutes
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
357 {
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
358 set_hhmmss (pc, $1.value, $3.value, 0, 0);
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
359 pc->meridian = MER24;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
360 pc->zones_seen++;
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
361 pc->time_zone = time_zone_hhmm (pc, $4, $5);
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
362 }
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
363 | tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
364 {
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
365 set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec);
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
366 pc->meridian = $6;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
367 }
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
368 | tUNUMBER ':' tUNUMBER ':' unsigned_seconds tSNUMBER o_colon_minutes
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
369 {
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
370 set_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec);
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
371 pc->meridian = MER24;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
372 pc->zones_seen++;
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
373 pc->time_zone = time_zone_hhmm (pc, $6, $7);
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
374 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
375 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
376
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
377 local_zone:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
378 tLOCAL_ZONE
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
379 {
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
380 pc->local_isdst = $1;
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
381 pc->dsts_seen += (0 < $1);
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
382 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
383 | tLOCAL_ZONE tDST
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
384 {
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
385 pc->local_isdst = 1;
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
386 pc->dsts_seen += (0 < $1) + 1;
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
387 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
388 ;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
389
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
390 zone:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
391 tZONE
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
392 { pc->time_zone = $1; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
393 | tZONE relunit_snumber
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
394 { pc->time_zone = $1;
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
395 apply_relative_time (pc, $2, 1); }
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
396 | tZONE tSNUMBER o_colon_minutes
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
397 { pc->time_zone = $1 + time_zone_hhmm (pc, $2, $3); }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
398 | tDAYZONE
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
399 { pc->time_zone = $1 + 60; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
400 | tZONE tDST
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
401 { pc->time_zone = $1 + 60; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
402 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
403
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
404 day:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
405 tDAY
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
406 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
407 pc->day_ordinal = 1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
408 pc->day_number = $1;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
409 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
410 | tDAY ','
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
411 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
412 pc->day_ordinal = 1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
413 pc->day_number = $1;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
414 }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
415 | tORDINAL tDAY
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
416 {
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
417 pc->day_ordinal = $1;
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
418 pc->day_number = $2;
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
419 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
420 | tUNUMBER tDAY
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
421 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
422 pc->day_ordinal = $1.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
423 pc->day_number = $2;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
424 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
425 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
426
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
427 date:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
428 tUNUMBER '/' tUNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
429 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
430 pc->month = $1.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
431 pc->day = $3.value;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
432 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
433 | tUNUMBER '/' tUNUMBER '/' tUNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
434 {
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
435 /* Interpret as YYYY/MM/DD if the first value has 4 or more digits,
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
436 otherwise as MM/DD/YY.
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
437 The goal in recognizing YYYY/MM/DD is solely to support legacy
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
438 machine-generated dates like those in an RCS log listing. If
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
439 you want portability, use the ISO 8601 format. */
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
440 if (4 <= $1.digits)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
441 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
442 pc->year = $1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
443 pc->month = $3.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
444 pc->day = $5.value;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
445 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
446 else
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
447 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
448 pc->month = $1.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
449 pc->day = $3.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
450 pc->year = $5;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
451 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
452 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
453 | tUNUMBER tSNUMBER tSNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
454 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
455 /* ISO 8601 format. YYYY-MM-DD. */
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
456 pc->year = $1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
457 pc->month = -$2.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
458 pc->day = -$3.value;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
459 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
460 | tUNUMBER tMONTH tSNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
461 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
462 /* e.g. 17-JUN-1992. */
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
463 pc->day = $1.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
464 pc->month = $2;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
465 pc->year.value = -$3.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
466 pc->year.digits = $3.digits;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
467 }
4503
c4806038beda (date): Also accept dates like May-23-2003; suggestion
Paul Eggert <eggert@cs.ucla.edu>
parents: 4156
diff changeset
468 | tMONTH tSNUMBER tSNUMBER
c4806038beda (date): Also accept dates like May-23-2003; suggestion
Paul Eggert <eggert@cs.ucla.edu>
parents: 4156
diff changeset
469 {
c4806038beda (date): Also accept dates like May-23-2003; suggestion
Paul Eggert <eggert@cs.ucla.edu>
parents: 4156
diff changeset
470 /* e.g. JUN-17-1992. */
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
471 pc->month = $1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
472 pc->day = -$2.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
473 pc->year.value = -$3.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
474 pc->year.digits = $3.digits;
4503
c4806038beda (date): Also accept dates like May-23-2003; suggestion
Paul Eggert <eggert@cs.ucla.edu>
parents: 4156
diff changeset
475 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
476 | tMONTH tUNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
477 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
478 pc->month = $1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
479 pc->day = $2.value;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
480 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
481 | tMONTH tUNUMBER ',' tUNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
482 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
483 pc->month = $1;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
484 pc->day = $2.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
485 pc->year = $4;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
486 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
487 | tUNUMBER tMONTH
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
488 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
489 pc->day = $1.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
490 pc->month = $2;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
491 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
492 | tUNUMBER tMONTH tUNUMBER
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
493 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
494 pc->day = $1.value;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
495 pc->month = $2;
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
496 pc->year = $3;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
497 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
498 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
499
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
500 rel:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
501 relunit tAGO
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
502 { apply_relative_time (pc, $1, -1); }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
503 | relunit
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
504 { apply_relative_time (pc, $1, 1); }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
505 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
506
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
507 relunit:
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
508 tORDINAL tYEAR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
509 { $$ = RELATIVE_TIME_0; $$.year = $1; }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
510 | tUNUMBER tYEAR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
511 { $$ = RELATIVE_TIME_0; $$.year = $1.value; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
512 | tYEAR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
513 { $$ = RELATIVE_TIME_0; $$.year = 1; }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
514 | tORDINAL tMONTH_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
515 { $$ = RELATIVE_TIME_0; $$.month = $1; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
516 | tUNUMBER tMONTH_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
517 { $$ = RELATIVE_TIME_0; $$.month = $1.value; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
518 | tMONTH_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
519 { $$ = RELATIVE_TIME_0; $$.month = 1; }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
520 | tORDINAL tDAY_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
521 { $$ = RELATIVE_TIME_0; $$.day = $1 * $2; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
522 | tUNUMBER tDAY_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
523 { $$ = RELATIVE_TIME_0; $$.day = $1.value * $2; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
524 | tDAY_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
525 { $$ = RELATIVE_TIME_0; $$.day = $1; }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
526 | tORDINAL tHOUR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
527 { $$ = RELATIVE_TIME_0; $$.hour = $1; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
528 | tUNUMBER tHOUR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
529 { $$ = RELATIVE_TIME_0; $$.hour = $1.value; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
530 | tHOUR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
531 { $$ = RELATIVE_TIME_0; $$.hour = 1; }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
532 | tORDINAL tMINUTE_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
533 { $$ = RELATIVE_TIME_0; $$.minutes = $1; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
534 | tUNUMBER tMINUTE_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
535 { $$ = RELATIVE_TIME_0; $$.minutes = $1.value; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
536 | tMINUTE_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
537 { $$ = RELATIVE_TIME_0; $$.minutes = 1; }
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
538 | tORDINAL tSEC_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
539 { $$ = RELATIVE_TIME_0; $$.seconds = $1; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
540 | tUNUMBER tSEC_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
541 { $$ = RELATIVE_TIME_0; $$.seconds = $1.value; }
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
542 | tSDECIMAL_NUMBER tSEC_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
543 { $$ = RELATIVE_TIME_0; $$.seconds = $1.tv_sec; $$.ns = $1.tv_nsec; }
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
544 | tUDECIMAL_NUMBER tSEC_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
545 { $$ = RELATIVE_TIME_0; $$.seconds = $1.tv_sec; $$.ns = $1.tv_nsec; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
546 | tSEC_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
547 { $$ = RELATIVE_TIME_0; $$.seconds = 1; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
548 | relunit_snumber
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
549 ;
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
550
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
551 relunit_snumber:
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
552 tSNUMBER tYEAR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
553 { $$ = RELATIVE_TIME_0; $$.year = $1.value; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
554 | tSNUMBER tMONTH_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
555 { $$ = RELATIVE_TIME_0; $$.month = $1.value; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
556 | tSNUMBER tDAY_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
557 { $$ = RELATIVE_TIME_0; $$.day = $1.value * $2; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
558 | tSNUMBER tHOUR_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
559 { $$ = RELATIVE_TIME_0; $$.hour = $1.value; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
560 | tSNUMBER tMINUTE_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
561 { $$ = RELATIVE_TIME_0; $$.minutes = $1.value; }
5795
73e3d526838b (zone): Allow relunit_snumber after tZONE, so
Paul Eggert <eggert@cs.ucla.edu>
parents: 5793
diff changeset
562 | tSNUMBER tSEC_UNIT
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
563 { $$ = RELATIVE_TIME_0; $$.seconds = $1.value; }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
564 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
565
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
566 seconds: signed_seconds | unsigned_seconds;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
567
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
568 signed_seconds:
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
569 tSDECIMAL_NUMBER
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
570 | tSNUMBER
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
571 { $$.tv_sec = $1.value; $$.tv_nsec = 0; }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
572 ;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
573
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
574 unsigned_seconds:
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
575 tUDECIMAL_NUMBER
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
576 | tUNUMBER
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
577 { $$.tv_sec = $1.value; $$.tv_nsec = 0; }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
578 ;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
579
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
580 number:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
581 tUNUMBER
9484
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
582 { digits_to_date_time (pc, $1); }
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
583 ;
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
584
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
585 hybrid:
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
586 tUNUMBER relunit_snumber
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
587 {
9484
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
588 /* Hybrid all-digit and relative offset, so that we accept e.g.,
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
589 "YYYYMMDD +N days" as well as "YYYYMMDD N days". */
f546f92d1513 Adjust getdate's grammar to accept a slightly more regular language.
Ondřej Vašík <ovasik@redhat.com>
parents: 9433
diff changeset
590 digits_to_date_time (pc, $1);
10254
309ad548f542 getdate.y: factor out common actions
Ondřej Vašík <ovasik@redhat.com>
parents: 9626
diff changeset
591 apply_relative_time (pc, $2, 1);
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
592 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
593 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
594
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
595 o_colon_minutes:
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
596 /* empty */
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
597 { $$ = -1; }
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
598 | ':' tUNUMBER
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
599 { $$ = $2.value; }
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
600 ;
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
601
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
602 o_merid:
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
603 /* empty */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
604 { $$ = MER24; }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
605 | tMERIDIAN
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
606 { $$ = $1; }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
607 ;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
608
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
609 %%
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
610
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
611 static table const meridian_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
612 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
613 { "AM", tMERIDIAN, MERam },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
614 { "A.M.", tMERIDIAN, MERam },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
615 { "PM", tMERIDIAN, MERpm },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
616 { "P.M.", tMERIDIAN, MERpm },
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
617 { NULL, 0, 0 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
618 };
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
619
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
620 static table const dst_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
621 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
622 { "DST", tDST, 0 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
623 };
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
624
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
625 static table const month_and_day_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
626 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
627 { "JANUARY", tMONTH, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
628 { "FEBRUARY", tMONTH, 2 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
629 { "MARCH", tMONTH, 3 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
630 { "APRIL", tMONTH, 4 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
631 { "MAY", tMONTH, 5 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
632 { "JUNE", tMONTH, 6 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
633 { "JULY", tMONTH, 7 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
634 { "AUGUST", tMONTH, 8 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
635 { "SEPTEMBER",tMONTH, 9 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
636 { "SEPT", tMONTH, 9 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
637 { "OCTOBER", tMONTH, 10 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
638 { "NOVEMBER", tMONTH, 11 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
639 { "DECEMBER", tMONTH, 12 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
640 { "SUNDAY", tDAY, 0 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
641 { "MONDAY", tDAY, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
642 { "TUESDAY", tDAY, 2 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
643 { "TUES", tDAY, 2 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
644 { "WEDNESDAY",tDAY, 3 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
645 { "WEDNES", tDAY, 3 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
646 { "THURSDAY", tDAY, 4 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
647 { "THUR", tDAY, 4 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
648 { "THURS", tDAY, 4 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
649 { "FRIDAY", tDAY, 5 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
650 { "SATURDAY", tDAY, 6 },
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
651 { NULL, 0, 0 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
652 };
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
653
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
654 static table const time_units_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
655 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
656 { "YEAR", tYEAR_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
657 { "MONTH", tMONTH_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
658 { "FORTNIGHT",tDAY_UNIT, 14 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
659 { "WEEK", tDAY_UNIT, 7 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
660 { "DAY", tDAY_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
661 { "HOUR", tHOUR_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
662 { "MINUTE", tMINUTE_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
663 { "MIN", tMINUTE_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
664 { "SECOND", tSEC_UNIT, 1 },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
665 { "SEC", tSEC_UNIT, 1 },
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
666 { NULL, 0, 0 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
667 };
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
668
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
669 /* Assorted relative-time words. */
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
670 static table const relative_time_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
671 {
4618
daa83913e57f (relative_time_table): Use tDAY_UNIT for "tomorrow", "yesterday",
Paul Eggert <eggert@cs.ucla.edu>
parents: 4503
diff changeset
672 { "TOMORROW", tDAY_UNIT, 1 },
daa83913e57f (relative_time_table): Use tDAY_UNIT for "tomorrow", "yesterday",
Paul Eggert <eggert@cs.ucla.edu>
parents: 4503
diff changeset
673 { "YESTERDAY",tDAY_UNIT, -1 },
daa83913e57f (relative_time_table): Use tDAY_UNIT for "tomorrow", "yesterday",
Paul Eggert <eggert@cs.ucla.edu>
parents: 4503
diff changeset
674 { "TODAY", tDAY_UNIT, 0 },
daa83913e57f (relative_time_table): Use tDAY_UNIT for "tomorrow", "yesterday",
Paul Eggert <eggert@cs.ucla.edu>
parents: 4503
diff changeset
675 { "NOW", tDAY_UNIT, 0 },
5449
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
676 { "LAST", tORDINAL, -1 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
677 { "THIS", tORDINAL, 0 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
678 { "NEXT", tORDINAL, 1 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
679 { "FIRST", tORDINAL, 1 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
680 /*{ "SECOND", tORDINAL, 2 }, */
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
681 { "THIRD", tORDINAL, 3 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
682 { "FOURTH", tORDINAL, 4 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
683 { "FIFTH", tORDINAL, 5 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
684 { "SIXTH", tORDINAL, 6 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
685 { "SEVENTH", tORDINAL, 7 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
686 { "EIGHTH", tORDINAL, 8 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
687 { "NINTH", tORDINAL, 9 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
688 { "TENTH", tORDINAL, 10 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
689 { "ELEVENTH", tORDINAL, 11 },
3b55c2b65e86 (tORDINAL): New token.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5414
diff changeset
690 { "TWELFTH", tORDINAL, 12 },
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
691 { "AGO", tAGO, 1 },
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
692 { NULL, 0, 0 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
693 };
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
694
5793
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
695 /* The universal time zone table. These labels can be used even for
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
696 time stamps that would not otherwise be valid, e.g., GMT time
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
697 stamps in London during summer. */
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
698 static table const universal_time_zone_table[] =
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
699 {
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
700 { "GMT", tZONE, HOUR ( 0) }, /* Greenwich Mean */
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
701 { "UT", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
702 { "UTC", tZONE, HOUR ( 0) },
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
703 { NULL, 0, 0 }
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
704 };
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
705
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
706 /* The time zone table. This table is necessarily incomplete, as time
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
707 zone abbreviations are ambiguous; e.g. Australians interpret "EST"
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
708 as Eastern time in Australia, not as US Eastern Standard Time.
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
709 You cannot rely on getdate to handle arbitrary time zone
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
710 abbreviations; use numeric abbreviations like `-0500' instead. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
711 static table const time_zone_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
712 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
713 { "WET", tZONE, HOUR ( 0) }, /* Western European */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
714 { "WEST", tDAYZONE, HOUR ( 0) }, /* Western European Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
715 { "BST", tDAYZONE, HOUR ( 0) }, /* British Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
716 { "ART", tZONE, -HOUR ( 3) }, /* Argentina */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
717 { "BRT", tZONE, -HOUR ( 3) }, /* Brazil */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
718 { "BRST", tDAYZONE, -HOUR ( 3) }, /* Brazil Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
719 { "NST", tZONE, -(HOUR ( 3) + 30) }, /* Newfoundland Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
720 { "NDT", tDAYZONE,-(HOUR ( 3) + 30) }, /* Newfoundland Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
721 { "AST", tZONE, -HOUR ( 4) }, /* Atlantic Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
722 { "ADT", tDAYZONE, -HOUR ( 4) }, /* Atlantic Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
723 { "CLT", tZONE, -HOUR ( 4) }, /* Chile */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
724 { "CLST", tDAYZONE, -HOUR ( 4) }, /* Chile Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
725 { "EST", tZONE, -HOUR ( 5) }, /* Eastern Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
726 { "EDT", tDAYZONE, -HOUR ( 5) }, /* Eastern Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
727 { "CST", tZONE, -HOUR ( 6) }, /* Central Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
728 { "CDT", tDAYZONE, -HOUR ( 6) }, /* Central Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
729 { "MST", tZONE, -HOUR ( 7) }, /* Mountain Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
730 { "MDT", tDAYZONE, -HOUR ( 7) }, /* Mountain Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
731 { "PST", tZONE, -HOUR ( 8) }, /* Pacific Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
732 { "PDT", tDAYZONE, -HOUR ( 8) }, /* Pacific Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
733 { "AKST", tZONE, -HOUR ( 9) }, /* Alaska Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
734 { "AKDT", tDAYZONE, -HOUR ( 9) }, /* Alaska Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
735 { "HST", tZONE, -HOUR (10) }, /* Hawaii Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
736 { "HAST", tZONE, -HOUR (10) }, /* Hawaii-Aleutian Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
737 { "HADT", tDAYZONE, -HOUR (10) }, /* Hawaii-Aleutian Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
738 { "SST", tZONE, -HOUR (12) }, /* Samoa Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
739 { "WAT", tZONE, HOUR ( 1) }, /* West Africa */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
740 { "CET", tZONE, HOUR ( 1) }, /* Central European */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
741 { "CEST", tDAYZONE, HOUR ( 1) }, /* Central European Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
742 { "MET", tZONE, HOUR ( 1) }, /* Middle European */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
743 { "MEZ", tZONE, HOUR ( 1) }, /* Middle European */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
744 { "MEST", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
745 { "MESZ", tDAYZONE, HOUR ( 1) }, /* Middle European Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
746 { "EET", tZONE, HOUR ( 2) }, /* Eastern European */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
747 { "EEST", tDAYZONE, HOUR ( 2) }, /* Eastern European Summer */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
748 { "CAT", tZONE, HOUR ( 2) }, /* Central Africa */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
749 { "SAST", tZONE, HOUR ( 2) }, /* South Africa Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
750 { "EAT", tZONE, HOUR ( 3) }, /* East Africa */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
751 { "MSK", tZONE, HOUR ( 3) }, /* Moscow */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
752 { "MSD", tDAYZONE, HOUR ( 3) }, /* Moscow Daylight */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
753 { "IST", tZONE, (HOUR ( 5) + 30) }, /* India Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
754 { "SGT", tZONE, HOUR ( 8) }, /* Singapore */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
755 { "KST", tZONE, HOUR ( 9) }, /* Korea Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
756 { "JST", tZONE, HOUR ( 9) }, /* Japan Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
757 { "GST", tZONE, HOUR (10) }, /* Guam Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
758 { "NZST", tZONE, HOUR (12) }, /* New Zealand Standard */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
759 { "NZDT", tDAYZONE, HOUR (12) }, /* New Zealand Daylight */
5793
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
760 { NULL, 0, 0 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
761 };
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
762
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
763 /* Military time zone table. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
764 static table const military_table[] =
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
765 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
766 { "A", tZONE, -HOUR ( 1) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
767 { "B", tZONE, -HOUR ( 2) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
768 { "C", tZONE, -HOUR ( 3) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
769 { "D", tZONE, -HOUR ( 4) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
770 { "E", tZONE, -HOUR ( 5) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
771 { "F", tZONE, -HOUR ( 6) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
772 { "G", tZONE, -HOUR ( 7) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
773 { "H", tZONE, -HOUR ( 8) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
774 { "I", tZONE, -HOUR ( 9) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
775 { "K", tZONE, -HOUR (10) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
776 { "L", tZONE, -HOUR (11) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
777 { "M", tZONE, -HOUR (12) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
778 { "N", tZONE, HOUR ( 1) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
779 { "O", tZONE, HOUR ( 2) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
780 { "P", tZONE, HOUR ( 3) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
781 { "Q", tZONE, HOUR ( 4) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
782 { "R", tZONE, HOUR ( 5) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
783 { "S", tZONE, HOUR ( 6) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
784 { "T", tZONE, HOUR ( 7) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
785 { "U", tZONE, HOUR ( 8) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
786 { "V", tZONE, HOUR ( 9) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
787 { "W", tZONE, HOUR (10) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
788 { "X", tZONE, HOUR (11) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
789 { "Y", tZONE, HOUR (12) },
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
790 { "Z", tZONE, HOUR ( 0) },
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
791 { NULL, 0, 0 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
792 };
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
793
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
794
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
795
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
796 /* Convert a time zone expressed as HH:MM into an integer count of
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
797 minutes. If MM is negative, then S is of the form HHMM and needs
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
798 to be picked apart; otherwise, S is of the form HH. As specified in
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
799 http://www.opengroup.org/susv3xbd/xbd_chap08.html#tag_08_03, allow
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
800 only valid TZ range, and consider first two digits as hours, if no
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
801 minutes specified. */
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
802
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
803 static long int
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
804 time_zone_hhmm (parser_control *pc, textint s, long int mm)
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
805 {
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
806 long int n_minutes;
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
807
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
808 /* If the length of S is 1 or 2 and no minutes are specified,
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
809 interpret it as a number of hours. */
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
810 if (s.digits <= 2 && mm < 0)
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
811 s.value *= 100;
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
812
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
813 if (mm < 0)
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
814 n_minutes = (s.value / 100) * 60 + s.value % 100;
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
815 else
10398
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
816 n_minutes = s.value * 60 + (s.negative ? -mm : mm);
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
817
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
818 /* If the absolute number of minutes is larger than 24 hours,
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
819 arrange to reject it by incrementing pc->zones_seen. Thus,
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
820 we allow only values in the range UTC-24:00 to UTC+24:00. */
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
821 if (24 * 60 < abs (n_minutes))
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
822 pc->zones_seen++;
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
823
c640552acc85 getdate.y: reject an out-of-range timezone value
Ondřej Vašík <ovasik@redhat.com>
parents: 10302
diff changeset
824 return n_minutes;
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
825 }
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
826
16
01c6d40adf9d Make tables static and const when possible.
Jim Meyering <jim@meyering.net>
parents: 9
diff changeset
827 static int
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
828 to_hour (long int hours, int meridian)
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
829 {
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
830 switch (meridian)
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
831 {
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
832 default: /* Pacify GCC. */
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
833 case MER24:
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
834 return 0 <= hours && hours < 24 ? hours : -1;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
835 case MERam:
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
836 return 0 < hours && hours < 12 ? hours : hours == 12 ? 0 : -1;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
837 case MERpm:
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
838 return 0 < hours && hours < 12 ? hours + 12 : hours == 12 ? 12 : -1;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
839 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
840 }
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
841
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
842 static long int
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
843 to_year (textint textyear)
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
844 {
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
845 long int year = textyear.value;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
846
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
847 if (year < 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
848 year = -year;
852
2156a43352c1 1997-01-06 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents: 814
diff changeset
849
2156a43352c1 1997-01-06 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents: 814
diff changeset
850 /* XPG4 suggests that years 00-68 map to 2000-2068, and
2156a43352c1 1997-01-06 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents: 814
diff changeset
851 years 69-99 map to 1969-1999. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
852 else if (textyear.digits == 2)
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
853 year += year < 69 ? 2000 : 1900;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
854
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
855 return year;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
856 }
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
857
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
858 static table const *
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
859 lookup_zone (parser_control const *pc, char const *name)
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
860 {
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
861 table const *tp;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
862
5793
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
863 for (tp = universal_time_zone_table; tp->name; tp++)
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
864 if (strcmp (name, tp->name) == 0)
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
865 return tp;
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
866
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
867 /* Try local zone abbreviations before those in time_zone_table, as
e6643f99cbc0 (universal_time_zone_table): New constant.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5787
diff changeset
868 the local ones are more likely to be right. */
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
869 for (tp = pc->local_time_zone_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
870 if (strcmp (name, tp->name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
871 return tp;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
872
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
873 for (tp = time_zone_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
874 if (strcmp (name, tp->name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
875 return tp;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
876
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
877 return NULL;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
878 }
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
879
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
880 #if ! HAVE_TM_GMTOFF
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
881 /* Yield the difference between *A and *B,
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
882 measured in seconds, ignoring leap seconds.
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
883 The body of this function is taken directly from the GNU C Library;
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
884 see src/strftime.c. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
885 static long int
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
886 tm_diff (struct tm const *a, struct tm const *b)
207
25a5ae7fce09 Revert 1.14-1.16 changes that removed difftm and modified get_date.
Jim Meyering <jim@meyering.net>
parents: 202
diff changeset
887 {
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
888 /* Compute intervening leap days correctly even if year is negative.
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
889 Take care to avoid int overflow in leap day calculations. */
5414
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
890 int a4 = SHR (a->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (a->tm_year & 3);
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
891 int b4 = SHR (b->tm_year, 2) + SHR (TM_YEAR_BASE, 2) - ! (b->tm_year & 3);
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
892 int a100 = a4 / 25 - (a4 % 25 < 0);
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
893 int b100 = b4 / 25 - (b4 % 25 < 0);
5414
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
894 int a400 = SHR (a100, 2);
1b5e702ecdd1 (SHR): New macro, which is a portable
Paul Eggert <eggert@cs.ucla.edu>
parents: 5391
diff changeset
895 int b400 = SHR (b100, 2);
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
896 int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
897 long int ayear = a->tm_year;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
898 long int years = ayear - b->tm_year;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
899 long int days = (365 * years + intervening_leap_days
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
900 + (a->tm_yday - b->tm_yday));
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
901 return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
902 + (a->tm_min - b->tm_min))
207
25a5ae7fce09 Revert 1.14-1.16 changes that removed difftm and modified get_date.
Jim Meyering <jim@meyering.net>
parents: 202
diff changeset
903 + (a->tm_sec - b->tm_sec));
25a5ae7fce09 Revert 1.14-1.16 changes that removed difftm and modified get_date.
Jim Meyering <jim@meyering.net>
parents: 202
diff changeset
904 }
2080
32451d20b978 Sync tm_diff with the GNU C Library.
Jim Meyering <jim@meyering.net>
parents: 2048
diff changeset
905 #endif /* ! HAVE_TM_GMTOFF */
207
25a5ae7fce09 Revert 1.14-1.16 changes that removed difftm and modified get_date.
Jim Meyering <jim@meyering.net>
parents: 202
diff changeset
906
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
907 static table const *
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
908 lookup_word (parser_control const *pc, char *word)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
909 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
910 char *p;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
911 char *q;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
912 size_t wordlen;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
913 table const *tp;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
914 bool period_found;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
915 bool abbrev;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
916
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
917 /* Make it uppercase. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
918 for (p = word; *p; p++)
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5080
diff changeset
919 {
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5080
diff changeset
920 unsigned char ch = *p;
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
921 *p = c_toupper (ch);
5159
a535859efd14 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5080
diff changeset
922 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
923
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
924 for (tp = meridian_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
925 if (strcmp (word, tp->name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
926 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
927
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
928 /* See if we have an abbreviation for a month. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
929 wordlen = strlen (word);
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
930 abbrev = wordlen == 3 || (wordlen == 4 && word[3] == '.');
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
931
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
932 for (tp = month_and_day_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
933 if ((abbrev ? strncmp (word, tp->name, 3) : strcmp (word, tp->name)) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
934 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
935
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
936 if ((tp = lookup_zone (pc, word)))
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
937 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
938
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
939 if (strcmp (word, dst_table[0].name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
940 return dst_table;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
941
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
942 for (tp = time_units_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
943 if (strcmp (word, tp->name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
944 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
945
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
946 /* Strip off any plural and try the units table again. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
947 if (word[wordlen - 1] == 'S')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
948 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
949 word[wordlen - 1] = '\0';
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
950 for (tp = time_units_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
951 if (strcmp (word, tp->name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
952 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
953 word[wordlen - 1] = 'S'; /* For "this" in relative_time_table. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
954 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
955
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
956 for (tp = relative_time_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
957 if (strcmp (word, tp->name) == 0)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
958 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
959
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
960 /* Military time zones. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
961 if (wordlen == 1)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
962 for (tp = military_table; tp->name; tp++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
963 if (word[0] == tp->name[0])
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
964 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
965
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
966 /* Drop out any periods and try the time zone table again. */
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
967 for (period_found = false, p = q = word; (*p = *q); q++)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
968 if (*q == '.')
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
969 period_found = true;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
970 else
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
971 p++;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
972 if (period_found && (tp = lookup_zone (pc, word)))
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
973 return tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
974
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
975 return NULL;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
976 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
977
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
978 static int
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
979 yylex (YYSTYPE *lvalp, parser_control *pc)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
980 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
981 unsigned char c;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
982 size_t count;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
983
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
984 for (;;)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
985 {
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
986 while (c = *pc->input, c_isspace (c))
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
987 pc->input++;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
988
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
989 if (ISDIGIT (c) || c == '-' || c == '+')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
990 {
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
991 char const *p;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
992 int sign;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
993 unsigned long int value;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
994 if (c == '-' || c == '+')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
995 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
996 sign = c == '-' ? -1 : 1;
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
997 while (c = *++pc->input, c_isspace (c))
5080
033d299cab29 * getdate.y (yylex): Allow space between sign and number.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4984
diff changeset
998 continue;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
999 if (! ISDIGIT (c))
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1000 /* skip the '-' sign */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1001 continue;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1002 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1003 else
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1004 sign = 0;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1005 p = pc->input;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1006 for (value = 0; ; value *= 10)
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1007 {
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1008 unsigned long int value1 = value + (c - '0');
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1009 if (value1 < value)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1010 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1011 value = value1;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1012 c = *++p;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1013 if (! ISDIGIT (c))
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1014 break;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1015 if (ULONG_MAX / 10 < value)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1016 return '?';
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1017 }
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1018 if ((c == '.' || c == ',') && ISDIGIT (p[1]))
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1019 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1020 time_t s;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1021 int ns;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1022 int digits;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1023 unsigned long int value1;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1024
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1025 /* Check for overflow when converting value to time_t. */
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1026 if (sign < 0)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1027 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1028 s = - value;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1029 if (0 < s)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1030 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1031 value1 = -s;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1032 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1033 else
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1034 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1035 s = value;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1036 if (s < 0)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1037 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1038 value1 = s;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1039 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1040 if (value != value1)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1041 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1042
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1043 /* Accumulate fraction, to ns precision. */
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1044 p++;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1045 ns = *p++ - '0';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1046 for (digits = 2; digits <= LOG10_BILLION; digits++)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1047 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1048 ns *= 10;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1049 if (ISDIGIT (*p))
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1050 ns += *p++ - '0';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1051 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1052
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1053 /* Skip excess digits, truncating toward -Infinity. */
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1054 if (sign < 0)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1055 for (; ISDIGIT (*p); p++)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1056 if (*p != '0')
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1057 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1058 ns++;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1059 break;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1060 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1061 while (ISDIGIT (*p))
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1062 p++;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1063
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1064 /* Adjust to the timespec convention, which is that
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1065 tv_nsec is always a positive offset even if tv_sec is
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1066 negative. */
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1067 if (sign < 0 && ns)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1068 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1069 s--;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1070 if (! (s < 0))
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1071 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1072 ns = BILLION - ns;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1073 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1074
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1075 lvalp->timespec.tv_sec = s;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1076 lvalp->timespec.tv_nsec = ns;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1077 pc->input = p;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1078 return sign ? tSDECIMAL_NUMBER : tUDECIMAL_NUMBER;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1079 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1080 else
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1081 {
5520
abe89af7ac24 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5449
diff changeset
1082 lvalp->textintval.negative = sign < 0;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1083 if (sign < 0)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1084 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1085 lvalp->textintval.value = - value;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1086 if (0 < lvalp->textintval.value)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1087 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1088 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1089 else
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1090 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1091 lvalp->textintval.value = value;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1092 if (lvalp->textintval.value < 0)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1093 return '?';
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1094 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1095 lvalp->textintval.digits = p - pc->input;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1096 pc->input = p;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1097 return sign ? tSNUMBER : tUNUMBER;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1098 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1099 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1100
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
1101 if (c_isalpha (c))
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1102 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1103 char buff[20];
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1104 char *p = buff;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1105 table const *tp;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1106
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1107 do
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1108 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1109 if (p < buff + sizeof buff - 1)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1110 *p++ = c;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1111 c = *++pc->input;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1112 }
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
1113 while (c_isalpha (c) || c == '.');
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1114
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1115 *p = '\0';
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1116 tp = lookup_word (pc, buff);
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1117 if (! tp)
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1118 return '?';
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1119 lvalp->intval = tp->value;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1120 return tp->type;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1121 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1122
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1123 if (c != '(')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1124 return *pc->input++;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1125 count = 0;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1126 do
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1127 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1128 c = *pc->input++;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1129 if (c == '\0')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1130 return c;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1131 if (c == '(')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1132 count++;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1133 else if (c == ')')
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1134 count--;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1135 }
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1136 while (count != 0);
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1137 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1138 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1139
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1140 /* Do nothing if the parser reports an error. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1141 static int
7558
c778aa6236a8 * lib/getdate.y (yyerror): Make the arguments pointer-to-const,
Paul Eggert <eggert@cs.ucla.edu>
parents: 7302
diff changeset
1142 yyerror (parser_control const *pc ATTRIBUTE_UNUSED,
c778aa6236a8 * lib/getdate.y (yyerror): Make the arguments pointer-to-const,
Paul Eggert <eggert@cs.ucla.edu>
parents: 7302
diff changeset
1143 char const *s ATTRIBUTE_UNUSED)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1144 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1145 return 0;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1146 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1147
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1148 /* If *TM0 is the old and *TM1 is the new value of a struct tm after
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1149 passing it to mktime, return true if it's OK that mktime returned T.
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1150 It's not OK if *TM0 has out-of-range members. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1151
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1152 static bool
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1153 mktime_ok (struct tm const *tm0, struct tm const *tm1, time_t t)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1154 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1155 if (t == (time_t) -1)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1156 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1157 /* Guard against falsely reporting an error when parsing a time
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1158 stamp that happens to equal (time_t) -1, on a host that
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1159 supports such a time stamp. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1160 tm1 = localtime (&t);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1161 if (!tm1)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1162 return false;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1163 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1164
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1165 return ! ((tm0->tm_sec ^ tm1->tm_sec)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1166 | (tm0->tm_min ^ tm1->tm_min)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1167 | (tm0->tm_hour ^ tm1->tm_hour)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1168 | (tm0->tm_mday ^ tm1->tm_mday)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1169 | (tm0->tm_mon ^ tm1->tm_mon)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1170 | (tm0->tm_year ^ tm1->tm_year));
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1171 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1172
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1173 /* A reasonable upper bound for the size of ordinary TZ strings.
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1174 Use heap allocation if TZ's length exceeds this. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1175 enum { TZBUFSIZE = 100 };
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1176
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1177 /* Return a copy of TZ, stored in TZBUF if it fits, and heap-allocated
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1178 otherwise. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1179 static char *
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1180 get_tz (char tzbuf[TZBUFSIZE])
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1181 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1182 char *tz = getenv ("TZ");
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1183 if (tz)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1184 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1185 size_t tzsize = strlen (tz) + 1;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1186 tz = (tzsize <= TZBUFSIZE
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1187 ? memcpy (tzbuf, tz, tzsize)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1188 : xmemdup (tz, tzsize));
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1189 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1190 return tz;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1191 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1192
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1193 /* Parse a date/time string, storing the resulting time value into *RESULT.
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1194 The string itself is pointed to by P. Return true if successful.
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1195 P can be an incomplete or relative time specification; if so, use
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1196 *NOW as the basis for the returned time. */
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1197 bool
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1198 get_date (struct timespec *result, char const *p, struct timespec const *now)
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1199 {
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1200 time_t Start;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1201 long int Start_ns;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1202 struct tm const *tmp;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1203 struct tm tm;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1204 struct tm tm0;
2280
adaf08e40364 Handle two-digit years with leading zeros correctly.
Jim Meyering <jim@meyering.net>
parents: 2110
diff changeset
1205 parser_control pc;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1206 struct timespec gettime_buffer;
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1207 unsigned char c;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1208 bool tz_was_altered = false;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1209 char *tz0 = NULL;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1210 char tz0buf[TZBUFSIZE];
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1211 bool ok = true;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1212
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1213 if (! now)
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1214 {
5662
42df9db003cc * modules/gethrxtime: New file.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5548
diff changeset
1215 gettime (&gettime_buffer);
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1216 now = &gettime_buffer;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1217 }
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1218
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1219 Start = now->tv_sec;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1220 Start_ns = now->tv_nsec;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1221
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1222 tmp = localtime (&now->tv_sec);
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1223 if (! tmp)
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1224 return false;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1225
10302
3884ac6e6550 getdate.y: avoid locale-dependent date parsing failure
Jim Meyering <meyering@redhat.com>
parents: 10256
diff changeset
1226 while (c = *p, c_isspace (c))
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1227 p++;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1228
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1229 if (strncmp (p, "TZ=\"", 4) == 0)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1230 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1231 char const *tzbase = p + 4;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1232 size_t tzsize = 1;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1233 char const *s;
5391
4776df58a51d Remove trailing white space.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5382
diff changeset
1234
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1235 for (s = tzbase; *s; s++, tzsize++)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1236 if (*s == '\\')
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1237 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1238 s++;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1239 if (! (*s == '\\' || *s == '"'))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1240 break;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1241 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1242 else if (*s == '"')
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1243 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1244 char *z;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1245 char *tz1;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1246 char tz1buf[TZBUFSIZE];
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1247 bool large_tz = TZBUFSIZE < tzsize;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1248 bool setenv_ok;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1249 tz0 = get_tz (tz0buf);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1250 z = tz1 = large_tz ? xmalloc (tzsize) : tz1buf;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1251 for (s = tzbase; *s != '"'; s++)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1252 *z++ = *(s += *s == '\\');
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1253 *z = '\0';
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1254 setenv_ok = setenv ("TZ", tz1, 1) == 0;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1255 if (large_tz)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1256 free (tz1);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1257 if (!setenv_ok)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1258 goto fail;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1259 tz_was_altered = true;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1260 p = s + 1;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1261 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1262 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1263
9433
bb252eb60189 Treat an empty date string exactly like "0".
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
1264 /* As documented, be careful to treat the empty string just like
bb252eb60189 Treat an empty date string exactly like "0".
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
1265 a date string of "0". Without this, an empty string would be
bb252eb60189 Treat an empty date string exactly like "0".
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
1266 declared invalid when parsed during a DST transition. */
bb252eb60189 Treat an empty date string exactly like "0".
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
1267 if (*p == '\0')
bb252eb60189 Treat an empty date string exactly like "0".
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
1268 p = "0";
bb252eb60189 Treat an empty date string exactly like "0".
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
1269
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1270 pc.input = p;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1271 pc.year.value = tmp->tm_year;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1272 pc.year.value += TM_YEAR_BASE;
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
1273 pc.year.digits = 0;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1274 pc.month = tmp->tm_mon + 1;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1275 pc.day = tmp->tm_mday;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1276 pc.hour = tmp->tm_hour;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1277 pc.minutes = tmp->tm_min;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1278 pc.seconds.tv_sec = tmp->tm_sec;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1279 pc.seconds.tv_nsec = Start_ns;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1280 tm.tm_isdst = tmp->tm_isdst;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1281
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1282 pc.meridian = MER24;
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1283 pc.rel = RELATIVE_TIME_0;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1284 pc.timespec_seen = false;
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
1285 pc.rels_seen = false;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1286 pc.dates_seen = 0;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1287 pc.days_seen = 0;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1288 pc.times_seen = 0;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1289 pc.local_zones_seen = 0;
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
1290 pc.dsts_seen = 0;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1291 pc.zones_seen = 0;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1292
4102
1804d7137fc9 Test HAVE_STRUCT_TM_TM_ZONE, not HAVE_TM_ZONE.
Bruno Haible <bruno@clisp.org>
parents: 3701
diff changeset
1293 #if HAVE_STRUCT_TM_TM_ZONE
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1294 pc.local_time_zone_table[0].name = tmp->tm_zone;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1295 pc.local_time_zone_table[0].type = tLOCAL_ZONE;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1296 pc.local_time_zone_table[0].value = tmp->tm_isdst;
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1297 pc.local_time_zone_table[1].name = NULL;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1298
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1299 /* Probe the names used in the next three calendar quarters, looking
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1300 for a tm_isdst different from the one we already have. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1301 {
1929
f7d4ee7478d7 (get_date): Rename outermost local `probe' to `quarter'.
Jim Meyering <jim@meyering.net>
parents: 1928
diff changeset
1302 int quarter;
f7d4ee7478d7 (get_date): Rename outermost local `probe' to `quarter'.
Jim Meyering <jim@meyering.net>
parents: 1928
diff changeset
1303 for (quarter = 1; quarter <= 3; quarter++)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1304 {
1929
f7d4ee7478d7 (get_date): Rename outermost local `probe' to `quarter'.
Jim Meyering <jim@meyering.net>
parents: 1928
diff changeset
1305 time_t probe = Start + quarter * (90 * 24 * 60 * 60);
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1306 struct tm const *probe_tm = localtime (&probe);
1930
92632825178b (get_date): Rename latter local `tm' to probe_tm.
Jim Meyering <jim@meyering.net>
parents: 1929
diff changeset
1307 if (probe_tm && probe_tm->tm_zone
92632825178b (get_date): Rename latter local `tm' to probe_tm.
Jim Meyering <jim@meyering.net>
parents: 1929
diff changeset
1308 && probe_tm->tm_isdst != pc.local_time_zone_table[0].value)
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1309 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1310 {
1930
92632825178b (get_date): Rename latter local `tm' to probe_tm.
Jim Meyering <jim@meyering.net>
parents: 1929
diff changeset
1311 pc.local_time_zone_table[1].name = probe_tm->tm_zone;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1312 pc.local_time_zone_table[1].type = tLOCAL_ZONE;
1930
92632825178b (get_date): Rename latter local `tm' to probe_tm.
Jim Meyering <jim@meyering.net>
parents: 1929
diff changeset
1313 pc.local_time_zone_table[1].value = probe_tm->tm_isdst;
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1314 pc.local_time_zone_table[2].name = NULL;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1315 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1316 break;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1317 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1318 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1319 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1320 #else
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1321 #if HAVE_TZNAME
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1322 {
9626
def4f669ceac Fix problem with getdate on mingw32 reported by Simon Josefsson
Paul Eggert <eggert@cs.ucla.edu>
parents: 9545
diff changeset
1323 # if !HAVE_DECL_TZNAME
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1324 extern char *tzname[];
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1325 # endif
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1326 int i;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1327 for (i = 0; i < 2; i++)
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1328 {
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1329 pc.local_time_zone_table[i].name = tzname[i];
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1330 pc.local_time_zone_table[i].type = tLOCAL_ZONE;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1331 pc.local_time_zone_table[i].value = i;
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1332 }
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1333 pc.local_time_zone_table[i].name = NULL;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1334 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1335 #else
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1336 pc.local_time_zone_table[0].name = NULL;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1337 #endif
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1338 #endif
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1339
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1340 if (pc.local_time_zone_table[0].name && pc.local_time_zone_table[1].name
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1341 && ! strcmp (pc.local_time_zone_table[0].name,
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1342 pc.local_time_zone_table[1].name))
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1343 {
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1344 /* This locale uses the same abbrevation for standard and
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1345 daylight times. So if we see that abbreviation, we don't
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1346 know whether it's daylight time. */
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1347 pc.local_time_zone_table[0].value = -1;
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1348 pc.local_time_zone_table[1].name = NULL;
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1349 }
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1350
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1351 if (yyparse (&pc) != 0)
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1352 goto fail;
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1353
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1354 if (pc.timespec_seen)
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1355 *result = pc.seconds;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1356 else
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1357 {
5787
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
1358 if (1 < (pc.times_seen | pc.dates_seen | pc.days_seen | pc.dsts_seen
cbe22a271d32 (parser_control): rels_seen is now a boolean, not a
Paul Eggert <eggert@cs.ucla.edu>
parents: 5662
diff changeset
1359 | (pc.local_zones_seen + pc.zones_seen)))
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1360 goto fail;
852
2156a43352c1 1997-01-06 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents: 814
diff changeset
1361
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1362 tm.tm_year = to_year (pc.year) - TM_YEAR_BASE;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1363 tm.tm_mon = pc.month - 1;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1364 tm.tm_mday = pc.day;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1365 if (pc.times_seen || (pc.rels_seen && ! pc.dates_seen && ! pc.days_seen))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1366 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1367 tm.tm_hour = to_hour (pc.hour, pc.meridian);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1368 if (tm.tm_hour < 0)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1369 goto fail;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1370 tm.tm_min = pc.minutes;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1371 tm.tm_sec = pc.seconds.tv_sec;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1372 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1373 else
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1374 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1375 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1376 pc.seconds.tv_nsec = 0;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1377 }
852
2156a43352c1 1997-01-06 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents: 814
diff changeset
1378
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1379 /* Let mktime deduce tm_isdst if we have an absolute time stamp. */
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1380 if (pc.dates_seen | pc.days_seen | pc.times_seen)
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1381 tm.tm_isdst = -1;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1382
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1383 /* But if the input explicitly specifies local time with or without
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1384 DST, give mktime that information. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1385 if (pc.local_zones_seen)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1386 tm.tm_isdst = pc.local_isdst;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1387
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1388 tm0 = tm;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1389
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1390 Start = mktime (&tm);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1391
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1392 if (! mktime_ok (&tm0, &tm, Start))
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1393 {
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1394 if (! pc.zones_seen)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1395 goto fail;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1396 else
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1397 {
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1398 /* Guard against falsely reporting errors near the time_t
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1399 boundaries when parsing times in other time zones. For
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1400 example, suppose the input string "1969-12-31 23:00:00 -0100",
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1401 the current time zone is 8 hours ahead of UTC, and the min
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1402 time_t value is 1970-01-01 00:00:00 UTC. Then the min
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1403 localtime value is 1970-01-01 08:00:00, and mktime will
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1404 therefore fail on 1969-12-31 23:00:00. To work around the
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1405 problem, set the time zone to 1 hour behind UTC temporarily
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1406 by setting TZ="XXX1:00" and try mktime again. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1407
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1408 long int time_zone = pc.time_zone;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1409 long int abs_time_zone = time_zone < 0 ? - time_zone : time_zone;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1410 long int abs_time_zone_hour = abs_time_zone / 60;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1411 int abs_time_zone_min = abs_time_zone % 60;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1412 char tz1buf[sizeof "XXX+0:00"
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1413 + sizeof pc.time_zone * CHAR_BIT / 3];
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1414 if (!tz_was_altered)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1415 tz0 = get_tz (tz0buf);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1416 sprintf (tz1buf, "XXX%s%ld:%02d", "-" + (time_zone < 0),
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1417 abs_time_zone_hour, abs_time_zone_min);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1418 if (setenv ("TZ", tz1buf, 1) != 0)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1419 goto fail;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1420 tz_was_altered = true;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1421 tm = tm0;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1422 Start = mktime (&tm);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1423 if (! mktime_ok (&tm0, &tm, Start))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1424 goto fail;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1425 }
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1426 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1427
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1428 if (pc.days_seen && ! pc.dates_seen)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1429 {
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1430 tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1431 + 7 * (pc.day_ordinal - (0 < pc.day_ordinal)));
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1432 tm.tm_isdst = -1;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1433 Start = mktime (&tm);
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1434 if (Start == (time_t) -1)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1435 goto fail;
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1436 }
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1437
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1438 /* Add relative date. */
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1439 if (pc.rel.year | pc.rel.month | pc.rel.day)
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1440 {
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1441 int year = tm.tm_year + pc.rel.year;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1442 int month = tm.tm_mon + pc.rel.month;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1443 int day = tm.tm_mday + pc.rel.day;
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1444 if (((year < tm.tm_year) ^ (pc.rel.year < 0))
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1445 | ((month < tm.tm_mon) ^ (pc.rel.month < 0))
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1446 | ((day < tm.tm_mday) ^ (pc.rel.day < 0)))
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1447 goto fail;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1448 tm.tm_year = year;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1449 tm.tm_mon = month;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1450 tm.tm_mday = day;
6755
ac1a29f7e8d8 * getdate.y (get_date): When adding relative date, start with the
Paul Eggert <eggert@cs.ucla.edu>
parents: 6269
diff changeset
1451 tm.tm_hour = tm0.tm_hour;
ac1a29f7e8d8 * getdate.y (get_date): When adding relative date, start with the
Paul Eggert <eggert@cs.ucla.edu>
parents: 6269
diff changeset
1452 tm.tm_min = tm0.tm_min;
ac1a29f7e8d8 * getdate.y (get_date): When adding relative date, start with the
Paul Eggert <eggert@cs.ucla.edu>
parents: 6269
diff changeset
1453 tm.tm_sec = tm0.tm_sec;
ac1a29f7e8d8 * getdate.y (get_date): When adding relative date, start with the
Paul Eggert <eggert@cs.ucla.edu>
parents: 6269
diff changeset
1454 tm.tm_isdst = tm0.tm_isdst;
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1455 Start = mktime (&tm);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1456 if (Start == (time_t) -1)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1457 goto fail;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1458 }
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1459
10256
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1460 /* The only "output" of this if-block is an updated Start value,
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1461 so this block must follow others that clobber Start. */
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1462 if (pc.zones_seen)
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1463 {
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1464 long int delta = pc.time_zone * 60;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1465 time_t t1;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1466 #ifdef HAVE_TM_GMTOFF
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1467 delta -= tm.tm_gmtoff;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1468 #else
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1469 time_t t = Start;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1470 struct tm const *gmt = gmtime (&t);
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1471 if (! gmt)
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1472 goto fail;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1473 delta -= tm_diff (&tm, gmt);
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1474 #endif
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1475 t1 = Start - delta;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1476 if ((Start < t1) != (delta < 0))
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1477 goto fail; /* time_t overflow */
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1478 Start = t1;
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1479 }
af15fcca9925 getdate.y: do not ignore TZ with relative day, month or year offset
Ondřej Vašík <ovasik@redhat.com>
parents: 10254
diff changeset
1480
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1481 /* Add relative hours, minutes, and seconds. On hosts that support
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1482 leap seconds, ignore the possibility of leap seconds; e.g.,
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1483 "+ 10 minutes" adds 600 seconds, even if one of them is a
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1484 leap second. Typically this is not what the user wants, but it's
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1485 too hard to do it the other way, because the time zone indicator
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1486 must be applied before relative times, and if mktime is applied
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1487 again the time zone will be lost. */
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1488 {
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1489 long int sum_ns = pc.seconds.tv_nsec + pc.rel.ns;
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1490 long int normalized_ns = (sum_ns % BILLION + BILLION) % BILLION;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1491 time_t t0 = Start;
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1492 long int d1 = 60 * 60 * pc.rel.hour;
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1493 time_t t1 = t0 + d1;
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1494 long int d2 = 60 * pc.rel.minutes;
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1495 time_t t2 = t1 + d2;
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1496 long int d3 = pc.rel.seconds;
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1497 time_t t3 = t2 + d3;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1498 long int d4 = (sum_ns - normalized_ns) / BILLION;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1499 time_t t4 = t3 + d4;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1500
6269
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1501 if ((d1 / (60 * 60) ^ pc.rel.hour)
e3cfa812528f * m4/getdate.m4 (gl_C_COMPOUND_LITERALS): New macro.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
1502 | (d2 / 60 ^ pc.rel.minutes)
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1503 | ((t1 < t0) ^ (d1 < 0))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1504 | ((t2 < t1) ^ (d2 < 0))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1505 | ((t3 < t2) ^ (d3 < 0))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1506 | ((t4 < t3) ^ (d4 < 0)))
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1507 goto fail;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1508
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1509 result->tv_sec = t4;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1510 result->tv_nsec = normalized_ns;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1511 }
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1512 }
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1513
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1514 goto done;
852
2156a43352c1 1997-01-06 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents: 814
diff changeset
1515
5373
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1516 fail:
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1517 ok = false;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1518 done:
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1519 if (tz_was_altered)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1520 ok &= (tz0 ? setenv ("TZ", tz0, 1) : unsetenv ("TZ")) == 0;
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1521 if (tz0 != tz0buf)
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1522 free (tz0);
2169bf8a12fc Add support for TZ="foo" within a date string.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5368
diff changeset
1523 return ok;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1524 }
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1525
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1526 #if TEST
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1527
202
eeeec8731bb9 merge with 1.9.4e
Jim Meyering <jim@meyering.net>
parents: 201
diff changeset
1528 int
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1529 main (int ac, char **av)
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1530 {
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1531 char buff[BUFSIZ];
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1532
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1533 printf ("Enter date, or blank line to exit.\n\t> ");
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1534 fflush (stdout);
321
4f4862ac3437 merge with 1.10q
Jim Meyering <jim@meyering.net>
parents: 307
diff changeset
1535
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1536 buff[BUFSIZ - 1] = '\0';
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1537 while (fgets (buff, BUFSIZ - 1, stdin) && buff[0])
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1538 {
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1539 struct timespec d;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1540 struct tm const *tm;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1541 if (! get_date (&d, buff, NULL))
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1542 printf ("Bad format - couldn't convert.\n");
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1543 else if (! (tm = localtime (&d.tv_sec)))
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1544 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1545 long int sec = d.tv_sec;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1546 printf ("localtime (%ld) failed\n", sec);
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1547 }
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1548 else
4984
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1549 {
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1550 int ns = d.tv_nsec;
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1551 printf ("%04ld-%02d-%02d %02d:%02d:%02d.%09d\n",
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1552 tm->tm_year + 1900L, tm->tm_mon + 1, tm->tm_mday,
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1553 tm->tm_hour, tm->tm_min, tm->tm_sec, ns);
8c6149ff20c9 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4644
diff changeset
1554 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1555 printf ("\t> ");
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1556 fflush (stdout);
857
35c6ee15b830 Indent with GNU indent.
Jim Meyering <jim@meyering.net>
parents: 856
diff changeset
1557 }
1928
3119c326ccc8 Add copyright notice.
Jim Meyering <jim@meyering.net>
parents: 1914
diff changeset
1558 return 0;
9
f8dce34b5ab0 Initial revision
Jim Meyering <jim@meyering.net>
parents:
diff changeset
1559 }
5368
d7bc1d77db6d Use Bison 1.875 features, and some minor
Paul Eggert <eggert@cs.ucla.edu>
parents: 5318
diff changeset
1560 #endif /* TEST */