import Period, {NULL_PERIOD, DAY_PERIOD, WEEK_PERIOD, MONTH_PERIOD, QUARTER_PERIOD, YEAR_PERIOD} from "ts-time/Period";
Comprises a fixed date/time interval in certain units of measurement. As opposed to Duration, it can comprise a variable-length interval such as month. Month duration varies from 28 to 31 days, but in terms of periods, month is a valid unit. Period is mainly involved to manipulate date/time-related objects such as LocalDate, LocalDateTime, OffsetDateTime and ZonedDateTime. In particular, ZonedDateTime.plusPeriod method adds a period to the respective date/time, not instant. It means that if you add DAY_PERIOD to a ZonedDateTime, the real time shift won't be 24 hours if time zone offset changes during this day, while LocalTime will truly stay the same:
const start = ZonedDateTime.parse("2019-10-27T00:00:00.000+02:00[Europe/Berlin]"), // Summer time end = start.plusPeriod(DAY_PERIOD); expect(end.toString()).toBe("2019-10-28T00:00:00.000+01:00[Europe/Berlin]"); // Winter time expect(end.epochMs - start.epochMs).toBe(25 * MS_PER_HOUR);
To ascertain a predictable fixed real time shift, you are supposed to add a Duration.
Period doesn't support alignment out of the box. For example, WEEK_PERIOD won't automatically snap your dates to MONDAY.
Current API doesn't support complex periods such as 1 month + 1 day, as their application depends on the order, and use cases of such periods are unclear.
readonly empty: boolean
abstract (date: LocalDate, amount: number): LocalDate
abstract (start: LocalDate, end: LocalDate): number
(multiplier: number): Period
(years: number): Period
(quarters: number): Period
(months: number): Period
(weeks: number): Period
(days: number): Period
NULL_PERIOD: Period
DAY_PERIOD: Period
WEEK_PERIOD: Period
MONTH_PERIOD: Period
QUARTER_PERIOD: Period
YEAR_PERIOD: Period