bruce wrote:
> Dave Page wrote:
> > This was posted as a documentation comment:
> >
> > to_char(interval '0d 0h 12m 44s', 'DD HH MI SS');
> > with HH and HH12 will return 12 instead of 0.
> >
> > Testing on 8.4.1, it does seem to be the case that you get "00 12 12
> > 44". Seems bogus to me, but am I and the OP missing something?
>
> Fixed with the attached patch. I think HH and HH24 should be the same
> for intervals. It is hard to explain why zero hours should show as
> '12' for intervals.
Oops, I needed a second patch to fix hours > 12 for intervals. Patch
attached and applied. It will now report the full hours of the
interval.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
PG East: http://www.enterprisedb.com/community/nav-pg-east-2010.do
+ If your life is a hard drive, Christ can be your backup. +
Index: src/backend/utils/adt/formatting.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v
retrieving revision 1.164
diff -c -c -r1.164 formatting.c
*** src/backend/utils/adt/formatting.c 23 Feb 2010 01:42:19 -0000 1.164
--- src/backend/utils/adt/formatting.c 23 Feb 2010 06:25:59 -0000
***************
*** 2089,2095 ****
case DCH_HH:
case DCH_HH12:
sprintf(s, "%0*d", S_FM(n->suffix) ? 0 : 2,
! !is_interval && 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));
--- 2089,2096 ----
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));