data Period
Calendar interval (§17.1): months and days are not fixed lengths, Date + Period is calendar arithmetic. Build it
with 1.month, 2.years, 3.days, Period(months: 1, days: 3).
Example:
use std.time { Period }
fn main() io {
let p = 1.year() + 2.months() + 3.days()
print("{p.show()} {p.totalMonths()}")
}Output
P1Y2M3D 14
@derive(Copy, Eq, Hash)
pub(api) data PeriodThread safety. an immutable value.
Since. 1.0.0-beta
Fields
pub(api) years: i64 = 0 | Calendar years. |
pub(api) months: i64 = 0 | Calendar months. |
pub(api) days: i64 = 0 | Calendar days. |
Methods
ofYears | (n: i64) -> PeriodA calendar period of n years. |
ofMonths | (n: i64) -> PeriodA calendar period of n months. |
ofWeeks | (n: i64) -> PeriodA calendar period of n weeks (7 days each). |
ofDays | (n: i64) -> PeriodA calendar period of n days. |
isZero | () -> boolWhether all parts of the period are zero. |
totalMonths | () -> i64Total months (years * 12 + months). |
+ | (a: Period, b: Period) -> PeriodThe sum of two periods (part by part). |
- | (a: Period, b: Period) -> PeriodThe difference of two periods (part by part). |
- | (a: Period) -> PeriodThe negated period. |
* | (a: Period, k: i64) -> PeriodA period multiplied by an integer. |
show | () -> strISO 8601 text: P1Y2M3D, P0D for zero. |
Defined in: std/time/time.oxl:866