BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc - Mailing list pgsql-bugs

From Tomislav Bodor
Subject BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc
Date
Msg-id 200901230056.n0N0uCOs059165@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: *****SPAM***** BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc  (Michael Meskes <meskes@postgresql.org>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      4623
Logged by:          Tomislav Bodor
Email address:      tbodor@yahoo.com
PostgreSQL version: 8.3.5
Operating system:   Linux, Ubuntu 8.10
Description:        %s pattern broken in PGTYPEStimestamp_defmt_asc
Details:

Support for %s format is broken in PGTYPEStimestamp_defmt_asc.

Simple test case:

char buffer[128];
snprintf(buffer, sizeof(buffer), "%u", (unsigned int) time(NULL));
timestamp ts;
PGTYPEStimestamp_defmt_asc(buffer, "%s", &ts);

The call to PGTYPEStimestamp_defmt_asc returns 1 and sets ts to an invalid
timestamp (when converted to string using PGTYPEStimestamp_to_asc, I get
'0108-11-30 00:43:48' for what should be '2009-01-23 ...'.

The reason is incorrect interpretation of results of a call to gmtime in the
implementation of %s pattern (PGTYPEStimestamp_defmt_scan, dt_common.c). In
the rest of the patterns, month is 1-based (January==1), but in
implementation of %s pattern, it is 0-based, after the call to gmtime. In
addition, gmtime returns year since 1900, so in order to get the full year,
1900 needs to be added to what gmtime returns.

This should be trivial to fix, but if you would like me to supply a patch,
please let me know.


Regards,
Tomislav

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: BUG #4622: xpath only work in utf-8 server encoding
Next
From: "Alexander"
Date:
Subject: BUG #4624: pg_restore