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