@@ -3679,39 +3679,54 @@ EncodeDateOnly(struct pg_tm * tm, int style, char *str)
36793679
36803680/* EncodeTimeOnly()
36813681 * Encode time fields only.
3682+ *
3683+ * tm and fsec are the value to encode, print_tz determines whether to include
3684+ * a time zone (the difference between time and timetz types), tz is the
3685+ * numeric time zone offset, style is the date style, str is where to write the
3686+ * output.
36823687 */
36833688void
3684- EncodeTimeOnly (struct pg_tm * tm ,fsec_t fsec ,int * tzp ,int style ,char * str )
3689+ EncodeTimeOnly (struct pg_tm * tm ,fsec_t fsec ,bool print_tz , int tz ,int style ,char * str )
36853690{
36863691sprintf (str ,"%02d:%02d:" ,tm -> tm_hour ,tm -> tm_min );
36873692str += strlen (str );
36883693
36893694AppendSeconds (str ,tm -> tm_sec ,fsec ,MAX_TIME_PRECISION , true);
36903695
3691- if (tzp != NULL )
3692- EncodeTimezone (str ,* tzp ,style );
3696+ if (print_tz )
3697+ EncodeTimezone (str ,tz ,style );
36933698}
36943699
36953700
36963701/* EncodeDateTime()
36973702 * Encode date and time interpreted as local time.
3698- * Support several date styles:
3703+ *
3704+ * tm and fsec are the value to encode, print_tz determines whether to include
3705+ * a time zone (the difference between timestamp and timestamptz types), tz is
3706+ * the numeric time zone offset, tzn is the textual time zone, which if
3707+ * specified will be used instead of tz by some styles, style is the date
3708+ * style, str is where to write the output.
3709+ *
3710+ * Supported date styles:
36993711 *Postgres - day mon hh:mm:ss yyyy tz
37003712 *SQL - mm/dd/yyyy hh:mm:ss.ss tz
37013713 *ISO - yyyy-mm-dd hh:mm:ss+/-tz
37023714 *German - dd.mm.yyyy hh:mm:ss tz
37033715 *XSD - yyyy-mm-ddThh:mm:ss.ss+/-tz
3704- * Variants (affects order of month and day for Postgres and SQL styles):
3705- *US - mm/dd/yyyy
3706- *European - dd/mm/yyyy
37073716 */
37083717void
3709- EncodeDateTime (struct pg_tm * tm ,fsec_t fsec ,int * tzp , char * * tzn ,int style ,char * str )
3718+ EncodeDateTime (struct pg_tm * tm ,fsec_t fsec ,bool print_tz , int tz , const char * tzn ,int style ,char * str )
37103719{
37113720int day ;
37123721
37133722Assert (tm -> tm_mon >=1 && tm -> tm_mon <=MONTHS_PER_YEAR );
37143723
3724+ /*
3725+ * Negative tm_isdst means we have no valid time zone translation.
3726+ */
3727+ if (tm -> tm_isdst < 0 )
3728+ print_tz = false;
3729+
37153730switch (style )
37163731{
37173732case USE_ISO_DATES :
@@ -3729,14 +3744,8 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
37293744
37303745AppendTimestampSeconds (str + strlen (str ),tm ,fsec );
37313746
3732- /*
3733- * tzp == NULL indicates that we don't want *any* time zone info
3734- * in the output string. *tzn != NULL indicates that we have alpha
3735- * time zone info available. tm_isdst != -1 indicates that we have
3736- * a valid time zone translation.
3737- */
3738- if (tzp != NULL && tm -> tm_isdst >=0 )
3739- EncodeTimezone (str ,* tzp ,style );
3747+ if (print_tz )
3748+ EncodeTimezone (str ,tz ,style );
37403749
37413750if (tm -> tm_year <=0 )
37423751sprintf (str + strlen (str )," BC" );
@@ -3762,12 +3771,12 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
37623771 * TZ abbreviations in the Olson database are plain ASCII.
37633772 */
37643773
3765- if (tzp != NULL && tm -> tm_isdst >= 0 )
3774+ if (print_tz )
37663775{
3767- if (* tzn != NULL )
3768- sprintf (str + strlen (str )," %.*s" ,MAXTZLEN ,* tzn );
3776+ if (tzn )
3777+ sprintf (str + strlen (str )," %.*s" ,MAXTZLEN ,tzn );
37693778else
3770- EncodeTimezone (str ,* tzp ,style );
3779+ EncodeTimezone (str ,tz ,style );
37713780}
37723781
37733782if (tm -> tm_year <=0 )
@@ -3785,12 +3794,12 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
37853794
37863795AppendTimestampSeconds (str + strlen (str ),tm ,fsec );
37873796
3788- if (tzp != NULL && tm -> tm_isdst >= 0 )
3797+ if (print_tz )
37893798{
3790- if (* tzn != NULL )
3791- sprintf (str + strlen (str )," %.*s" ,MAXTZLEN ,* tzn );
3799+ if (tzn )
3800+ sprintf (str + strlen (str )," %.*s" ,MAXTZLEN ,tzn );
37923801else
3793- EncodeTimezone (str ,* tzp ,style );
3802+ EncodeTimezone (str ,tz ,style );
37943803}
37953804
37963805if (tm -> tm_year <=0 )
@@ -3819,10 +3828,10 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
38193828sprintf (str + strlen (str )," %04d" ,
38203829(tm -> tm_year > 0 ) ?tm -> tm_year :- (tm -> tm_year - 1 ));
38213830
3822- if (tzp != NULL && tm -> tm_isdst >= 0 )
3831+ if (print_tz )
38233832{
3824- if (* tzn != NULL )
3825- sprintf (str + strlen (str )," %.*s" ,MAXTZLEN ,* tzn );
3833+ if (tzn )
3834+ sprintf (str + strlen (str )," %.*s" ,MAXTZLEN ,tzn );
38263835else
38273836{
38283837/*
@@ -3832,7 +3841,7 @@ EncodeDateTime(struct pg_tm * tm, fsec_t fsec, int *tzp, char **tzn, int style,
38323841 * the date/time parser later. - thomas 2001-10-19
38333842 */
38343843sprintf (str + strlen (str )," " );
3835- EncodeTimezone (str ,* tzp ,style );
3844+ EncodeTimezone (str ,tz ,style );
38363845}
38373846}
38383847