Thread: BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc

BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc

From
"Tomislav Bodor"
Date:
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

Re: *****SPAM***** BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc

From
Michael Meskes
Date:
Sorry, for the long time before I answer, but this email, like others, was
caught by my spam filter. Spamassassin doesn't like mail hubs calling
themselves localhost. Sigh.

> Support for %s format is broken in PGTYPEStimestamp_defmt_asc.

Fixed in CVS HEAD. Thanks for the report.

Michael

--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!