On 15/03/17 05:44, Eric Blake wrote: > On 03/15/2017 07:23 AM, Ulf Zibis wrote: > >> >> A more simple example without touch: >> $ date +%F >> 2017-03-15 >> $ date -d "-20 day" +%F >> 2017-02-23 >> $ date -d "-20 day -2 month" +%F >> 2016-12-26 >> $ date -d "-2 month -20 day" +%F >> 2016-12-26 >> >> In the 2nd example I would expect: >> 2016-12-23 > > Why? Both operations are computing: Subtract 20 days, and subtract 2 > months (equivalent to 60 days). Subtraction is commutative, it doesn't > matter which one you subtract first, if you are doing two subtractions. > > Maybe you are confused on how date implements "subtract a month". It > does NOT do "subtract 28, 29, 30, or 31 days as appropriate", but rather > does "subtract 30 days, for lack of anything better to do". Maybe it > could, but someone would have to write the patch. Relative dates are > HARD to compute, which is why --debug included this warning:
Yes that's an awkward gotcha (I'm not sure is related to the OP's issue). I outlined a solution at http://bugs.gnu.org/18159#8 I didn't document in "coreutils gotchas" as it's covered in "coreutils FAQ", though it might deserve a discussion there. cheers, Pádraig
