strftime %y and negative years

Clive D.W. Feather clive at demon.net
Wed Aug 25 09:23:45 UTC 2004


Paul Eggert said:
>> Note, by the way, that strftime is only supposed to work when the relevant
>> fields are in their "normal range". No such range is given for tm_year.
> I intepret this to mean that strftime is supposed to work regardless
> of the value of tm_year.

I would agree.

> However, the standard says that %C always generates a value in the
> range [00,99] so it would appear there's an inconsistency here.

Also agreed.

> I
> suppose one could argue that %C has undefined behavior for years
> outside the range [0, 9999].  But this appears to me to be a defect in
> the standard -- at least, things are quite unclear here.  I would
> prefer it if strftime were required to handle all tm_year values.

So would I, but persuading WG14 might be harder.

> There is no similar restriction on the range for %Y, which suggests
> that strftime %Y must handle all tm_year values.
> 
> For %y the range is [00,99], which argues for using modulus rather
> than remainder.

All that says is that the value must be in that range. A system that
generates %C "-2" %y "34" for the year -234 (235 B.C.) would, I think,
conform.

> Here's a test program you can use to try out your implementation.

FreeBSD appears to do the same as OpenBSD.

-- 
Clive D.W. Feather  | Work:  <clive at demon.net>   | Tel:    +44 20 8495 6138
Internet Expert     | Home:  <clive at davros.org>  | Fax:    +44 870 051 9937
Demon Internet      | WWW: http://www.davros.org | Mobile: +44 7973 377646
Thus plc            |                            |



More information about the tz mailing list