summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-04-24 12:48:45 +0000
committerJim Meyering <jim@meyering.net>1994-04-24 12:48:45 +0000
commit7c68f857d0f0df3dac81ff27ff7f2205abe859fd (patch)
treee9cff760b359c8ad1dd0913c2ec8cd8637f8eeb7 /lib
parente628e7bb9e1d441d35b9d429b760589e96616a2c (diff)
downloadcoreutils-7c68f857d0f0df3dac81ff27ff7f2205abe859fd.tar.xz
Revert 1.14-1.16 changes that removed difftm and modified get_date.
Diffstat (limited to 'lib')
-rw-r--r--lib/getdate.y50
1 files changed, 31 insertions, 19 deletions
diff --git a/lib/getdate.y b/lib/getdate.y
index 6d93a57d6..31e402b23 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -863,38 +863,50 @@ yylex()
}
}
+#define TM_YEAR_ORIGIN 1900
+
+/* Yield A - B, measured in seconds. */
+static long
+difftm (a, b)
+ struct tm *a, *b;
+{
+ int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
+ int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
+ int days = (
+ /* difference in day of year */
+ a->tm_yday - b->tm_yday
+ /* + intervening leap days */
+ + ((ay >> 2) - (by >> 2))
+ - (ay/100 - by/100)
+ + ((ay/100 >> 2) - (by/100 >> 2))
+ /* + difference in years * 365 */
+ + (long)(ay-by) * 365
+ );
+ return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
+ + (a->tm_min - b->tm_min))
+ + (a->tm_sec - b->tm_sec));
+}
+
time_t
get_date(p, now)
char *p;
struct timeb *now;
{
- struct tm *tm;
+ struct tm *tm, gmt;
struct timeb ftz;
time_t Start;
time_t tod;
yyInput = p;
- if (now == NULL)
- {
- int tz;
- struct tm *tmp;
- time_t epoch = 0;
-
+ if (now == NULL) {
now = &ftz;
(void)time(&ftz.time);
- /* Compute local timezone. Do *not* take daylight savings
- into account here. */
- tmp = localtime (&epoch);
- tz = tmp->tm_hour * 60 + tmp->tm_min; /* Minutes east of UTC. */
- if (tz > 0)
- {
- tz = 24 * 60 - tz; /* Minutes west of UTC. */
- if (tmp->tm_year == 70)
- tz -= 24 * 60; /* Account for date line. */
- }
- ftz.timezone = tz;
- }
+ if (! (tm = gmtime (&ftz.time)))
+ return -1;
+ gmt = *tm; /* Make a copy, in case localtime modifies *tm. */
+ ftz.timezone = difftm (&gmt, localtime (&ftz.time)) / 60;
+ }
tm = localtime(&now->time);
yyYear = tm->tm_year;