BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc

From: "Tomislav Bodor" <tbodor(at)yahoo(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4623: %s pattern broken in PGTYPEStimestamp_defmt_asc
Date: 2009-01-23 00:56:12
Message-ID: 200901230056.n0N0uCOs059165@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4623
Logged by: Tomislav Bodor
Email address: tbodor(at)yahoo(dot)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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander 2009-01-23 09:15:48 BUG #4624: pg_restore
Previous Message Bruce Momjian 2009-01-22 22:58:26 Re: [BUGS] Status of issue 4593