UNPKG

lakutata

Version:

An IoC-based universal application framework.

280 lines (277 loc) 7.58 kB
import './TypeDef.2.js'; declare namespace UnitOfTime { type Base = ('year' | 'years' | 'y' | 'month' | 'months' | 'M' | 'week' | 'weeks' | 'w' | 'day' | 'days' | 'd' | 'hour' | 'hours' | 'h' | 'minute' | 'minutes' | 'm' | 'second' | 'seconds' | 's' | 'millisecond' | 'milliseconds' | 'ms'); type _quarter = 'quarter' | 'quarters' | 'Q'; type _isoWeek = 'isoWeek' | 'isoWeeks' | 'W'; type _date = 'date' | 'dates' | 'D'; type DurationConstructor = Base | _quarter; type DurationAs = Base; type StartOf = Base | _quarter | _isoWeek | _date | null; type Diff = Base | _quarter; type MomentConstructor = Base | _date; type All = Base | _quarter | _isoWeek | _date | 'weekYear' | 'weekYears' | 'gg' | 'isoWeekYear' | 'isoWeekYears' | 'GG' | 'dayOfYear' | 'dayOfYears' | 'DDD' | 'weekday' | 'weekdays' | 'e' | 'isoWeekday' | 'isoWeekdays' | 'E'; } type TimeInput = Time | Date | string | number | (number | string)[] | null; type TimeObject = { years: number; months: number; date: number; hours: number; minutes: number; seconds: number; milliseconds: number; }; /** * Time class */ declare class Time extends Date { #private; /** * Constructor * @param inp */ constructor(inp?: TimeInput); /** * Get all timezone names */ static timezones(): string[]; /** * Returns the maximum value for a given instance (farthest into the future) * @param times */ static max(...times: Time[]): Time; /** * Returns the minimum value (most distant past) of the given instance * @param times */ static min(...times: Time[]): Time; /** * Update the current instance internal timestamp and return the current instance * @param time * @protected */ protected updateTimestamp(time: number): this; /** * Get time zone offset */ getTimezoneOffset(): number; /** * Get or set time zone */ timezone(): string | undefined; timezone(tz: string): this; /** * Get or set the number of milliseconds */ milliseconds(): number; milliseconds(value: number): this; /** * Get or set seconds */ seconds(): number; seconds(value: number): this; /** * Get or set minutes */ minutes(): number; minutes(value: number): this; /** * Get or set the hour */ hours(): number; hours(value: number): this; /** * Get or set the day of the month * Accepts numbers from 1 to 31. If out of range it will bubble up to months */ date(): number; date(value: number): this; /** * Set to get or set the day of the week */ weekday(): number; weekday(value: number): this; /** * Get or set the ISO day of the week, 1 is Monday, 7 is Sunday */ isoWeekday(): number; isoWeekday(value: number): this; /** * Get or set the day of the year * Accepts numbers from 1 to 366. If out of range it will bubble up to the year */ dayOfYear(): number; dayOfYear(value: number): this; /** * Gets or sets the week of the year */ weeks(): number; weeks(value: number): this; /** * Gets or sets the ISO week of the year */ isoWeeks(): number; isoWeeks(value: number): this; /** * Get or set the month * Accepts numbers from 0 to 11. If out of range it will bubble up to the year */ month(): number; month(value: number): this; /** * Gets or sets the quarter (1 to 4) */ quarters(): number; quarters(value: number): this; /** * Get or set the year * Accepts numbers from -270,000 to 270,000 */ year(): number; year(value: number): this; /** * Gets or sets the week of the year in ISO time */ isoWeekYear(): number; isoWeekYear(value: number): this; /** * Gets the week number based on the locale of the current instance's year */ weeksInYear(): number; /** * Get the week number of the year where the current instance is located based on the week number */ isoWeeksInYear(): number; /** * Universal getter (Depends on input unit) * @param unit */ get(unit: UnitOfTime.All): number; /** * Universal setter (Depends on input unit) * @param unit * @param value */ set(unit: UnitOfTime.All, value: number): this; /** * Increase time * @param amount * @param unit */ add(amount: number, unit: UnitOfTime.DurationConstructor): this; /** * Minus time * @param amount * @param unit */ subtract(amount: number, unit: UnitOfTime.DurationConstructor): this; /** * Set to the start of a time unit * @param unit */ startOf(unit: UnitOfTime.StartOf): this; /** * Set to the end of the time unit * @param unit */ endOf(unit: UnitOfTime.StartOf): this; /** * Format output time string */ format(): string; format(format: string): string; /** * Get time difference * @param inp * @param unit * @param precise */ diff(inp: TimeInput, unit?: UnitOfTime.Diff, precise?: boolean): number; /** * Outputs a Unix timestamp (number of seconds since the Unix epoch) */ unix(): number; /** * Get the number of days in the current month */ daysInMonth(): number; /** * This will return an array that reflects the parameters in new Date() */ toArray(): [number, number, number, number, number, number, number]; /** * Returns an object containing the year, month, day of the month, hour, minute, second, and millisecond */ toObject(): TimeObject; /** * To string */ toString(): string; /** * To time string */ toTimeString(): string; /** * To UTC string */ toUTCString(): string; /** * To date string */ toDateString(): string; /** * Return ISO format time string */ toISOString(): string; /** * Convert current time object to Date object */ toDate(): Date; /** * Is current time before input time * @param inp * @param granularity */ isBefore(inp?: TimeInput, granularity?: UnitOfTime.StartOf): boolean; /** * Is current time same with input time * @param inp * @param granularity */ isSame(inp?: TimeInput, granularity?: UnitOfTime.StartOf): boolean; /** * Is current time after input time * @param inp * @param granularity */ isAfter(inp?: TimeInput, granularity?: UnitOfTime.StartOf): boolean; /** * Is current time same or before input time * @param inp * @param granularity */ isSameOrBefore(inp?: TimeInput, granularity?: UnitOfTime.StartOf): boolean; /** * Is current time same or after input time * @param inp * @param granularity */ isSameOrAfter(inp?: TimeInput, granularity?: UnitOfTime.StartOf): boolean; /** * Is current time between two input times * @param a * @param b * @param granularity * @param inclusivity */ isBetween(a: TimeInput, b: TimeInput, granularity?: UnitOfTime.StartOf, inclusivity?: '()' | '[)' | '(]' | '[]'): boolean; /** * Check current time instance is leap year */ isLeapYear(): boolean; /** * Clone a time instance */ clone(): Time; } export { Time as T };