3 June 2021 (In calibre version 5.21)
- Add the function date_arithmetic(date, calc_spec, fmt) to simplify computing new dates from existing ones. The documentation for the function is
Quote:
date_arithmetic(date, calc_spec, fmt) -- Calculate a new date from 'date' using 'calc_spec'. Return the new date formatted according to optional 'fmt'; if not supplied then the result will be in ISO format. The calc_spec is a string formed by concatenating pairs of 'vW' ('valueWhat') where 'v' is a possibly-negative number and W is one of the following letters:- 's': add 'v' seconds to 'date'
- 'm': add 'v' minutes to 'date'
- 'h': add 'v' hours to 'date'
- 'd': add 'v' days to 'date'
- 'w': add 'v' weeks to 'date'
- 'y': add 'v' years to 'date', where a year is 365 days.
Example: '1s3d-1m' will add 1 second, add 3 days, and subtract 1 minute from 'date'.
|
NB: you probably want to use a raw_field() or '$$date' to fetch the source date so you can be sure that all the fields are there.
And yes, the 'months' specifier is missing, because the number of days in a month depend on both the source date month and year. This is also why a year is fixed at 365 days.