TH to_char modifier doesn't work with HH12 - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject TH to_char modifier doesn't work with HH12
Date
Msg-id 4A5222C1.9030607@enterprisedb.com
Whole thread Raw
Responses Re: TH to_char modifier doesn't work with HH12  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-bugs by date:

Previous
From: wstrzalka
Date:
Subject: Re: Unknown winsock error 10061
Next
From: Tom Lane
Date:
Subject: Re: TH to_char modifier doesn't work with HH12