Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a3d33c

Browse files
committed
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 latterwas midnight rather than the specified time.Dean Rasheed, with some stylistic changes
1 parenteab2ef6 commit8a3d33c

File tree

3 files changed

+100
-14
lines changed

3 files changed

+100
-14
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
799799
boolis2digits= FALSE;
800800
boolbc= FALSE;
801801
pg_tz*namedTz=NULL;
802+
structpg_tmcur_tm;
802803

803804
/*
804805
* 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,
11971198
caseDTK_YESTERDAY:
11981199
tmask=DTK_DATE_M;
11991200
*dtype=DTK_DATE;
1200-
GetCurrentDateTime(tm);
1201-
j2date(date2j(tm->tm_year,tm->tm_mon,tm->tm_mday)-1,
1201+
GetCurrentDateTime(&cur_tm);
1202+
j2date(date2j(cur_tm.tm_year,cur_tm.tm_mon,cur_tm.tm_mday)-1,
12021203
&tm->tm_year,&tm->tm_mon,&tm->tm_mday);
1203-
tm->tm_hour=0;
1204-
tm->tm_min=0;
1205-
tm->tm_sec=0;
12061204
break;
12071205

12081206
caseDTK_TODAY:
12091207
tmask=DTK_DATE_M;
12101208
*dtype=DTK_DATE;
1211-
GetCurrentDateTime(tm);
1212-
tm->tm_hour=0;
1213-
tm->tm_min=0;
1214-
tm->tm_sec=0;
1209+
GetCurrentDateTime(&cur_tm);
1210+
tm->tm_year=cur_tm.tm_year;
1211+
tm->tm_mon=cur_tm.tm_mon;
1212+
tm->tm_mday=cur_tm.tm_mday;
12151213
break;
12161214

12171215
caseDTK_TOMORROW:
12181216
tmask=DTK_DATE_M;
12191217
*dtype=DTK_DATE;
1220-
GetCurrentDateTime(tm);
1221-
j2date(date2j(tm->tm_year,tm->tm_mon,tm->tm_mday)+1,
1218+
GetCurrentDateTime(&cur_tm);
1219+
j2date(date2j(cur_tm.tm_year,cur_tm.tm_mon,cur_tm.tm_mday)+1,
12221220
&tm->tm_year,&tm->tm_mon,&tm->tm_mday);
1223-
tm->tm_hour=0;
1224-
tm->tm_min=0;
1225-
tm->tm_sec=0;
12261221
break;
12271222

12281223
caseDTK_ZULU:

‎src/test/regress/expected/horology.out

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,48 @@ SELECT (timestamp without time zone 'today' = (timestamp without time zone 'tomo
388388
t
389389
(1 row)
390390

391+
SELECT (timestamp without time zone 'today 10:30' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True";
392+
True
393+
------
394+
t
395+
(1 row)
396+
397+
SELECT (timestamp without time zone '10:30 today' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True";
398+
True
399+
------
400+
t
401+
(1 row)
402+
391403
SELECT (timestamp without time zone 'tomorrow' = (timestamp without time zone 'yesterday' + interval '2 days')) as "True";
392404
True
393405
------
394406
t
395407
(1 row)
396408

409+
SELECT (timestamp without time zone 'tomorrow 16:00:00' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True";
410+
True
411+
------
412+
t
413+
(1 row)
414+
415+
SELECT (timestamp without time zone '16:00:00 tomorrow' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True";
416+
True
417+
------
418+
t
419+
(1 row)
420+
421+
SELECT (timestamp without time zone 'yesterday 12:34:56' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True";
422+
True
423+
------
424+
t
425+
(1 row)
426+
427+
SELECT (timestamp without time zone '12:34:56 yesterday' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True";
428+
True
429+
------
430+
t
431+
(1 row)
432+
397433
SELECT (timestamp without time zone 'tomorrow' > 'now') as "True";
398434
True
399435
------
@@ -603,12 +639,54 @@ SELECT (timestamp with time zone 'today' = (timestamp with time zone 'tomorrow'
603639
t
604640
(1 row)
605641

642+
SELECT (timestamp with time zone 'today 10:30+05' = timestamptz(date 'today', time with time zone '10:30 +05')) as "True";
643+
True
644+
------
645+
t
646+
(1 row)
647+
648+
SELECT (timestamp with time zone '10:30+05 today' = timestamptz(date 'today', time with time zone '10:30 +05')) as "True";
649+
True
650+
------
651+
t
652+
(1 row)
653+
606654
SELECT (timestamp with time zone 'tomorrow' = (timestamp with time zone 'yesterday' + interval '2 days')) as "True";
607655
True
608656
------
609657
t
610658
(1 row)
611659

660+
SELECT (timestamp with time zone 'tomorrow 10:30+05' = (timestamp with time zone 'today 10:30+05' + interval '1 day')) as "True";
661+
True
662+
------
663+
t
664+
(1 row)
665+
666+
SELECT (timestamp with time zone '10:30+05 tomorrow' = (timestamp with time zone 'today 10:30+05' + interval '1 day')) as "True";
667+
True
668+
------
669+
t
670+
(1 row)
671+
672+
SELECT (timestamp with time zone 'yesterday 12:34:56-7' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True";
673+
True
674+
------
675+
t
676+
(1 row)
677+
678+
SELECT (timestamp with time zone '12:34:56 yesterday -7' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True";
679+
True
680+
------
681+
t
682+
(1 row)
683+
684+
SELECT (timestamp with time zone '12:34:56-7 yesterday' = timestamptz(date 'yesterday', time with time zone '12:34:56-7')) as "True";
685+
True
686+
------
687+
t
688+
(1 row)
689+
612690
SELECT (timestamp with time zone 'tomorrow' > 'now') as "True";
613691
True
614692
------

‎src/test/regress/sql/horology.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ SELECT timestamp without time zone '12/31/294276' - timestamp without time zone
9191
-- So, just try to test parser and hope for the best - thomas 97/04/26
9292
SELECT (timestamp without time zone'today'= (timestamp without time zone'yesterday'+ interval'1 day'))as"True";
9393
SELECT (timestamp without time zone'today'= (timestamp without time zone'tomorrow'- interval'1 day'))as"True";
94+
SELECT (timestamp without time zone'today 10:30'= (timestamp without time zone'yesterday'+ interval'1 day 10 hr 30 min'))as"True";
95+
SELECT (timestamp without time zone'10:30 today'= (timestamp without time zone'yesterday'+ interval'1 day 10 hr 30 min'))as"True";
9496
SELECT (timestamp without time zone'tomorrow'= (timestamp without time zone'yesterday'+ interval'2 days'))as"True";
97+
SELECT (timestamp without time zone'tomorrow 16:00:00'= (timestamp without time zone'today'+ interval'1 day 16 hours'))as"True";
98+
SELECT (timestamp without time zone'16:00:00 tomorrow'= (timestamp without time zone'today'+ interval'1 day 16 hours'))as"True";
99+
SELECT (timestamp without time zone'yesterday 12:34:56'= (timestamp without time zone'tomorrow'- interval'2 days - 12:34:56'))as"True";
100+
SELECT (timestamp without time zone'12:34:56 yesterday'= (timestamp without time zone'tomorrow'- interval'2 days - 12:34:56'))as"True";
95101
SELECT (timestamp without time zone'tomorrow'>'now')as"True";
96102

97103
-- Convert from date and time to timestamp
@@ -112,7 +118,14 @@ SELECT timestamp with time zone '1999-12-01' + interval '1 month - 1 second' AS
112118

113119
SELECT (timestamp with time zone'today'= (timestamp with time zone'yesterday'+ interval'1 day'))as"True";
114120
SELECT (timestamp with time zone'today'= (timestamp with time zone'tomorrow'- interval'1 day'))as"True";
121+
SELECT (timestamp with time zone'today 10:30+05'=timestamptz(date'today',time with time zone'10:30 +05'))as"True";
122+
SELECT (timestamp with time zone'10:30+05 today'=timestamptz(date'today',time with time zone'10:30 +05'))as"True";
115123
SELECT (timestamp with time zone'tomorrow'= (timestamp with time zone'yesterday'+ interval'2 days'))as"True";
124+
SELECT (timestamp with time zone'tomorrow 10:30+05'= (timestamp with time zone'today 10:30+05'+ interval'1 day'))as"True";
125+
SELECT (timestamp with time zone'10:30+05 tomorrow'= (timestamp with time zone'today 10:30+05'+ interval'1 day'))as"True";
126+
SELECT (timestamp with time zone'yesterday 12:34:56-7'=timestamptz(date'yesterday',time with time zone'12:34:56-7'))as"True";
127+
SELECT (timestamp with time zone'12:34:56 yesterday -7'=timestamptz(date'yesterday',time with time zone'12:34:56-7'))as"True";
128+
SELECT (timestamp with time zone'12:34:56-7 yesterday'=timestamptz(date'yesterday',time with time zone'12:34:56-7'))as"True";
116129
SELECT (timestamp with time zone'tomorrow'>'now')as"True";
117130

118131
-- timestamp with time zone, interval arithmetic around DST change

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp