comparison lib/getdate.y @ 201:883cc816a727

.
author Jim Meyering <jim@meyering.net>
date Tue, 19 Apr 1994 02:30:46 +0000
parents 09762e848a40
children eeeec8731bb9
comparison
equal deleted inserted replaced
200:14fbbb10fea8 201:883cc816a727
4 ** at the University of North Carolina at Chapel Hill. Later tweaked by 4 ** at the University of North Carolina at Chapel Hill. Later tweaked by
5 ** a couple of people on Usenet. Completely overhauled by Rich $alz 5 ** a couple of people on Usenet. Completely overhauled by Rich $alz
6 ** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990; 6 ** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
7 ** send any email to Rich. 7 ** send any email to Rich.
8 ** 8 **
9 ** This grammar has nine shift/reduce conflicts. 9 ** This grammar has 10 shift/reduce conflicts.
10 ** 10 **
11 ** This code is in the public domain and has no copyright. 11 ** This code is in the public domain and has no copyright.
12 */ 12 */
13 /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */ 13 /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
14 /* SUPPRESS 288 on yyerrlab *//* Label unused */ 14 /* SUPPRESS 288 on yyerrlab *//* Label unused */
15 15
16 #ifdef HAVE_CONFIG_H 16 #ifdef HAVE_CONFIG_H
17 #if defined (emacs) || defined (CONFIG_BROKETS) 17 #if defined (emacs) || defined (CONFIG_BROKETS)
18 #include <config.h> 18 #include <config.h>
881 Count--; 881 Count--;
882 } while (Count > 0); 882 } while (Count > 0);
883 } 883 }
884 } 884 }
885 885
886
887 #define TM_YEAR_ORIGIN 1900
888
889 /* Yield A - B, measured in seconds. */
890 static long
891 difftm (a, b)
892 struct tm *a, *b;
893 {
894 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
895 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
896 int days = (
897 /* difference in day of year */
898 a->tm_yday - b->tm_yday
899 /* + intervening leap days */
900 + ((ay >> 2) - (by >> 2))
901 - (ay/100 - by/100)
902 + ((ay/100 >> 2) - (by/100 >> 2))
903 /* + difference in years * 365 */
904 + (long)(ay-by) * 365
905 );
906 return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
907 + (a->tm_min - b->tm_min))
908 + (a->tm_sec - b->tm_sec));
909 }
910
911 time_t 886 time_t
912 get_date(p, now) 887 get_date(p, now)
913 char *p; 888 char *p;
914 struct timeb *now; 889 struct timeb *now;
915 { 890 {
916 struct tm *tm, gmt; 891 struct tm *tm;
917 struct timeb ftz; 892 struct timeb ftz;
918 time_t Start; 893 time_t Start;
919 time_t tod; 894 time_t tod;
920 895
921 yyInput = p; 896 yyInput = p;
922 if (now == NULL) { 897 if (now == NULL)
898 {
899 int tz;
900 struct tm *tmp;
901 time_t epoch = 0;
902
923 now = &ftz; 903 now = &ftz;
924 (void)time(&ftz.time); 904 (void)time(&ftz.time);
925 905
926 if (! (tm = gmtime (&ftz.time))) 906 /* Compute local timezone. Do *not* take daylight savings
927 return -1; 907 into account here. */
928 gmt = *tm; /* Make a copy, in case localtime modifies *tm. */ 908 tmp = localtime (&epoch);
929 ftz.timezone = difftm (&gmt, localtime (&ftz.time)) / 60; 909 tz = tmp->tm_hour * 60 + tmp->tm_min; /* Minutes east of UTC. */
930 } 910 if (tz > 0)
911 {
912 tz = 24 * 60 - tz; /* Minutes west of UTC. */
913 if (tmp->tm_year == 70)
914 tz -= 24 * 60; /* Account for date line. */
915 }
916 ftz.timezone = tz;
917 }
931 918
932 tm = localtime(&now->time); 919 tm = localtime(&now->time);
933 yyYear = tm->tm_year; 920 yyYear = tm->tm_year;
934 yyMonth = tm->tm_mon + 1; 921 yyMonth = tm->tm_mon + 1;
935 yyDay = tm->tm_mday; 922 yyDay = tm->tm_mday;