OxL Справочник OxL
РусскийEnglish

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:

oxl✓ проверяется в CI
use std.time { Period }

fn main() io {
  let p = 1.year() + 2.months() + 3.days()
  print("{p.show()} {p.totalMonths()}")
}
Вывод
P1Y2M3D 14
@derive(Copy, Eq, Hash)
pub(api) data Period

Потокобезопасность. an immutable value.

С версии. 1.0.0-beta

Поля

pub(api) years: i64 = 0

Calendar years.

pub(api) months: i64 = 0

Calendar months.

pub(api) days: i64 = 0

Calendar days.

Методы

ofYears(n: i64) -> Period
A calendar period of n years.
ofMonths(n: i64) -> Period
A calendar period of n months.
ofWeeks(n: i64) -> Period
A calendar period of n weeks (7 days each).
ofDays(n: i64) -> Period
A calendar period of n days.
isZero() -> bool
Whether all parts of the period are zero.
totalMonths() -> i64
Total months (years * 12 + months).
+(a: Period, b: Period) -> Period
The sum of two periods (part by part).
-(a: Period, b: Period) -> Period
The difference of two periods (part by part).
-(a: Period) -> Period
The negated period.
*(a: Period, k: i64) -> Period
A period multiplied by an integer.
show() -> str
ISO 8601 text: P1Y2M3D, P0D for zero.

Определено в: std/time/time.oxl:866

См. также