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

Commita97683b

Browse files
author
Thomas G. Lockhart
committed
Change #if FALSE to #if NOT_USED to avoid port problems.
Fix problem with date_part() for timespan (had an offset of one) when given decade, century, and millenium as arguments. Reported by Ricardo J.C.Coelho.
1 parent910fe58 commita97683b

File tree

1 file changed

+31
-24
lines changed
  • src/backend/utils/adt

1 file changed

+31
-24
lines changed

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

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.62 1999/01/20 16:29:39 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/dt.c,v 1.63 1999/02/13 04:25:01 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -249,7 +249,7 @@ timespan_in(char *str)
249249
caseDTK_DELTA:
250250
if (tm2timespan(tm,fsec,span)!=0)
251251
{
252-
#ifFALSE
252+
#ifNOT_USED
253253
TIMESPAN_INVALID(span);
254254
#endif
255255
elog(ERROR,"Bad timespan external representation '%s'",str);
@@ -1412,7 +1412,7 @@ datetime_trunc(text *units, DateTime *datetime)
14121412

14131413
if (DATETIME_NOT_FINITE(*datetime))
14141414
{
1415-
#ifFALSE
1415+
#ifNOT_USED
14161416
/* should return null but Postgres doesn't like that currently. - tgl 97/06/12 */
14171417
elog(ERROR,"Datetime is not finite",NULL);
14181418
#endif
@@ -1494,7 +1494,7 @@ datetime_trunc(text *units, DateTime *datetime)
14941494
if (tm2datetime(tm,fsec,&tz,result)!=0)
14951495
elog(ERROR,"Unable to truncate datetime to '%s'",lowunits);
14961496

1497-
#ifFALSE
1497+
#ifNOT_USED
14981498
}
14991499
elseif ((type==RESERV)&& (val==DTK_EPOCH))
15001500
{
@@ -1552,7 +1552,7 @@ timespan_trunc(text *units, TimeSpan *timespan)
15521552

15531553
if (TIMESPAN_IS_INVALID(*timespan))
15541554
{
1555-
#ifFALSE
1555+
#ifNOT_USED
15561556
elog(ERROR,"Timespan is not finite",NULL);
15571557
#endif
15581558
result=NULL;
@@ -1610,7 +1610,7 @@ timespan_trunc(text *units, TimeSpan *timespan)
16101610
result=NULL;
16111611
}
16121612

1613-
#ifFALSE
1613+
#ifNOT_USED
16141614
}
16151615
elseif ((type==RESERV)&& (val==DTK_EPOCH))
16161616
{
@@ -1678,7 +1678,7 @@ datetime_part(text *units, DateTime *datetime)
16781678

16791679
if (DATETIME_NOT_FINITE(*datetime))
16801680
{
1681-
#ifFALSE
1681+
#ifNOT_USED
16821682
/* should return null but Postgres doesn't like that currently. - tgl 97/06/12 */
16831683
elog(ERROR,"Datetime is not finite",NULL);
16841684
#endif
@@ -1843,7 +1843,7 @@ timespan_part(text *units, TimeSpan *timespan)
18431843

18441844
if (TIMESPAN_IS_INVALID(*timespan))
18451845
{
1846-
#ifFALSE
1846+
#ifNOT_USED
18471847
elog(ERROR,"Timespan is not finite",NULL);
18481848
#endif
18491849
*result=0;
@@ -1893,15 +1893,15 @@ timespan_part(text *units, TimeSpan *timespan)
18931893
break;
18941894

18951895
caseDTK_DECADE:
1896-
*result= (tm->tm_year /10)+1;
1896+
*result= (tm->tm_year /10);
18971897
break;
18981898

18991899
caseDTK_CENTURY:
1900-
*result= (tm->tm_year /100)+1;
1900+
*result= (tm->tm_year /100);
19011901
break;
19021902

19031903
caseDTK_MILLENIUM:
1904-
*result= (tm->tm_year /1000)+1;
1904+
*result= (tm->tm_year /1000);
19051905
break;
19061906

19071907
default:
@@ -2454,7 +2454,7 @@ datetime2tm(DateTime dt, int *tzp, struct tm * tm, double *fsec, char **tzn)
24542454
tm->tm_mday=tx->tm_mday;
24552455
tm->tm_hour=tx->tm_hour;
24562456
tm->tm_min=tx->tm_min;
2457-
#ifFALSE
2457+
#ifNOT_USED
24582458
/* XXX HACK
24592459
* Argh! My Linux box puts in a 1 second offset for dates less than 1970
24602460
*but only if the seconds field was non-zero. So, don't copy the seconds
@@ -2814,6 +2814,7 @@ DecodeDateTime(char **field, int *ftype, int nf,
28142814
intflen,
28152815
val;
28162816
intmer=HR24;
2817+
inthaveTextMonth= FALSE;
28172818
intis2digits= FALSE;
28182819
intbc= FALSE;
28192820

@@ -2955,14 +2956,23 @@ DecodeDateTime(char **field, int *ftype, int nf,
29552956
#ifdefDATEDEBUG
29562957
printf("DecodeDateTime- month field %s value is %d\n",field[i],val);
29572958
#endif
2959+
/* already have a (numeric) month? then see if we can substitute... */
2960+
if ((fmask&DTK_M(MONTH))&& (!haveTextMonth)
2961+
&& (!(fmask&DTK_M(DAY)))
2962+
&& ((tm->tm_mon >=1)&& (tm->tm_mon <=31)))
2963+
{
2964+
tm->tm_mday=tm->tm_mon;
2965+
tmask=DTK_M(DAY);
2966+
#ifdefDATEDEBUG
2967+
printf("DecodeNumber- misidentified month previously; assign as day %d\n",tm->tm_mday);
2968+
#endif
2969+
}
2970+
haveTextMonth= TRUE;
29582971
tm->tm_mon=val;
29592972
break;
29602973

2961-
/*
2962-
* daylight savings time modifier (solves "MET
2963-
* DST" syntax)
2964-
*/
29652974
caseDTZMOD:
2975+
/* daylight savings time modifier (solves "MET DST" syntax) */
29662976
tmask |=DTK_M(DTZ);
29672977
tm->tm_isdst=1;
29682978
if (tzp==NULL)
@@ -3466,17 +3476,14 @@ DecodeNumber(int flen, char *str, int fmask,
34663476
*tmask=DTK_M(YEAR);
34673477

34683478
/* already have a year? then see if we can substitute... */
3469-
if (fmask&DTK_M(YEAR))
3479+
if ((fmask&DTK_M(YEAR))&& (!(fmask&DTK_M(DAY)))
3480+
&& ((tm->tm_year >=1)&& (tm->tm_year <=31)))
34703481
{
3471-
if ((!(fmask&DTK_M(DAY)))
3472-
&& ((tm->tm_year >=1)&& (tm->tm_year <=31)))
3473-
{
3482+
tm->tm_mday=tm->tm_year;
3483+
*tmask=DTK_M(DAY);
34743484
#ifdefDATEDEBUG
3475-
printf("DecodeNumber- misidentified year previously;swap with day %d\n",tm->tm_mday);
3485+
printf("DecodeNumber- misidentified year previously;assign as day %d\n",tm->tm_mday);
34763486
#endif
3477-
tm->tm_mday=tm->tm_year;
3478-
*tmask=DTK_M(DAY);
3479-
}
34803487
}
34813488

34823489
tm->tm_year=val;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp