diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-08-30 11:34:29 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-08-30 11:38:42 -0400 |
commit | 8a3d33c8e6c681d512f79af4a521ee0c02befcef (patch) | |
tree | f85ddcc351946c777225a19c578d2c52254c5d61 /src/backend/utils | |
parent | eab2ef6164ae2d0e5a72501de9c09474fd94a394 (diff) | |
download | postgresql-8a3d33c8e6c681d512f79af4a521ee0c02befcef.tar.gz postgresql-8a3d33c8e6c681d512f79af4a521ee0c02befcef.zip |
Fix parsing of time string followed by yesterday/today/tomorrow.
Previously, 'yesterday 04:00:00'::timestamp didn't do the same thing as
'04:00:00 yesterday'::timestamp, and the return value from the latter
was midnight rather than the specified time.
Dean Rasheed, with some stylistic changes
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 3d320ccdd58..dad41fc20e5 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -799,6 +799,7 @@ DecodeDateTime(char **field, int *ftype, int nf, bool is2digits = FALSE; bool bc = FALSE; pg_tz *namedTz = NULL; + struct pg_tm cur_tm; /* * We'll insist on at least all of the date fields, but initialize the @@ -1197,32 +1198,26 @@ DecodeDateTime(char **field, int *ftype, int nf, case DTK_YESTERDAY: tmask = DTK_DATE_M; *dtype = DTK_DATE; - GetCurrentDateTime(tm); - j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - 1, + 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); - 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; + 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(tm); - j2date(date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) + 1, + 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); - tm->tm_hour = 0; - tm->tm_min = 0; - tm->tm_sec = 0; break; case DTK_ZULU: |