add Days(days: int) - > Date- Module
- std.
date - Receiver
- Date
- Minimum arity
- 1
- Maximum arity
- 1
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.date in language mode 5.21.
The current compiler selects std/date.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1105 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 60 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1105 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 459 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 288
Receiver
Date
Parameter constraints
Date.addDays accepts a signed int count of whole calendar days. Positive values move forward, negative values move backward, and zero returns the same date value.
The result follows the same proleptic Gregorian calendar as Date.fromYmd. Month boundaries, leap days, and year boundaries are crossed by counting calendar days. Historical calendar cutovers and daylight saving changes do not alter the result.
The result must remain from 0001-01-01 through 9999-12-31. A count whose mathematical result is outside that range raises TPZ4004 during execution. An intermediate integer overflow also raises TPZ4004.
An invalid result does not wrap, saturate, return a partial date, or change the receiver. Evaluation stops at the fault before later statements run.
The receiver is evaluated before the day count and each is evaluated once. An earlier fault prevents later evaluation. The operation has no external effects.
Adding a count and then its negative recovers the starting date when both results lie in range. Date.toIso and the component accessors observe the resulting date without changing it.
Related rule: Add whole calendar days within the civil date rangeResult
The declared result type is Date.
Effects
Failures
Result and effects
LinkCalendar arithmetic preserves the receiver. A result outside years 1 through 9999 raises TPZ4004.
Resolved contracts
LinkRelated entries
LinkAdd whole calendar days within the civil date range
LinkAdd whole calendar days within the civil date range
Date.addDays accepts a signed int count of whole calendar days. Positive values move forward, negative values move backward, and zero returns the same date value.
The result follows the same proleptic Gregorian calendar as Date.fromYmd. Month boundaries, leap days, and year boundaries are crossed by counting calendar days. Historical calendar cutovers and daylight saving changes do not alter the result.
The result must remain from 0001-01-01 through 9999-12-31. A count whose mathematical result is outside that range raises TPZ4004 during execution. An intermediate integer overflow also raises TPZ4004.
An invalid result does not wrap, saturate, return a partial date, or change the receiver. Evaluation stops at the fault before later statements run.
The receiver is evaluated before the day count and each is evaluated once. An earlier fault prevents later evaluation. The operation has no external effects.
Adding a count and then its negative recovers the starting date when both results lie in range. Date.toIso and the component accessors observe the resulting date without changing it.
Why
Calendar arithmetic should depend on a date and a day count. A bounded result with an explicit overflow fault prevents wraparound from silently producing a different civil date.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 3 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 13 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/lib.rs at
912a5e86e1f9· 164 -
topaz.stdlib.contract.date-arithmeticatworking-tree - topaz.decision.date-civil-range.1 at
topaz.decisi
Cross leap days, years, and the full supported interval
Linkimport std.date { Date }import std.testimport std.iolet leap = test.assertOk(Date.fromYmd(2000, 2, 28))io.writeLine(leap.addDays(1).toIso())io.writeLine(leap.addDays(2).toIso())io.writeLine(leap.toIso())io.writeLine(test.assertOk(Date.fromYmd(1900, 2, 28)).addDays(1).toIso())io.writeLine(test.assertOk(Date.fromYmd(1582, 10, 4)).addDays(1).toIso())io.writeLine(test.assertOk(Date.fromYmd(2000, 1, 1)).addDays(-1).toIso())io.writeLine(leap.addDays(0).toIso())io.writeLine(test.assertOk(Date.fromYmd(1, 1, 1)).addDays(3652058).toIso())io.writeLine(test.assertOk(Date.fromYmd(9999, 12, 31)).addDays(-3652058).toIso())
2000-02-29 2000-03-01 2000-02-28 1900-03-01 1582-10-05 1999-12-31 2000-02-28 9999-12-31 0001-01-01
Expected result
Expected result
Execution completes. Exit code 0.
2000-02-292000-03-012000-02-281900-03-011582-10-051999-12-312000-02-289999-12-310001-01-01
Source evidence
- compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 3 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 13 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/lib.rs at
912a5e86e1f9· 164 -
topaz.stdlib.contract.date-arithmeticatworking-tree - topaz.decision.date-civil-range.1 at
topaz.decisi
Reject the day after the final supported date
Linkimport std.date { Date }import std.testimport std.iolet date = test.assertOk(Date.fromYmd(9999, 12, 31))date.addDays(1)io.writeLine("after")
No stdout.
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4004stdlib-date-range-overflow atmain.tpz:6:1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 3 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 13 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/lib.rs at
912a5e86e1f9· 164 -
topaz.stdlib.contract.date-arithmeticatworking-tree - topaz.decision.date-civil-range.1 at
topaz.decisi
Reject the day before the first supported date
Linkimport std.date { Date }import std.testimport std.iolet date = test.assertOk(Date.fromYmd(1, 1, 1))date.addDays(-1)io.writeLine("after")
No stdout.
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4004stdlib-date-range-overflow atmain.tpz:6:1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 3 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 13 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/lib.rs at
912a5e86e1f9· 164 -
topaz.stdlib.contract.date-arithmeticatworking-tree - topaz.decision.date-civil-range.1 at
topaz.decisi
Reject a day count that overflows signed arithmetic
Linkimport std.date { Date }import std.testimport std.iolet date = test.assertOk(Date.fromYmd(1, 1, 1))date.addDays(-9223372036854775808)io.writeLine("after")
No stdout.
Expected result
Expected result
Rejection during run. Nonzero exit.
TPZ4004stdlib-date-range-overflow atmain.tpz:6:1
Source evidence
- compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 3 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 13 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/lib.rs at
912a5e86e1f9· 164 -
topaz.stdlib.contract.date-arithmeticatworking-tree - topaz.decision.date-civil-range.1 at
topaz.decisi
Evaluate a date receiver before its day count
Linkimport std.date { Date }import std.testimport std.iofunction receiver() -> Date {io.writeLine("date")return test.assertOk(Date.fromYmd(2024, 2, 28))}function days() -> int {io.writeLine("days")return 1}let next = receiver().addDays(days())io.writeLine(next.toIso())
date days 2024-02-29
Expected result
Expected result
Execution completes. Exit code 0.
datedays2024-02-29
Source evidence
- compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 3 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 13 - compiler/crates/topaz_value/src/value/builtins/date.rs at
912a5e86e1f9· 144 - compiler/crates/topaz_value/src/lib.rs at
912a5e86e1f9· 164 -
topaz.stdlib.contract.date-arithmeticatworking-tree - topaz.decision.date-civil-range.1 at
topaz.decisi