UNPKG

@naturalcycles/js-lib

Version:

Standard library for universal (browser + Node.js) javascript

38 lines (37 loc) 1.35 kB
import type { UnixTimestamp } from '../types.js'; import type { LocalTime, LocalTimeInput } from './localTime.js'; export type TimeIntervalConfig = TimeInterval | TimeIntervalString; export type TimeIntervalString = string; /** * Class that supports an "interval of time" between 2 timestamps - start and end. * Example: `1649267185/1649267187`. * * @experimental */ export declare class TimeInterval { private $start; private $end; private constructor(); static of(start: LocalTimeInput, end: LocalTimeInput): TimeInterval; get start(): UnixTimestamp; get end(): UnixTimestamp; get startTime(): LocalTime; get endTime(): LocalTime; /** * Parses string like `1649267185/1649267187` into a TimeInterval. */ static parse(d: TimeIntervalConfig): TimeInterval; isSame(d: TimeIntervalConfig): boolean; isBefore(d: TimeIntervalConfig, inclusive?: boolean): boolean; isSameOrBefore(d: TimeIntervalConfig): boolean; isAfter(d: TimeIntervalConfig, inclusive?: boolean): boolean; isSameOrAfter(d: TimeIntervalConfig): boolean; includes(d: LocalTimeInput): boolean; /** * TimeIntervals compare by start date. * If it's the same - then by end date. */ cmp(d: TimeIntervalConfig): -1 | 0 | 1; toString(): TimeIntervalString; toJSON(): TimeIntervalString; }