[Toybox] [PATCH] Fix year parsing in date(1).

enh enh at google.com
Thu Nov 12 20:32:51 PST 2015


thanks. that's got people off my back.

i did notice while testing 4-digit years (which is what the bug report
was about) that 2-digit years don't work as you intended them to
either. (the behavior didn't seem entirely unreasonable to me, because
what kind of person uses two digit years anyway?)

anyway, three missing test cases:
1. if a 0-digit year is supplied, the year should be the current year.
right now it's 1900.
2. the 2-digit year 75 should be "1975".
3. the 2-digit year 16 should be "2016".

these all boil down to this comment being wrong:

  // If year specified, overwrite one we fetched earlier

maybe at some point you had fetched a year earlier, but currently at
this point, tm_year is 0. (because the last thing that happened to the
struct tm was that it was memset to 0.)

i started to write a patch, but realized i'd rather just disallow
2-digit years. i'm assuming that -- even though POSIX's explicit
specification of which years are past and which are future is a bit
crazy -- you don't want to deviate from POSIX so far that you just
reject 2-digit years? (though that might be a less problematic
incompatibility than having a different interpretation of
past/future?)

On Thu, Nov 12, 2015 at 8:33 AM, enh <enh at google.com> wrote:
> ping? (since this was a reported bug from a test team i'd like to get
> this in this week's sync.)
>
> On Tue, Nov 10, 2015 at 6:25 PM, enh <enh at google.com> wrote:
>> Four-digit years were being mangled by the code for two-digit years.
>> Move all the two-digit year code into the "we only saw two digits" case.
>>
>> Add some new tests and fix existing tests.
>> ---
>>  tests/date.test   |  8 ++++++--
>>  toys/posix/date.c | 10 ++++++----
>>  2 files changed, 12 insertions(+), 6 deletions(-)
>>
>> --
>> Elliott Hughes - http://who/enh - http://jessies.org/~enh/
>> Android native code/tools questions? Mail me/drop by/add me as a reviewer.
>
>
>
> --
> Elliott Hughes - http://who/enh - http://jessies.org/~enh/
> Android native code/tools questions? Mail me/drop by/add me as a reviewer.



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.

 1447389171.0


More information about the Toybox mailing list