8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.177 2007/02/19 17:41:39 momjian Exp $
11
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.178 2007/03/01 14:52:03 petere Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -3153,7 +3153,7 @@ datebsearch(const char *key, const datetkn *base, int nel)
3153
3153
* Append representation of a numeric timezone offset to str.
3154
3154
*/
3155
3155
static void
3156
- EncodeTimezone (char * str , int tz )
3156
+ EncodeTimezone (char * str , int tz , int style )
3157
3157
{
3158
3158
int hour ,
3159
3159
min ,
@@ -3171,7 +3171,7 @@ EncodeTimezone(char *str, int tz)
3171
3171
3172
3172
if (sec != 0 )
3173
3173
sprintf (str , "%02d:%02d:%02d" , hour , min , sec );
3174
- else if (min != 0 )
3174
+ else if (min != 0 || style == USE_XSD_DATES )
3175
3175
sprintf (str , "%02d:%02d" , hour , min );
3176
3176
else
3177
3177
sprintf (str , "%02d" , hour );
@@ -3189,6 +3189,7 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
3189
3189
switch (style )
3190
3190
{
3191
3191
case USE_ISO_DATES :
3192
+ case USE_XSD_DATES :
3192
3193
/* compatible with ISO date formats */
3193
3194
if (tm -> tm_year > 0 )
3194
3195
sprintf (str , "%04d-%02d-%02d" ,
@@ -3266,7 +3267,7 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
3266
3267
sprintf (str + strlen (str ), ":%02d" , tm -> tm_sec );
3267
3268
3268
3269
if (tzp != NULL )
3269
- EncodeTimezone (str , * tzp );
3270
+ EncodeTimezone (str , * tzp , style );
3270
3271
3271
3272
return TRUE;
3272
3273
} /* EncodeTimeOnly() */
@@ -3279,6 +3280,7 @@ EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, int *tzp, int style, char *str)
3279
3280
* SQL - mm/dd/yyyy hh:mm:ss.ss tz
3280
3281
* ISO - yyyy-mm-dd hh:mm:ss+/-tz
3281
3282
* German - dd.mm.yyyy hh:mm:ss tz
3283
+ * XSD - yyyy-mm-ddThh:mm:ss.ss+/-tz
3282
3284
* Variants (affects order of month and day for Postgres and SQL styles):
3283
3285
* US - mm/dd/yyyy
3284
3286
* European - dd/mm/yyyy
@@ -3297,11 +3299,18 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
3297
3299
switch (style )
3298
3300
{
3299
3301
case USE_ISO_DATES :
3302
+ case USE_XSD_DATES :
3300
3303
/* Compatible with ISO-8601 date formats */
3301
3304
3302
- sprintf (str , "%04d-%02d-%02d %02d:%02d" ,
3305
+ if (style == USE_ISO_DATES )
3306
+ sprintf (str , "%04d-%02d-%02d %02d:%02d" ,
3303
3307
(tm -> tm_year > 0 ) ? tm -> tm_year : - (tm -> tm_year - 1 ),
3304
3308
tm -> tm_mon , tm -> tm_mday , tm -> tm_hour , tm -> tm_min );
3309
+ else
3310
+ sprintf (str , "%04d-%02d-%02dT%02d:%02d" ,
3311
+ (tm -> tm_year > 0 ) ? tm -> tm_year : - (tm -> tm_year - 1 ),
3312
+ tm -> tm_mon , tm -> tm_mday , tm -> tm_hour , tm -> tm_min );
3313
+
3305
3314
3306
3315
/*
3307
3316
* Print fractional seconds if any. The field widths here should
@@ -3333,7 +3342,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
3333
3342
* a valid time zone translation.
3334
3343
*/
3335
3344
if (tzp != NULL && tm -> tm_isdst >= 0 )
3336
- EncodeTimezone (str , * tzp );
3345
+ EncodeTimezone (str , * tzp , style );
3337
3346
3338
3347
if (tm -> tm_year <= 0 )
3339
3348
sprintf (str + strlen (str ), " BC" );
@@ -3379,7 +3388,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
3379
3388
if (* tzn != NULL )
3380
3389
sprintf (str + strlen (str ), " %.*s" , MAXTZLEN , * tzn );
3381
3390
else
3382
- EncodeTimezone (str , * tzp );
3391
+ EncodeTimezone (str , * tzp , style );
3383
3392
}
3384
3393
3385
3394
if (tm -> tm_year <= 0 )
@@ -3423,7 +3432,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
3423
3432
if (* tzn != NULL )
3424
3433
sprintf (str + strlen (str ), " %.*s" , MAXTZLEN , * tzn );
3425
3434
else
3426
- EncodeTimezone (str , * tzp );
3435
+ EncodeTimezone (str , * tzp , style );
3427
3436
}
3428
3437
3429
3438
if (tm -> tm_year <= 0 )
@@ -3486,7 +3495,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
3486
3495
* the date/time parser later. - thomas 2001-10-19
3487
3496
*/
3488
3497
sprintf (str + strlen (str ), " " );
3489
- EncodeTimezone (str , * tzp );
3498
+ EncodeTimezone (str , * tzp , style );
3490
3499
}
3491
3500
}
3492
3501
0 commit comments