Skip to content

Commit a548031

Browse files
committed
Revert recent change of to_char('HH12') handling for intervals; instead
improve documentation, and add C comment.
1 parent 4f56dc3 commit a548031

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

doc/src/sgml/func.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.505 2010/02/19 00:15:25 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.506 2010/02/23 16:14:25 momjian Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -5317,8 +5317,9 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
53175317
<listitem>
53185318
<para>
53195319
<function>to_char(interval)</function> formats <literal>HH</> and
5320-
<literal>HH12</> as hours in a single day, while <literal>HH24</>
5321-
can output hours exceeding a single day, e.g., &gt;24.
5320+
<literal>HH12</> as shown on a 12-hour clock, i.e. zero hours
5321+
and 36 hours output as <literal>12</>, while <literal>HH24</>
5322+
outputs the full hour value, which can exceed 23 for intervals.
53225323
</para>
53235324
</listitem>
53245325

src/backend/utils/adt/formatting.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.165 2010/02/23 06:29:01 momjian Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.166 2010/02/23 16:14:26 momjian Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2010, PostgreSQL Global Development Group
@@ -2088,10 +2088,10 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
20882088
break;
20892089
case DCH_HH:
20902090
case DCH_HH12:
2091+
/* display time as shown on a 12-hour clock, even for intervals */
20912092
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2,
2092-
is_interval ? tm->tm_hour :
2093-
tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ?
2094-
12 : tm->tm_hour % (HOURS_PER_DAY / 2));
2093+
tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ? 12 :
2094+
tm->tm_hour % (HOURS_PER_DAY / 2));
20952095
if (S_THth(n->suffix))
20962096
str_numth(s, s, S_TH_TYPE(n->suffix));
20972097
s += strlen(s);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy