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

Commitb6ed78b

Browse files
committed
Properly adjust age() seconds to match the sign of the larger units.
Patch from Tom.
1 parentdf7128b commitb6ed78b

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.179 2007/07/06 04:15:59 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.180 2007/07/18 03:13:13 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3044,7 +3044,8 @@ timestamp_age(PG_FUNCTION_ARGS)
30443044
if (timestamp2tm(dt1,NULL,tm1,&fsec1,NULL,NULL)==0&&
30453045
timestamp2tm(dt2,NULL,tm2,&fsec2,NULL,NULL)==0)
30463046
{
3047-
fsec= (fsec1-fsec2);
3047+
/* form the symbolic difference */
3048+
fsec=fsec1-fsec2;
30483049
tm->tm_sec=tm1->tm_sec-tm2->tm_sec;
30493050
tm->tm_min=tm1->tm_min-tm2->tm_min;
30503051
tm->tm_hour=tm1->tm_hour-tm2->tm_hour;
@@ -3064,6 +3065,17 @@ timestamp_age(PG_FUNCTION_ARGS)
30643065
tm->tm_year=-tm->tm_year;
30653066
}
30663067

3068+
/* propagate any negative fields into the next higher field */
3069+
while (fsec<0)
3070+
{
3071+
#ifdefHAVE_INT64_TIMESTAMP
3072+
fsec+=USECS_PER_SEC;
3073+
#else
3074+
fsec+=1.0;
3075+
#endif
3076+
tm->tm_sec--;
3077+
}
3078+
30673079
while (tm->tm_sec<0)
30683080
{
30693081
tm->tm_sec+=SECS_PER_MINUTE;
@@ -3158,6 +3170,7 @@ timestamptz_age(PG_FUNCTION_ARGS)
31583170
if (timestamp2tm(dt1,&tz1,tm1,&fsec1,&tzn,NULL)==0&&
31593171
timestamp2tm(dt2,&tz2,tm2,&fsec2,&tzn,NULL)==0)
31603172
{
3173+
/* form the symbolic difference */
31613174
fsec=fsec1-fsec2;
31623175
tm->tm_sec=tm1->tm_sec-tm2->tm_sec;
31633176
tm->tm_min=tm1->tm_min-tm2->tm_min;
@@ -3178,6 +3191,17 @@ timestamptz_age(PG_FUNCTION_ARGS)
31783191
tm->tm_year=-tm->tm_year;
31793192
}
31803193

3194+
/* propagate any negative fields into the next higher field */
3195+
while (fsec<0)
3196+
{
3197+
#ifdefHAVE_INT64_TIMESTAMP
3198+
fsec+=USECS_PER_SEC;
3199+
#else
3200+
fsec+=1.0;
3201+
#endif
3202+
tm->tm_sec--;
3203+
}
3204+
31813205
while (tm->tm_sec<0)
31823206
{
31833207
tm->tm_sec+=SECS_PER_MINUTE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp