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

Commit975da0a

Browse files
committed
Remove formatter's assumption that year would never exceed four digits.
Enforce MAXTZLEN for all datestyles, not just some. Remove macrodefinitions that were redundant with datetime.h.
1 parentb1f10c8 commit975da0a

File tree

1 file changed

+13
-43
lines changed

1 file changed

+13
-43
lines changed

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

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.65 2001/06/18 16:14:43 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.66 2001/07/10 01:41:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,6 +25,9 @@
2525
#include"utils/guc.h"
2626
#include"utils/datetime.h"
2727

28+
29+
#defineROUND_ALL 1
30+
2831
staticintDecodeNumber(intflen,char*field,
2932
intfmask,int*tmask,
3033
structtm*tm,double*fsec,int*is2digits);
@@ -36,15 +39,12 @@ static int DecodeTime(char *str, int fmask, int *tmask,
3639
staticintDecodeTimezone(char*str,int*tzp);
3740
staticdatetkn*datebsearch(char*key,datetkn*base,unsignedintnel);
3841
staticintDecodeDate(char*str,intfmask,int*tmask,structtm*tm);
39-
40-
#defineROUND_ALL 0
41-
4242
staticintDecodePosixTimezone(char*str,int*val);
4343

44+
4445
intday_tab[2][13]= {
4546
{31,28,31,30,31,30,31,31,30,31,30,31,0},
46-
{31,29,31,30,31,30,31,31,30,31,30,31,0}};
47-
47+
{31,29,31,30,31,30,31,31,30,31,30,31,0}};
4848

4949
char*months[]= {"Jan","Feb","Mar","Apr","May","Jun",
5050
"Jul","Aug","Sep","Oct","Nov","Dec",NULL};
@@ -53,28 +53,13 @@ char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
5353
"Thursday","Friday","Saturday",NULL};
5454

5555

56-
#defineUTIME_MINYEAR (1901)
57-
#defineUTIME_MINMONTH (12)
58-
#defineUTIME_MINDAY (14)
59-
#defineUTIME_MAXYEAR (2038)
60-
#defineUTIME_MAXMONTH (01)
61-
#defineUTIME_MAXDAY (18)
62-
63-
#defineIS_VALID_UTIME(y,m,d) (((y > UTIME_MINYEAR) \
64-
|| ((y == UTIME_MINYEAR) && ((m > UTIME_MINMONTH) \
65-
|| ((m == UTIME_MINMONTH) && (d >= UTIME_MINDAY))))) \
66-
&& ((y < UTIME_MAXYEAR) \
67-
|| ((y == UTIME_MAXYEAR) && ((m < UTIME_MAXMONTH) \
68-
|| ((m == UTIME_MAXMONTH) && (d <= UTIME_MAXDAY))))))
69-
70-
7156
/*****************************************************************************
7257
* PRIVATE ROUTINES *
7358
*****************************************************************************/
7459

7560
/* definitions for squeezing values into "value" */
76-
#defineABS_SIGNBIT(char) 0200
77-
#defineVALMASK(char) 0177
61+
#defineABS_SIGNBIT((char) 0200)
62+
#defineVALMASK((char) 0177)
7863
#defineNEG(n)((n)|ABS_SIGNBIT)
7964
#defineSIGNEDCHAR(c)((c)&ABS_SIGNBIT? -((c)&VALMASK): (c))
8065
#defineFROMVAL(tp)(-SIGNEDCHAR((tp)->value) * 10)/* uncompress */
@@ -2112,7 +2097,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
21122097
{
21132098
sprintf(str,"%04d-%02d-%02d %02d:%02d:",
21142099
tm->tm_year,tm->tm_mon,tm->tm_mday,tm->tm_hour,tm->tm_min);
2115-
sprintf((str+17), ((fsec!=0) ?"%05.2f" :"%02.0f"),sec);
2100+
sprintf((str+strlen(str)), ((fsec!=0) ?"%05.2f" :"%02.0f"),sec);
21162101

21172102
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
21182103
{
@@ -2154,11 +2139,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
21542139
tm->tm_year,tm->tm_hour,tm->tm_min,sec);
21552140

21562141
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
2157-
{
2158-
strcpy((str+22)," ");
2159-
strcpy((str+23),*tzn);
2160-
}
2161-
2142+
sprintf((str+strlen(str))," %.*s",MAXTZLEN,*tzn);
21622143
}
21632144
else
21642145
sprintf((str+5),"/%04d %02d:%02d %s",
@@ -2174,11 +2155,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
21742155
tm->tm_year,tm->tm_hour,tm->tm_min,sec);
21752156

21762157
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
2177-
{
2178-
strcpy((str+22)," ");
2179-
strcpy((str+23),*tzn);
2180-
}
2181-
2158+
sprintf((str+strlen(str))," %.*s",MAXTZLEN,*tzn);
21822159
}
21832160
else
21842161
sprintf((str+5),".%04d %02d:%02d %s",
@@ -2206,21 +2183,14 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
22062183
{
22072184
sprintf((str+16),":%05.2f %04d",sec,tm->tm_year);
22082185
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
2209-
{
2210-
strcpy((str+27)," ");
2211-
StrNCpy((str+28),*tzn,MAXTZLEN+1);
2212-
}
2186+
sprintf((str+strlen(str))," %.*s",MAXTZLEN,*tzn);
22132187
}
22142188
else
22152189
{
22162190
sprintf((str+16),":%02.0f %04d",sec,tm->tm_year);
22172191
if ((*tzn!=NULL)&& (tm->tm_isdst >=0))
2218-
{
2219-
strcpy((str+24)," ");
2220-
StrNCpy((str+25),*tzn,MAXTZLEN+1);
2221-
}
2192+
sprintf((str+strlen(str))," %.*s",MAXTZLEN,*tzn);
22222193
}
2223-
22242194
}
22252195
else
22262196
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp