Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/func.sgml,v
retrieving revision 1.505
diff -c -c -r1.505 func.sgml
*** doc/src/sgml/func.sgml	19 Feb 2010 00:15:25 -0000	1.505
--- doc/src/sgml/func.sgml	23 Feb 2010 16:12:37 -0000
***************
*** 5317,5324 ****
       <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.
        </para>
       </listitem>
  
--- 5317,5325 ----
       <listitem>
        <para>
          <function>to_char(interval)</function> formats <literal>HH</> and
!         <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: src/backend/utils/adt/formatting.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v
retrieving revision 1.165
diff -c -c -r1.165 formatting.c
*** src/backend/utils/adt/formatting.c	23 Feb 2010 06:29:01 -0000	1.165
--- src/backend/utils/adt/formatting.c	23 Feb 2010 16:12:37 -0000
***************
*** 2088,2097 ****
  				break;
  			case DCH_HH:
  			case DCH_HH12:
  				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));
  				if (S_THth(n->suffix))
  					str_numth(s, s, S_TH_TYPE(n->suffix));
  				s += strlen(s);
--- 2088,2097 ----
  				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,
! 						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);
