8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
25
25
#include "utils/guc.h"
26
26
#include "utils/datetime.h"
27
27
28
+
29
+ #define ROUND_ALL 1
30
+
28
31
static int DecodeNumber (int flen , char * field ,
29
32
int fmask , int * tmask ,
30
33
struct tm * tm , double * fsec , int * is2digits );
@@ -36,15 +39,12 @@ static int DecodeTime(char *str, int fmask, int *tmask,
36
39
static int DecodeTimezone (char * str , int * tzp );
37
40
static datetkn * datebsearch (char * key , datetkn * base , unsigned int nel );
38
41
static int DecodeDate (char * str , int fmask , int * tmask , struct tm * tm );
39
-
40
- #define ROUND_ALL 0
41
-
42
42
static int DecodePosixTimezone (char * str , int * val );
43
43
44
+
44
45
int day_tab [2 ][13 ] = {
45
46
{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 }};
48
48
49
49
char * months [] = {"Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" ,
50
50
"Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" , NULL };
@@ -53,28 +53,13 @@ char *days[] = {"Sunday", "Monday", "Tuesday", "Wednesday",
53
53
"Thursday" , "Friday" , "Saturday" , NULL };
54
54
55
55
56
- #define UTIME_MINYEAR (1901)
57
- #define UTIME_MINMONTH (12)
58
- #define UTIME_MINDAY (14)
59
- #define UTIME_MAXYEAR (2038)
60
- #define UTIME_MAXMONTH (01)
61
- #define UTIME_MAXDAY (18)
62
-
63
- #define IS_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
-
71
56
/*****************************************************************************
72
57
* PRIVATE ROUTINES *
73
58
*****************************************************************************/
74
59
75
60
/* definitions for squeezing values into "value" */
76
- #define ABS_SIGNBIT (char) 0200
77
- #define VALMASK (char) 0177
61
+ #define ABS_SIGNBIT (( char) 0200)
62
+ #define VALMASK (( char) 0177)
78
63
#define NEG (n ) ((n)|ABS_SIGNBIT)
79
64
#define SIGNEDCHAR (c ) ((c)&ABS_SIGNBIT? -((c)&VALMASK): (c))
80
65
#define FROMVAL (tp ) (-SIGNEDCHAR((tp)->value) * 10) /* uncompress */
@@ -2112,7 +2097,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
2112
2097
{
2113
2098
sprintf (str , "%04d-%02d-%02d %02d:%02d:" ,
2114
2099
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 );
2116
2101
2117
2102
if ((* tzn != NULL ) && (tm -> tm_isdst >= 0 ))
2118
2103
{
@@ -2154,11 +2139,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
2154
2139
tm -> tm_year , tm -> tm_hour , tm -> tm_min , sec );
2155
2140
2156
2141
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 );
2162
2143
}
2163
2144
else
2164
2145
sprintf ((str + 5 ), "/%04d %02d:%02d %s" ,
@@ -2174,11 +2155,7 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
2174
2155
tm -> tm_year , tm -> tm_hour , tm -> tm_min , sec );
2175
2156
2176
2157
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 );
2182
2159
}
2183
2160
else
2184
2161
sprintf ((str + 5 ), ".%04d %02d:%02d %s" ,
@@ -2206,21 +2183,14 @@ EncodeDateTime(struct tm * tm, double fsec, int *tzp, char **tzn, int style, cha
2206
2183
{
2207
2184
sprintf ((str + 16 ), ":%05.2f %04d" , sec , tm -> tm_year );
2208
2185
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 );
2213
2187
}
2214
2188
else
2215
2189
{
2216
2190
sprintf ((str + 16 ), ":%02.0f %04d" , sec , tm -> tm_year );
2217
2191
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 );
2222
2193
}
2223
-
2224
2194
}
2225
2195
else
2226
2196
{
0 commit comments