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
- date (string, required) : ISO 8601 starting date, YYYY-MM-DD
- days (integer, required) : Number of days to add; negative subtracts days
Outputs
- result_date: The resulting ISO 8601 date
Steps
- Parse the date as a proleptic Gregorian civil date.
- Convert it to a day-number using the Hinnant days_from_civil algorithm (cited above).
- Add the signed integer days to the day-number.
- Convert the resulting day-number back to a civil (year, month, day) using the inverse civil_from_days algorithm.
- Format the result as an ISO 8601 date.
Constants
None.
Sources
Worked example and test vectors
| Name | Inputs | Answer |
| 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
- Address:
64d7245fc1c632513712b6898bbf4665
- Made at:
2026-09-30T22:39:30.722Z
- Method sha256:
d770809d18f84cb8bec3f5875d2f1134d12d3a187b21a282c73b7bdf26fa1718