Quote:
Originally Posted by ownedbycats
I hope it doesn't break if a date is set to February 29, 2020. I'm testing it myself but still working out how the syntax works.
|
It won't break if the date ends up being on 29 Feb of a leap year. For example, 28 Feb 2020 + (1 day) will produce 29 Feb 2020. The date 28 Feb 2021 + (1 day) will produce 1 Mar 2021
By not supporting leap year I mean that with the exception of years, no calculation requires knowledge of whether 29 Feb (
EDIT: or any other day of the month) matters. That is why there is no "month" calculation specifier, because the calculation can change when going over a leap February (
EDIT: or if the current day doesn't exist in the target month). The problem is finessed for "years" by defining a year as 365 days, which given a valid date can never generate an invalid date, but the result might be a day short.
The syntax is straightforward: pairs of (numbers followed by a letter). The order is not important. Examples:
- -10w: subtract 10 weeks.
- 3d-1y: add 3 days and subtract 1 year.
- -1y3d-10w: subtract one year, add 3 days, then subtract 10 weeks.