OSDN Git Service

Revert recent change of to_char('HH12') handling for intervals; instead
authorBruce Momjian <bruce@momjian.us>
Tue, 23 Feb 2010 16:14:26 +0000 (16:14 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 23 Feb 2010 16:14:26 +0000 (16:14 +0000)
improve documentation, and add C comment.

doc/src/sgml/func.sgml
src/backend/utils/adt/formatting.c

index 52049e7..689cd34 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.505 2010/02/19 00:15:25 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.506 2010/02/23 16:14:25 momjian Exp $ -->
 
  <chapter id="functions">
   <title>Functions and Operators</title>
@@ -5317,8 +5317,9 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
      <listitem>
       <para>
         <function>to_char(interval)</function> formats <literal>HH</> and
-        <literal>HH12</> as hours in a single day, while <literal>HH24</>
-        can output hours exceeding a single day, e.g., &gt;24.
+        <literal>HH12</> as shown on a 12-hour clock, i.e. zero hours
+        and 36 hours output as <literal>12</>, while <literal>HH24</>
+        outputs the full hour value, which can exceed 23 for intervals.
       </para>
      </listitem>
 
index a41f6f1..af764e8 100644 (file)
@@ -1,7 +1,7 @@
 /* -----------------------------------------------------------------------
  * formatting.c
  *
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.165 2010/02/23 06:29:01 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.166 2010/02/23 16:14:26 momjian Exp $
  *
  *
  *      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)
                                break;
                        case DCH_HH:
                        case DCH_HH12:
+                               /* display time as shown on a 12-hour clock, even for intervals */
                                sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2,
-                                               is_interval ? tm->tm_hour :
-                                               tm->tm_hour % (HOURS_PER_DAY / 2) == 0 ?
-                                               12 : tm->tm_hour % (HOURS_PER_DAY / 2));
+                                               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, S_TH_TYPE(n->suffix));
                                s += strlen(s);