7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.1.1.1 1996/07/09 06:22:03 scrappy Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/datetimes.c,v 1.2 1996/07/19 07:19:56 scrappy Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -57,11 +57,15 @@ date_in(char *datestr)
57
57
int4 result ;
58
58
DateADT * date = (DateADT * )& result ;
59
59
60
+ #if 0
60
61
#ifdef USE_SHORT_YEAR
61
62
#define CHECK_DATE_LEN (datestr ) (strlen(datestr) >= 8)
62
63
#else
63
64
#define CHECK_DATE_LEN (datestr ) (strlen(datestr) == 10)
64
65
#endif /* USE_SHORT_YEAR */
66
+ #else
67
+ #define CHECK_DATE_LEN (datestr ) 1
68
+ #endif
65
69
66
70
#ifdef AMERICAN_STYLE
67
71
if (!CHECK_DATE_LEN (datestr ) ||
@@ -76,6 +80,8 @@ date_in(char *datestr)
76
80
datestr );
77
81
}
78
82
#endif
83
+ if (y < 0 || y > 32767 )
84
+ elog (WARN , "date_in: year must be limited to values 0 through 32767 in \"%s\"" , datestr );
79
85
if (m < 1 || m > 12 )
80
86
elog (WARN , "date_in: month must be limited to values 1 through 12 in \"%s\"" , datestr );
81
87
if (d < 1 || d > day_tab [isleap (y )][m - 1 ])
@@ -247,16 +253,19 @@ time_in(char *timestr)
247
253
TimeADT * time ;
248
254
249
255
if (sscanf (timestr , "%d%*c%d%*c%f" , & h , & m , & sec ) != 3 ) {
250
- elog (WARN , "time_in: time \"%s\" not of the form hh:mm:ss" ,
251
- timestr );
256
+ sec = 0.0 ;
257
+ if (sscanf (timestr , "%d%*c%d" , & h , & m ) != 2 ) {
258
+ elog (WARN , "time_in: time \"%s\" not of the form hh:mm:ss" ,
259
+ timestr );
260
+ }
252
261
}
253
262
254
263
if (h < 0 || h > 23 )
255
264
elog (WARN , "time_in: hour must be limited to values 0 through 23 in \"%s\"" , timestr );
256
265
if (m < 0 || m > 59 )
257
266
elog (WARN , "time_in: minute must be limited to values 0 through 59 in \"%s\"" , timestr );
258
- if (sec < 0 || sec >= 62 .0 )
259
- elog (WARN , "time_in: second must be limited to values 0 through 61.99 in \"%s\"" , timestr );
267
+ if (sec < 0 || sec >= 60 .0 )
268
+ elog (WARN , "time_in: second must be limited to values 0 through 59.999 in \"%s\"" , timestr );
260
269
261
270
time = (TimeADT * )palloc (sizeof (TimeADT ));
262
271
time -> hr = h ;
@@ -268,10 +277,24 @@ time_in(char *timestr)
268
277
char *
269
278
time_out (TimeADT * time )
270
279
{
271
- char * timestr = palloc (16 );
272
-
273
- sprintf (timestr , "%02d:%02d:%09.6f" ,
274
- (int )time -> hr , (int )time -> min , time -> sec );
280
+ char * timestr = palloc (32 );
281
+ int n ;
282
+ float f ;
283
+
284
+ if (time -> sec == 0.0 ) {
285
+ sprintf (timestr , "%02d:%02d" ,
286
+ (int )time -> hr , (int )time -> min );
287
+ } else {
288
+ n = (int )time -> sec ;
289
+ f = (float )n ;
290
+ if (f == time -> sec ) {
291
+ sprintf (timestr , "%02d:%02d:%02d" ,
292
+ (int )time -> hr , (int )time -> min , n );
293
+ } else {
294
+ sprintf (timestr , "%02d:%02d:%09.6f" ,
295
+ (int )time -> hr , (int )time -> min , time -> sec );
296
+ }
297
+ }
275
298
276
299
return timestr ;
277
300
}
0 commit comments