Method Deck / dates

Add days to a date

Adds (or subtracts, for a negative count) a whole number of days to a calendar date.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Parse the date as a proleptic Gregorian civil date.
  2. Convert it to a day-number using the Hinnant days_from_civil algorithm (cited above).
  3. Add the signed integer days to the day-number.
  4. Convert the resulting day-number back to a civil (year, month, day) using the inverse civil_from_days algorithm.
  5. Format the result as an ISO 8601 date.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"date":"2024-01-01","days":31}2024-02-01
test vector: leap day backward{"date":"2024-03-01","days":-1}2024-02-29
test vector: year rollover{"date":"2023-12-31","days":1}2024-01-01

Published card