]> Savannah Git Hosting - gnulib.git/commit
parse-datetime: add debug warning about date arithmetic
authorAssaf Gordon <assafgordon@gmail.com>
Thu, 5 Jan 2017 04:11:33 +0000 (23:11 -0500)
committerAssaf Gordon <assafgordon@gmail.com>
Thu, 5 Jan 2017 05:08:06 +0000 (00:08 -0500)
commitf14eff1b3cde2bf8198b836ab4da05b4098358cb
tree57856d67db3bdb1253c55d2d7d2a410a01b5a7d3
parent5c438e8ce7d9c74078100700cb5faa15b4de23b8
parse-datetime: add debug warning about date arithmetic

Date arithmetic are done directly on the fields of 'struct tm',
which can result in invalid dates. Normalization with 'mktime(3)'
will then produce a different date - which might cause unexpected results.

Examples:
  '2016-10-31 - 1 month' => 2016-09-31 normalized to 2016-10-01.
  '2016-02-29 + 1 year'  => 2017-02-29 normalized to 2017-03-01.

Note that date normalization is not inherently wrong and not rejected,
as it has legitimate uses:
  '2016-12-29 + 5 days' => 2016-12-34 noramlized to 2017-01-03.

If the user asked to adjust months but 'mday' changed,
or user asked to adjust years but 'month' changed - warn about it.

    $ ./src/date --debug -d '2016-10-31 - 1 month'
    ...
    date: warning: when adding relative months/years, \
                   it is recommended to specify the 15th of the month
    ...
    date: warning: month/year adjustment resulted in shifted dates:
    date:      adjusted Y M D: 2016 09 31
    date:    normalized Y M D: 2010 10 01
    ...

* lib/parse-datetime.y (parse_datetime2): Detect such cases and print
a warning message. Improve recommendation of when to use 15 of the month
or noon for date arithmetic.
ChangeLog
lib/parse-datetime.y