diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c new file mode 100644 index 3d320cc..936d9f5 *** a/src/backend/utils/adt/datetime.c --- b/src/backend/utils/adt/datetime.c *************** DecodeDateTime(char **field, int *ftype, *** 799,804 **** --- 799,806 ---- bool is2digits = FALSE; bool bc = FALSE; pg_tz *namedTz = NULL; + struct pg_tm tt, + *cur_tm = &tt; /* * We'll insist on at least all of the date fields, but initialize the *************** DecodeDateTime(char **field, int *ftype, *** 1197,1228 **** case DTK_YESTERDAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; ! GetCurrentDateTime(tm); ! j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - 1, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); - tm->tm_hour = 0; - tm->tm_min = 0; - tm->tm_sec = 0; break; case DTK_TODAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; ! GetCurrentDateTime(tm); ! tm->tm_hour = 0; ! tm->tm_min = 0; ! tm->tm_sec = 0; break; case DTK_TOMORROW: tmask = DTK_DATE_M; *dtype = DTK_DATE; ! GetCurrentDateTime(tm); ! j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); - tm->tm_hour = 0; - tm->tm_min = 0; - tm->tm_sec = 0; break; case DTK_ZULU: --- 1199,1224 ---- case DTK_YESTERDAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; ! GetCurrentDateTime(cur_tm); ! j2date(date2j(cur_tm->tm_year, cur_tm->tm_mon, cur_tm->tm_mday) - 1, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); break; case DTK_TODAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; ! GetCurrentDateTime(cur_tm); ! tm->tm_year = cur_tm->tm_year; ! tm->tm_mon = cur_tm->tm_mon; ! tm->tm_mday = cur_tm->tm_mday; break; case DTK_TOMORROW: tmask = DTK_DATE_M; *dtype = DTK_DATE; ! GetCurrentDateTime(cur_tm); ! j2date(date2j(cur_tm->tm_year, cur_tm->tm_mon, cur_tm->tm_mday) + 1, &tm->tm_year, &tm->tm_mon, &tm->tm_mday); break; case DTK_ZULU: diff --git a/src/test/regress/expected/horology.out b/src/test/regress/expected/horology.out new file mode 100644 index b13f7d7..8526765 *** a/src/test/regress/expected/horology.out --- b/src/test/regress/expected/horology.out *************** SELECT (timestamp without time zone 'tod *** 388,399 **** --- 388,435 ---- t (1 row) + SELECT (timestamp without time zone 'today 10:30' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp without time zone '10:30 today' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True"; + True + ------ + t + (1 row) + SELECT (timestamp without time zone 'tomorrow' = (timestamp without time zone 'yesterday' + interval '2 days')) as "True"; True ------ t (1 row) + SELECT (timestamp without time zone 'tomorrow 16:00:00' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp without time zone '16:00:00 tomorrow' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp without time zone 'yesterday 12:34:56' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp without time zone '12:34:56 yesterday' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True"; + True + ------ + t + (1 row) + SELECT (timestamp without time zone 'tomorrow' > 'now') as "True"; True ------ *************** SELECT (timestamp with time zone 'today' *** 603,612 **** --- 639,690 ---- t (1 row) + SELECT (timestamp with time zone 'today 10:30+05' = timestamptz(date 'today', time with time zone '10:30 +05')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp with time zone '10:30+05 today' = timestamptz(date 'today', time with time zone '10:30 +05')) as "True"; + True + ------ + t + (1 row) + SELECT (timestamp with time zone 'tomorrow' = (timestamp with time zone 'yesterday' + interval '2 days')) as "True"; True ------ t + (1 row) + + SELECT (timestamp with time zone 'tomorrow 10:30+05' = (timestamp with time zone 'today 10:30+05' + interval '1 day')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp with time zone '10:30+05 tomorrow' = (timestamp with time zone 'today 10:30+05' + interval '1 day')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp with time zone 'yesterday 12:34:56-7' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp with time zone '12:34:56 yesterday -7' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True"; + True + ------ + t + (1 row) + + SELECT (timestamp with time zone '12:34:56-7 yesterday' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True"; + True + ------ + t (1 row) SELECT (timestamp with time zone 'tomorrow' > 'now') as "True"; diff --git a/src/test/regress/sql/horology.sql b/src/test/regress/sql/horology.sql new file mode 100644 index 97ff9f2..e9981e5 *** a/src/test/regress/sql/horology.sql --- b/src/test/regress/sql/horology.sql *************** SELECT timestamp without time zone '12/3 *** 91,97 **** --- 91,103 ---- -- So, just try to test parser and hope for the best - thomas 97/04/26 SELECT (timestamp without time zone 'today' = (timestamp without time zone 'yesterday' + interval '1 day')) as "True"; SELECT (timestamp without time zone 'today' = (timestamp without time zone 'tomorrow' - interval '1 day')) as "True"; + SELECT (timestamp without time zone 'today 10:30' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True"; + SELECT (timestamp without time zone '10:30 today' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True"; SELECT (timestamp without time zone 'tomorrow' = (timestamp without time zone 'yesterday' + interval '2 days')) as "True"; + SELECT (timestamp without time zone 'tomorrow 16:00:00' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True"; + SELECT (timestamp without time zone '16:00:00 tomorrow' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True"; + SELECT (timestamp without time zone 'yesterday 12:34:56' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True"; + SELECT (timestamp without time zone '12:34:56 yesterday' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True"; SELECT (timestamp without time zone 'tomorrow' > 'now') as "True"; -- Convert from date and time to timestamp *************** SELECT timestamp with time zone '1999-12 *** 112,118 **** --- 118,131 ---- SELECT (timestamp with time zone 'today' = (timestamp with time zone 'yesterday' + interval '1 day')) as "True"; SELECT (timestamp with time zone 'today' = (timestamp with time zone 'tomorrow' - interval '1 day')) as "True"; + SELECT (timestamp with time zone 'today 10:30+05' = timestamptz(date 'today', time with time zone '10:30 +05')) as "True"; + SELECT (timestamp with time zone '10:30+05 today' = timestamptz(date 'today', time with time zone '10:30 +05')) as "True"; SELECT (timestamp with time zone 'tomorrow' = (timestamp with time zone 'yesterday' + interval '2 days')) as "True"; + SELECT (timestamp with time zone 'tomorrow 10:30+05' = (timestamp with time zone 'today 10:30+05' + interval '1 day')) as "True"; + SELECT (timestamp with time zone '10:30+05 tomorrow' = (timestamp with time zone 'today 10:30+05' + interval '1 day')) as "True"; + SELECT (timestamp with time zone 'yesterday 12:34:56-7' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True"; + SELECT (timestamp with time zone '12:34:56 yesterday -7' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True"; + SELECT (timestamp with time zone '12:34:56-7 yesterday' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True"; SELECT (timestamp with time zone 'tomorrow' > 'now') as "True"; -- timestamp with time zone, interval arithmetic around DST change