#include <stdio.h>
#include <ctype.h>
+#include <stdlib.h>
#define ISSPACE(c) (isspace ((unsigned char)c))
#define ISALPHA(c) (isalpha ((unsigned char)c))
static int yyerror ();
#define EPOCH 1970
-#define HOUR(x) ((x) * 60)
+#define HOUR(x) ((time_t)(x) * 60)
+#define SECSPERDAY (24L * 60L * 60L)
#define MAX_BUFF_LEN 128 /* size of buffer to read the date into */
yyRelYear += $1 * $2;
}
| tYEAR_UNIT {
- yyRelYear++;
+ yyRelYear += $1;
}
| tUNUMBER tMONTH_UNIT {
yyRelMonth += $1 * $2;
yyRelMonth += $1 * $2;
}
| tMONTH_UNIT {
- yyRelMonth++;
+ yyRelMonth += $1;
}
| tUNUMBER tDAY_UNIT {
yyRelDay += $1 * $2;
yyRelDay += $1 * $2;
}
| tDAY_UNIT {
- yyRelDay++;
+ yyRelDay += $1;
}
| tUNUMBER tHOUR_UNIT {
yyRelHour += $1 * $2;
yyRelHour += $1 * $2;
}
| tHOUR_UNIT {
- yyRelHour++;
+ yyRelHour += $1;
}
| tUNUMBER tMINUTE_UNIT {
yyRelMinutes += $1 * $2;
yyRelMinutes += $1 * $2;
}
| tMINUTE_UNIT {
- yyRelMinutes++;
+ yyRelMinutes += $1;
}
| tUNUMBER tSEC_UNIT {
yyRelSeconds += $1 * $2;
yyRelSeconds += $1 * $2;
}
| tSEC_UNIT {
- yyRelSeconds++;
+ yyRelSeconds += $1;
}
;
number : tUNUMBER
- {
+ {
if (yyHaveTime && yyHaveDate && !yyHaveRel)
yyYear = $1;
else
}
else
{
- yyHour = $1 / 100;
- yyMinutes = $1 % 100;
+ yyHour = $1 / 100;
+ yyMinutes = $1 % 100;
}
yySeconds = 0;
yyMeridian = MER24;
{ "now", tMINUTE_UNIT, 0 },
{ "last", tUNUMBER, -1 },
{ "this", tMINUTE_UNIT, 0 },
- { "next", tUNUMBER, 2 },
+ { "next", tUNUMBER, 1 /* Was bogusly 2 [mdw] */ },
{ "first", tUNUMBER, 1 },
/* { "second", tUNUMBER, 2 }, */
{ "third", tUNUMBER, 3 },
#define TM_YEAR_ORIGIN 1900
+#ifndef GETDATE_IGNORE_TIMEZONE
+
/* Yield A - B, measured in seconds. */
static long
difftm (a, b)
+ (a->tm_sec - b->tm_sec));
}
+#endif
+
time_t
get_date (p, now)
const char *p;
{
/* Guard against falsely reporting errors near the time_t boundaries
- when parsing times in other time zones. For example, if the min
- time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
- of UTC, then the min localtime value is 1970-01-01 08:00:00; if
- we apply mktime to 1970-01-01 00:00:00 we will get an error, so
- we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
- zone by 24 hours to compensate. This algorithm assumes that
- there is no DST transition within a day of the time_t boundaries. */
-
+ when parsing times in other time zones. For example, if the min
+ time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
+ of UTC, then the min localtime value is 1970-01-01 08:00:00; if
+ we apply mktime to 1970-01-01 00:00:00 we will get an error, so
+ we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
+ zone by 24 hours to compensate. This algorithm assumes that
+ there is no DST transition within a day of the time_t boundaries. */
+
+#ifndef GETDATE_IGNORE_TIMEZONE
if (yyHaveZone)
{
tm = tm0;
}
Start = mktime (&tm);
}
+#endif
if (Start == (time_t) -1)
return Start;
return Start;
}
+#ifndef GETDATE_IGNORE_TIMEZONE
if (yyHaveZone)
{
long delta = yyTimezone * 60L + difftm (&tm, gmtime (&Start));
return -1; /* time_t overflow */
Start += delta;
}
+#endif
return Start;
}