strftime %y and negative years
James R. Van Zandt
jrvz at comcast.net
Fri Sep 10 01:10:28 UTC 2004
"Clive D.W. Feather" <clive at demon.net> writes:
>The glibc and OpenBSD behaviours appear to be using the % operator. This is
>defined by:
>
> the expression (a/b)*b + a%b shall equal a.
>
>If b is positive (here, it's 100) and a is negative, there are two
>possibilities in C90:
>
>(1) a/b rounds towards zero (this is required in C99) and a%b is negative.
> This is what OpenBSD appears to be doing, with a = tm_year - 1900.
>(2) a/b rounds towards more negative numbers and a%b is positive. This is
> actually the behaviour I prefer, but regrettably it's not available
> in a simple way in C99. This is what glibc is doing.
I agree with your preference. In fact, I have never found an
application for (1). I expect the only reason (2) was ever accepted is
that it's easy to implement with common hardware. There used to be a
lot of lame floating point implementations around for the same reason.
It's a really poor reason for standardizing on (2), though.
- Jim Van Zandt
More information about the tz
mailing list