Boost logo

Boost :

Subject: Re: [boost] [date_time] [#1861] Change for the default duration format
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-06-01 16:56:53


Andrey Semashev wrote:
On Monday, June 01, 2009 4:09 PM
> On Monday 01 June 2009 19:55:04 Stewart, Robert wrote:
>
> > > The initial problem was that the default handling of the %H
> > > format specifier (passing it to strftime) played badly with
> > > time durations that could be longer than 24 hours. The
> > > resolution was to provide additional %O format specifier
> > > that does not have 24 hour restriction.
> >
> > I suspect that's not common -- other than for the OP, perhaps.
>
> You think so? I don't know how often it is needed to operate
> longer durations,
> but IMHO, objectively there is no such restriction for time
> durations and the
> library should not artificially impose one.

Given that strftime() uses %OH is for alternative formats, %H is the norm. Consequently, %H seems an unsurprising and useful default for Boost.DateTime, too.

> > Jeff's
> > explanation in the associated list message implies that, too.
>
> What message do you mean?

This message was mentioned in the issue: http://lists.boost.org/Archives/boost/2007/12/131541.php

> > > However the original poster proposes to change the default
> > > format of time durations from %H:%M:%S%F to %O:%M:%S%F so
> > > that formatted durations are always allowed to be longer
> > > than 24 hours. I mostly agree with this change, however it
> > > is clearly a breaking change that can affect error checking
> > > in some cases.
> >
> > Changing the default will create surprises in some cases.
> I'd prefer to
> > see error checking -- an exception when the valid %H range
> is violated.
> > That would alert library users to the problem when violated and the
> > exception message could even suggest the need for %O (as
> should the docs,
> > of course).
> >
> > That would provide useful behavior for those violating the range
> > unknowingly and it would avoid breaking compatibility and,
> reasonable
> > expectations for users.
>
> The change mostly affects formatting. There already is an
> assert, so users
> will know if %H is used improperly. The assert is present since 1.38.

I question the use of an assert as that's not going to catch errors in runtime values in non-debug builds.

> The question is whether the change to %O as a default is
> justified enough and
> how it should be announced better.

Using %O in this way is odd, given the strftime() treatment of %O. I haven't looked at the implementation, but I assume that DateTime is interpreting the specifiers itself. If so, there's freedom available, but deviating from strftime() will make things more surprising than necessary. strftime() uses %E and %O as modifiers. Thus, there's precedence for using a capital letter for a modifier, but there aren't many from which to choose ATM: J, K, L, N, and Q. From those, I'd suggest L because %LH can be read as "long hour."

I contend that an exception (preceded by an assertion, if desired) for violating %H's range can indicate the need for the %L prefix. Then, the documentation for %H should mention %L's modification of %H's range.

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk