to_char("HH12") with intervals

Started by Bruce Momjianabout 16 years ago2 messageshackers
Jump to latest
#1Bruce Momjian
bruce@momjian.us

bruce wrote:

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.

We currently have this in our documentation:

<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.

This seems pretty confusing because HH/HH12 formats as hours in a single
1/2 day, 12 hours, and it really does wall-clock time, zero hours is 12,
and for intervals it does the right thing now and prints the interval
hours.

We also have these range definitions:

<row>
<entry><literal>HH12</literal></entry>
<entry>hour of day (01-12)</entry>
</row>
<row>
<entry><literal>HH24</literal></entry>
<entry>hour of day (00-23)</entry>
</row>

HH24 could always be > 24 for intervals, and now HH12 can too for
intervals.

What should be changed here?

-- 
  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. +
#2Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#1)
Re: to_char("HH12") with intervals

Bruce Momjian wrote:

bruce wrote:

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.

We currently have this in our documentation:

<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.

This seems pretty confusing because HH/HH12 formats as hours in a single
1/2 day, 12 hours, and it really does wall-clock time, zero hours is 12,
and for intervals it does the right thing now and prints the interval
hours.

We also have these range definitions:

<row>
<entry><literal>HH12</literal></entry>
<entry>hour of day (01-12)</entry>
</row>
<row>
<entry><literal>HH24</literal></entry>
<entry>hour of day (00-23)</entry>
</row>

HH24 could always be > 24 for intervals, and now HH12 can too for
intervals.

What should be changed here?

I have rethought this and now realize the original code was fine, but
the documentation was very unclear. I have reverted the patch and added
a C command and documentation updates with examples; attached.

-- 
  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. +

Attachments:

/rtmp/difftext/x-diffDownload+11-10