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