TH to_char modifier doesn't work with HH12

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: TH to_char modifier doesn't work with HH12
Date: 2009-07-06 16:13:53
Message-ID: 4A5222C1.9030607@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The uppercase 'TH' modifier is not working with HH12:

template1=# select to_char('3-MAY-2007 2:34'::timestamptz,'FMHHTH" HOUR
OF THE "FMDDTH" DAY WAS ILL-FATED'::text);
to_char
---------------------------------------
2nd HOUR OF THE 3RD DAY WAS ILL-FATED
(1 row)

Looking at the code, that looks like an oversight and the fix is trivial:

--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -2094,7 +2094,7 @@ DCH_to_char(FormatNode *node, bool is_interval,
TmToChar *
tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ? 12 :
tm->tm_hour % (HOURS_PER_DAY / 2));
if (S_THth(n->suffix))
- str_numth(s, s, 0);
+ str_numth(s, s, S_TH_TYPE(n->suffix));
s += strlen(s);
break;
case DCH_HH24:

But given that it has been like that at least back to 8.0 which is the
oldest version I have installed right now: does anyone see a reason not
to fix that?

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Headland 2009-07-06 16:40:44 Re: BUG #4899: Open parenthesis breaks query plan
Previous Message wstrzalka 2009-07-06 14:00:03 Re: Unknown winsock error 10061