Merge pull request #32394 from mastermatt/luxon/lint-and-update

[@types/luxon] Lint and bring up to date.
This commit is contained in:
Benjamin Lichtman
2019-01-23 10:12:51 -08:00
committed by GitHub
3 changed files with 625 additions and 468 deletions
+439 -424
View File
@@ -8,459 +8,474 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare module 'luxon' {
namespace luxon {
type DateTimeFormatOptions = Intl.DateTimeFormatOptions;
export type DateTimeFormatOptions = Intl.DateTimeFormatOptions;
type ZoneOptions = {
keepLocalTime?: boolean;
/**
* @deprecated since 0.2.12. Use keepLocalTime instead
*/
keepCalendarTime?: boolean;
};
export interface ZoneOptions {
keepLocalTime?: boolean;
/**
* @deprecated since 0.2.12. Use keepLocalTime instead
*/
keepCalendarTime?: boolean;
}
type ToFormatOptions = DateTimeFormatOptions & {
round?: boolean;
};
export type ToRelativeUnit =
| "year"
| "quarter"
| "month"
| "week"
| "day"
| "hour"
| "minute"
| "second";
type ToRelativeOptions = {
/** The DateTime to use as the basis to which this time is compared. Defaults to now. */
base?: DateTime;
locale?: string;
style?: 'long' | 'short' | 'narrow';
/** If omitted, the method will pick the unit. */
unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
/** Defaults to `true`. */
round?: boolean;
/**
* Padding in milliseconds. This allows you to round up the result if it fits inside the threshold.
* Don't use in combination with {round: false} because the decimal output will include the padding.
* Defaults to 0.
*/
padding?: number;
/** The Intl system may choose not to honor this */
numberingSystem?: string;
};
export interface ToRelativeOptions {
/** The DateTime to use as the basis to which this time is compared. Defaults to now. */
base?: DateTime;
locale?: string;
style?: "long" | "short" | "narrow";
/** If omitted, the method will pick the unit. */
unit?: ToRelativeUnit;
/** Defaults to `true`. */
round?: boolean;
/**
* Padding in milliseconds. This allows you to round up the result if it fits inside the threshold.
* Don't use in combination with {round: false} because the decimal output will include the padding.
* Defaults to 0.
*/
padding?: number;
/** The Intl system may choose not to honor this */
numberingSystem?: string;
}
type ToRelativeCalendarOptions = {
/** The DateTime to use as the basis to which this time is compared. Defaults to now. */
base?: DateTime;
locale?: string;
/** If omitted, the method will pick the unit. */
unit?: 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
/** The Intl system may choose not to honor this. */
numberingSystem?: string;
};
export interface ToRelativeCalendarOptions {
/** The DateTime to use as the basis to which this time is compared. Defaults to now. */
base?: DateTime;
locale?: string;
/** If omitted, the method will pick the unit. */
unit?: ToRelativeUnit;
/** The Intl system may choose not to honor this. */
numberingSystem?: string;
}
type ToSQLOptions = {
includeOffset?: boolean;
includeZone?: boolean;
};
export interface ToSQLOptions {
includeOffset?: boolean;
includeZone?: boolean;
}
type ISOTimeOptions = {
suppressMilliseconds?: boolean;
suppressSeconds?: boolean;
includeOffset?: boolean;
};
export interface ToISOTimeOptions {
suppressMilliseconds?: boolean;
suppressSeconds?: boolean;
includeOffset?: boolean;
}
type LocaleOptions = {
locale?: string;
outputCalendar?: string;
numberingSystem?: string;
};
// alias for backwards compatibility
export type ISOTimeOptions = ToISOTimeOptions;
type DateTimeOptions = LocaleOptions & {
zone?: string | Zone;
setZone?: boolean;
};
export interface LocaleOptions {
locale?: string;
outputCalendar?: string;
numberingSystem?: string;
}
type DateTimeJSOptions = LocaleOptions & {
zone?: string | Zone;
};
export interface DateTimeOptions extends LocaleOptions {
zone?: string | Zone;
setZone?: boolean;
}
type DateObjectUnits = {
year?: number;
month?: number;
day?: number;
ordinal?: number;
weekYear?: number;
weekNumber?: number;
weekday?: number;
hour?: number;
minute?: number;
second?: number;
millisecond?: number;
};
export interface DateTimeJSOptions extends LocaleOptions {
zone?: string | Zone;
}
type DateObject = DateObjectUnits & LocaleOptions & {
zone?: string | Zone;
};
export interface DateObjectUnits {
year?: number;
month?: number;
day?: number;
ordinal?: number;
weekYear?: number;
weekNumber?: number;
weekday?: number;
hour?: number;
minute?: number;
second?: number;
millisecond?: number;
}
type DiffOptions = {
conversionAccuracy?: string;
};
export interface DateObject extends DateObjectUnits, LocaleOptions {
zone?: string | Zone;
}
type ExplainedFormat = {
input: string;
tokens: Array<{ literal: boolean, val: string }>,
regex?: RegExp;
rawMatches?: RegExpMatchArray | null;
matches?: {[k: string]: any};
result?: {[k: string]: any} | null;
zone?: Zone | null;
invalidReason?: string;
};
export interface DiffOptions {
conversionAccuracy?: string;
}
class DateTime {
static readonly DATETIME_FULL: DateTimeFormatOptions;
static readonly DATETIME_FULL_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATETIME_HUGE: DateTimeFormatOptions;
static readonly DATETIME_HUGE_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATETIME_MED: DateTimeFormatOptions;
static readonly DATETIME_MED_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATETIME_SHORT: DateTimeFormatOptions;
static readonly DATETIME_SHORT_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATE_FULL: DateTimeFormatOptions;
static readonly DATE_HUGE: DateTimeFormatOptions;
static readonly DATE_MED: DateTimeFormatOptions;
static readonly DATE_SHORT: DateTimeFormatOptions;
static readonly TIME_24_SIMPLE: DateTimeFormatOptions;
static readonly TIME_24_WITH_LONG_OFFSET: DateTimeFormatOptions;
static readonly TIME_24_WITH_SECONDS: DateTimeFormatOptions;
static readonly TIME_24_WITH_SHORT_OFFSET: DateTimeFormatOptions;
static readonly TIME_SIMPLE: DateTimeFormatOptions;
static readonly TIME_WITH_LONG_OFFSET: DateTimeFormatOptions;
static readonly TIME_WITH_SECONDS: DateTimeFormatOptions;
static readonly TIME_WITH_SHORT_OFFSET: DateTimeFormatOptions;
static fromHTTP(text: string, options?: DateTimeOptions): DateTime;
static fromISO(text: string, options?: DateTimeOptions): DateTime;
static fromJSDate(
date: Date,
options?: DateTimeJSOptions
): DateTime;
static fromMillis(ms: number, options?: DateTimeOptions): DateTime;
static fromObject(obj: DateObject): DateTime;
static fromRFC2822(
text: string,
options?: DateTimeOptions
): DateTime;
static fromSeconds(seconds: number, options?: DateTimeOptions): DateTime;
static fromSQL(text: string, options?: DateTimeOptions): DateTime;
static fromFormat(
text: string,
format: string,
opts?: DateTimeOptions
): DateTime;
static fromFormatExplain(
text: string,
format: string,
opts?: DateTimeOptions
): ExplainedFormat;
/**
* @deprecated since 0.3.0. Use fromFormat instead
*/
static fromString(
text: string,
format: string,
options?: DateTimeOptions
): DateTime;
/**
* @deprecated 0.3.0. Use fromFormatExplain instead
*/
static fromStringExplain(
text: string,
format: string,
options?: DateTimeOptions
): ExplainedFormat;
static invalid(reason: any): DateTime;
static local(
year?: number,
month?: number,
day?: number,
hour?: number,
minute?: number,
second?: number,
millisecond?: number
): DateTime;
static max(): undefined;
static max(...dateTimes: DateTime[]): DateTime;
static min(): undefined;
static min(...dateTimes: DateTime[]): DateTime;
static utc(
year?: number,
month?: number,
day?: number,
hour?: number,
minute?: number,
second?: number,
millisecond?: number
): DateTime;
day: number;
daysInMonth: number;
daysInYear: number;
hour: number;
invalidReason: string;
isInDST: boolean;
isInLeapYear: boolean;
isOffsetFixed: boolean;
isValid: boolean;
locale: string;
millisecond: number;
minute: number;
month: number;
monthLong: string;
monthShort: string;
numberingSystem: string;
offset: number;
offsetNameLong: string;
offsetNameShort: string;
ordinal: number;
outputCalendar: string;
quarter: number;
second: number;
weekNumber: number;
weekYear: number;
weekday: number;
weekdayLong: string;
weekdayShort: string;
weeksInWeekYear: number;
year: number;
zoneName: string;
zone: Zone;
diff(
other: DateTime,
unit?: DurationUnit | DurationUnit[],
options?: DiffOptions
): Duration;
diffNow(unit?: DurationUnit | DurationUnit[], options?: DiffOptions): Duration;
endOf(unit: DurationUnit): DateTime;
equals(other: DateTime): boolean;
get(unit: keyof DateTime): number;
hasSame(other: DateTime, unit: DurationUnit): boolean;
minus(duration: Duration | number | DurationObject): DateTime;
plus(duration: Duration | number | DurationObject): DateTime;
reconfigure(properties: LocaleOptions): DateTime;
resolvedLocaleOpts(options?: ToFormatOptions): LocaleOptions;
set(values: DateObjectUnits): DateTime;
setLocale(locale: any): DateTime;
setZone(zone: string | Zone, options?: ZoneOptions): DateTime;
startOf(unit: DurationUnit): DateTime;
toBSON(): Date;
toFormat(format: string, options?: ToFormatOptions): string;
toHTTP(): string;
toISO(options?: ISOTimeOptions): string;
toISODate(): string;
toISOTime(options?: ISOTimeOptions): string;
toISOWeekDate(): string;
toJSDate(): Date;
toJSON(): string;
toLocal(): DateTime;
toLocaleParts(options?: DateTimeFormatOptions): any[];
toLocaleString(options?: DateTimeFormatOptions): string;
toMillis(): number;
toMillis(): number;
toObject(options?: { includeConfig?: boolean }): DateObject;
toRelative(options?: ToRelativeOptions): string | null;
toRelativeCalendar(options?: ToRelativeCalendarOptions): string | null;
toRFC2822(): string;
toSeconds(): number;
toSQL(options?: ToSQLOptions): string;
toSQLDate(): string;
toSQLTime(options?: ToSQLOptions): string;
toString(): string;
toUTC(offset?: number, options?: ZoneOptions): DateTime;
until(other: DateTime): Interval;
valueOf(): number;
}
export interface ExplainedFormat {
input: string;
tokens: Array<{ literal: boolean; val: string }>;
regex?: RegExp;
rawMatches?: RegExpMatchArray | null;
matches?: { [k: string]: any };
result?: { [k: string]: any } | null;
zone?: Zone | null;
invalidReason?: string;
}
export class DateTime {
static readonly DATETIME_FULL: DateTimeFormatOptions;
static readonly DATETIME_FULL_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATETIME_HUGE: DateTimeFormatOptions;
static readonly DATETIME_HUGE_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATETIME_MED: DateTimeFormatOptions;
static readonly DATETIME_MED_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATETIME_SHORT: DateTimeFormatOptions;
static readonly DATETIME_SHORT_WITH_SECONDS: DateTimeFormatOptions;
static readonly DATE_FULL: DateTimeFormatOptions;
static readonly DATE_HUGE: DateTimeFormatOptions;
static readonly DATE_MED: DateTimeFormatOptions;
static readonly DATE_SHORT: DateTimeFormatOptions;
static readonly TIME_24_SIMPLE: DateTimeFormatOptions;
static readonly TIME_24_WITH_LONG_OFFSET: DateTimeFormatOptions;
static readonly TIME_24_WITH_SECONDS: DateTimeFormatOptions;
static readonly TIME_24_WITH_SHORT_OFFSET: DateTimeFormatOptions;
static readonly TIME_SIMPLE: DateTimeFormatOptions;
static readonly TIME_WITH_LONG_OFFSET: DateTimeFormatOptions;
static readonly TIME_WITH_SECONDS: DateTimeFormatOptions;
static readonly TIME_WITH_SHORT_OFFSET: DateTimeFormatOptions;
static fromHTTP(text: string, options?: DateTimeOptions): DateTime;
static fromISO(text: string, options?: DateTimeOptions): DateTime;
static fromJSDate(date: Date, options?: DateTimeJSOptions): DateTime;
static fromMillis(ms: number, options?: DateTimeOptions): DateTime;
static fromObject(obj: DateObject): DateTime;
static fromRFC2822(text: string, options?: DateTimeOptions): DateTime;
static fromSeconds(seconds: number, options?: DateTimeOptions): DateTime;
static fromSQL(text: string, options?: DateTimeOptions): DateTime;
static fromFormat(
text: string,
format: string,
opts?: DateTimeOptions
): DateTime;
static fromFormatExplain(
text: string,
format: string,
opts?: DateTimeOptions
): ExplainedFormat;
/**
* @deprecated since 0.3.0. Use fromFormat instead
*/
static fromString(
text: string,
format: string,
options?: DateTimeOptions
): DateTime;
/**
* @deprecated 0.3.0. Use fromFormatExplain instead
*/
static fromStringExplain(
text: string,
format: string,
options?: DateTimeOptions
): ExplainedFormat;
static invalid(reason: any): DateTime;
static isDateTime(o: any): o is DateTime;
static local(
year?: number,
month?: number,
day?: number,
hour?: number,
minute?: number,
second?: number,
millisecond?: number
): DateTime;
static max(): undefined;
static max(...dateTimes: DateTime[]): DateTime;
static min(): undefined;
static min(...dateTimes: DateTime[]): DateTime;
static utc(
year?: number,
month?: number,
day?: number,
hour?: number,
minute?: number,
second?: number,
millisecond?: number
): DateTime;
day: number;
daysInMonth: number;
daysInYear: number;
hour: number;
invalidReason: string | null;
invalidExplanation: string | null;
isInDST: boolean;
isInLeapYear: boolean;
isOffsetFixed: boolean;
isValid: boolean;
locale: string;
millisecond: number;
minute: number;
month: number;
monthLong: string;
monthShort: string;
numberingSystem: string;
offset: number;
offsetNameLong: string;
offsetNameShort: string;
ordinal: number;
outputCalendar: string;
quarter: number;
second: number;
weekNumber: number;
weekYear: number;
weekday: number;
weekdayLong: string;
weekdayShort: string;
weeksInWeekYear: number;
year: number;
zoneName: string;
zone: Zone;
diff(
other: DateTime,
unit?: DurationUnit | DurationUnit[],
options?: DiffOptions
): Duration;
diffNow(
unit?: DurationUnit | DurationUnit[],
options?: DiffOptions
): Duration;
endOf(unit: DurationUnit): DateTime;
equals(other: DateTime): boolean;
get(unit: keyof DateTime): number;
hasSame(other: DateTime, unit: DurationUnit): boolean;
minus(duration: Duration | number | DurationObject): DateTime;
plus(duration: Duration | number | DurationObject): DateTime;
reconfigure(properties: LocaleOptions): DateTime;
resolvedLocaleOpts(
options?: DateTimeFormatOptions
): Intl.ResolvedDateTimeFormatOptions;
set(values: DateObjectUnits): DateTime;
setLocale(locale: string): DateTime;
setZone(zone: string | Zone, options?: ZoneOptions): DateTime;
startOf(unit: DurationUnit): DateTime;
toBSON(): Date;
toFormat(format: string, options?: DateTimeFormatOptions): string;
toHTTP(): string;
toISO(options?: ToISOTimeOptions): string;
toISODate(): string;
toISOTime(options?: ToISOTimeOptions): string;
toISOWeekDate(): string;
toJSDate(): Date;
toJSON(): string;
toLocal(): DateTime;
toLocaleParts(options?: LocaleOptions & DateTimeFormatOptions): any[];
toLocaleString(options?: LocaleOptions & DateTimeFormatOptions): string;
toMillis(): number;
toObject(options?: { includeConfig?: boolean }): DateObject;
toRelative(options?: ToRelativeOptions): string | null;
toRelativeCalendar(options?: ToRelativeCalendarOptions): string | null;
toRFC2822(): string;
toSeconds(): number;
toSQL(options?: ToSQLOptions): string;
toSQLDate(): string;
toSQLTime(options?: ToSQLOptions): string;
toString(): string;
toUTC(offset?: number, options?: ZoneOptions): DateTime;
until(other: DateTime): Interval;
valueOf(): number;
}
type DurationOptions = {
locale?: string;
numberingSystem?: string;
conversionAccuracy?: string;
};
export interface DurationOptions {
locale?: string;
numberingSystem?: string;
conversionAccuracy?: string;
}
type DurationObjectUnits = {
years?: number;
months?: number;
weeks?: number;
days?: number;
hours?: number;
minutes?: number;
seconds?: number;
milliseconds?: number;
};
export interface DurationObjectUnits {
year?: number;
years?: number;
quarter?: number;
quarters?: number;
month?: number;
months?: number;
week?: number;
weeks?: number;
day?: number;
days?: number;
hour?: number;
hours?: number;
minute?: number;
minutes?: number;
second?: number;
seconds?: number;
millisecond?: number;
milliseconds?: number;
}
type DurationObject = DurationObjectUnits & DurationOptions;
export interface DurationObject extends DurationObjectUnits, DurationOptions {}
type DurationUnit = 'year' | 'years' | 'quarter' | 'quarters' | 'month' | 'months' | 'week' | 'weeks' | 'day' | 'days'
| 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds';
export type DurationUnit = keyof DurationObjectUnits;
class Duration {
static fromISO(text: string, options?: DurationOptions): Duration;
static fromMillis(
count: number,
options?: DurationOptions
): Duration;
static fromObject(
Object: DurationObject
): Duration;
static invalid(reason?: string): Duration;
days: number;
hours: number;
invalidReason: string;
isValid: boolean;
locale: string;
milliseconds: number;
minutes: number;
months: number;
numberingSystem: string;
quarters: number;
seconds: number;
weeks: number;
years: number;
as(unit: DurationUnit): number;
equals(other: Duration): boolean;
get(unit: DurationUnit): number;
minus(duration: Duration | number | DurationObject): Duration;
negate(): Duration;
normalize(): Duration;
plus(duration: Duration | number | DurationObject): Duration;
reconfigure(objectPattern: DurationOptions): Duration;
set(values: DurationObjectUnits): Duration;
shiftTo(...units: DurationUnit[]): Duration;
toFormat(format: string, options?: ToFormatOptions): string;
toISO(): string;
toJSON(): string;
toObject(options?: {
includeConfig?: boolean;
}): DurationObject;
toString(): string;
valueOf(): number;
}
export interface DurationToFormatOptions extends DateTimeFormatOptions {
floor?: boolean;
round?: boolean;
}
type EraLength = 'short' | 'long';
type UnitLength = EraLength | 'numeric' | '2-digit' | 'narrow';
type UnitOptions = InfoOptions & {
numberingSystem?: string;
outputCalendar?: string;
};
export class Duration {
static fromISO(text: string, options?: DurationOptions): Duration;
static fromMillis(count: number, options?: DurationOptions): Duration;
static fromObject(Object: DurationObject): Duration;
static invalid(reason?: string): Duration;
static isDuration(o: any): o is Duration;
days: number;
hours: number;
invalidReason: string | null;
invalidExplanation: string | null;
isValid: boolean;
locale: string;
milliseconds: number;
minutes: number;
months: number;
numberingSystem: string;
quarters: number;
seconds: number;
weeks: number;
years: number;
as(unit: DurationUnit): number;
equals(other: Duration): boolean;
get(unit: DurationUnit): number;
minus(duration: Duration | number | DurationObject): Duration;
negate(): Duration;
normalize(): Duration;
plus(duration: Duration | number | DurationObject): Duration;
reconfigure(objectPattern: DurationOptions): Duration;
set(values: DurationObjectUnits): Duration;
shiftTo(...units: DurationUnit[]): Duration;
toFormat(format: string, options?: DurationToFormatOptions): string;
toISO(): string;
toJSON(): string;
toObject(options?: { includeConfig?: boolean }): DurationObject;
toString(): string;
valueOf(): number;
}
type InfoOptions = {
locale?: string;
};
export type EraLength = "short" | "long";
export type UnitLength = EraLength | "numeric" | "2-digit" | "narrow";
export interface UnitOptions extends InfoOptions {
numberingSystem?: string;
outputCalendar?: string;
}
type Features = {
intl: boolean;
intlTokens: boolean;
zones: boolean;
};
export interface InfoOptions {
locale?: string;
}
namespace Info {
function eras(length?: EraLength, options?: InfoOptions): string[];
function features(): Features;
function hasDST(zone: string | Zone): boolean;
function isValidIANAZone(zone: string): boolean;
function meridiems(options?: InfoOptions): string[];
function months(length?: UnitLength, options?: UnitOptions): string[];
function monthsFormat(length?: UnitLength, options?: UnitOptions): string[];
function weekdays(length?: UnitLength, options?: UnitOptions): string[];
function weekdaysFormat(
length?: UnitLength,
options?: UnitOptions
): string[];
}
export interface Features {
intl: boolean;
intlTokens: boolean;
zones: boolean;
}
type IntervalObject = {
start?: DateTime;
end?: DateTime;
};
export namespace Info {
function eras(length?: EraLength, options?: InfoOptions): string[];
function features(): Features;
function hasDST(zone: string | Zone): boolean;
function isValidIANAZone(zone: string): boolean;
function normalizeZone(input?: number | string | Zone): Zone;
function meridiems(options?: InfoOptions): string[];
function months(length?: UnitLength, options?: UnitOptions): string[];
function monthsFormat(length?: UnitLength, options?: UnitOptions): string[];
function weekdays(length?: UnitLength, options?: UnitOptions): string[];
function weekdaysFormat(
length?: UnitLength,
options?: UnitOptions
): string[];
}
class Interval {
static after(
start: DateTime | DateObject | Date,
duration: Duration | number | DurationObject
): Interval;
static before(
end: DateTime | DateObject | Date,
duration: Duration | number | DurationObject
): Interval;
static fromDateTimes(
start: DateTime | DateObject | Date,
end: DateTime | DateObject | Date
): Interval;
static fromISO(string: string, options?: DateTimeOptions): Interval;
static invalid(reason?: string): Interval;
static merge(intervals: Interval[]): Interval[];
static xor(intervals: Interval[]): Interval[];
end: DateTime;
invalidReason: string;
isValid: boolean;
start: DateTime;
abutsEnd(other: Interval): boolean;
abutsStart(other: Interval): boolean;
contains(dateTime: DateTime): boolean;
count(unit?: DurationUnit): number;
difference(...intervals: Interval[]): Interval[];
divideEqually(numberOfParts?: number): Interval[];
engulfs(other: Interval): boolean;
equals(other: Interval): boolean;
hasSame(unit: DurationUnit): boolean;
intersection(other: Interval): Interval;
isAfter(dateTime: DateTime): boolean;
isBefore(dateTime: DateTime): boolean;
isEmpty(): boolean;
length(unit?: DurationUnit): number;
overlaps(other: Interval): boolean;
set(values: IntervalObject): Interval;
splitAt(...dateTimes: DateTime[]): Interval[];
splitBy(duration: Duration | DurationObject | number): Interval[];
toDuration(
unit: DurationUnit | DurationUnit[],
options?: DiffOptions
): Duration;
toFormat(
dateFormat: string,
options?: {
seperator?: string;
}
): string;
toISO(options?: ISOTimeOptions): string;
toString(): string;
union(other: Interval): Interval;
mapEndpoints(cb: (d: DateTime) => DateTime): Interval;
}
export interface IntervalObject {
start?: DateTime;
end?: DateTime;
}
namespace Settings {
let defaultLocale: string;
let defaultNumberingSystem: string;
let defaultOutputCalendar: string;
const defaultZone: Zone;
let defaultZoneName: string;
let throwOnInvalid: boolean;
let now: () => number;
function resetCaches(): void;
export class Interval {
static after(
start: DateTime | DateObject | Date,
duration: Duration | number | DurationObject
): Interval;
static before(
end: DateTime | DateObject | Date,
duration: Duration | number | DurationObject
): Interval;
static fromDateTimes(
start: DateTime | DateObject | Date,
end: DateTime | DateObject | Date
): Interval;
static fromISO(string: string, options?: DateTimeOptions): Interval;
static invalid(reason?: string): Interval;
static isInterval(o: any): o is Interval;
static merge(intervals: Interval[]): Interval[];
static xor(intervals: Interval[]): Interval[];
end: DateTime;
invalidReason: string | null;
invalidExplanation: string | null;
isValid: boolean;
start: DateTime;
abutsEnd(other: Interval): boolean;
abutsStart(other: Interval): boolean;
contains(dateTime: DateTime): boolean;
count(unit?: DurationUnit): number;
difference(...intervals: Interval[]): Interval[];
divideEqually(numberOfParts?: number): Interval[];
engulfs(other: Interval): boolean;
equals(other: Interval): boolean;
hasSame(unit: DurationUnit): boolean;
intersection(other: Interval): Interval;
isAfter(dateTime: DateTime): boolean;
isBefore(dateTime: DateTime): boolean;
isEmpty(): boolean;
length(unit?: DurationUnit): number;
overlaps(other: Interval): boolean;
set(values: IntervalObject): Interval;
splitAt(...dateTimes: DateTime[]): Interval[];
splitBy(duration: Duration | DurationObject | number): Interval[];
toDuration(
unit: DurationUnit | DurationUnit[],
options?: DiffOptions
): Duration;
toFormat(
dateFormat: string,
options?: {
separator?: string;
}
): string;
toISO(options?: ToISOTimeOptions): string;
toString(): string;
union(other: Interval): Interval;
mapEndpoints(cb: (d: DateTime) => DateTime): Interval;
}
type ZoneOffsetOptions = {
format?: 'short' | 'long';
localeCode?: string;
};
export namespace Settings {
let defaultLocale: string;
let defaultNumberingSystem: string;
let defaultOutputCalendar: string;
const defaultZone: Zone;
let defaultZoneName: string;
let throwOnInvalid: boolean;
function now(): number;
function resetCaches(): void;
}
class Zone {
static offsetName(ts: number, options?: ZoneOffsetOptions): string;
static isValid: boolean;
static name: string;
static type: string;
static universal: boolean;
equals(other: Zone): boolean;
offset(ts: number): number;
}
export interface ZoneOffsetOptions {
format?: "short" | "long";
localeCode?: string;
}
class IANAZone extends Zone {
constructor(ianaString: string);
}
}
export class Zone {
static offsetName(ts: number, options?: ZoneOffsetOptions): string;
static isValid: boolean;
static name: string;
static type: string;
static universal: boolean;
equals(other: Zone): boolean;
offset(ts: number): number;
}
export = luxon;
export class IANAZone extends Zone {
constructor(ianaString: string);
}
+185 -36
View File
@@ -35,19 +35,30 @@ getters.daysInMonth;
getters.ordinal;
getters.isInLeapYear;
dt.toLocaleString();
dt.toLocaleString(DateTime.DATE_MED);
dt.toISO();
dt.toISO({includeOffset: true});
dt.toSeconds();
dt.toSQL();
dt.toSQL({includeOffset: false, includeZone: true});
dt.toSQLDate();
dt.toSQLTime();
dt.toSQLTime({includeOffset: false, includeZone: true});
dt.toRelative();
dt.toRelativeCalendar();
dt.toBSON(); // $ExpectType Date
dt.toHTTP(); // $ExpectType string
dt.toISO(); // $ExpectType string
dt.toISO({ includeOffset: true }); // $ExpectType string
dt.toISODate(); // $ExpectType string
dt.toISOTime(); // $ExpectType string
dt.toISOWeekDate(); // $ExpectType string
dt.toJSDate(); // $ExpectType Date
dt.toJSON(); // $ExpectType string
dt.toLocaleString(); // $ExpectType string
dt.toLocaleString({ month: 'long', day: 'numeric' }); // $ExpectType string
dt.toLocaleString(DateTime.DATE_MED); // $ExpectType string
dt.toMillis(); // $ExpectType number
dt.toMillis(); // $ExpectType number
dt.toRelative(); // $ExpectType string | null
dt.toRelativeCalendar(); // $ExpectType string | null
dt.toRFC2822(); // $ExpectType string
dt.toSeconds(); // $ExpectType number
dt.toSQL(); // $ExpectType string
dt.toSQL({ includeOffset: false, includeZone: true }); // $ExpectType string
dt.toSQLDate(); // $ExpectType string
dt.toSQLTime(); // $ExpectType string
dt.toSQLTime({ includeOffset: false, includeZone: true }); // $ExpectType string
dt.valueOf(); // $ExpectType number
// $ExpectType string | null
dt.toRelative({
@@ -73,49 +84,70 @@ dt.minus({ days: 7 });
dt.startOf('day');
dt.endOf('hour');
dt.zone;
dt.zoneName;
dt.zoneName; // $ExpectType string
dt.offset; // $ExpectType number
dt.offsetNameShort; // $ExpectType string
dt.offsetNameLong; // $ExpectType string
dt.isOffsetFixed; // $ExpectType boolean
dt.isInDST; // $ExpectType boolean
dt.set({ hour: 3 }).hour;
dt.set({ hour: 3 }).hour; // $ExpectType number
const f = { month: 'long', day: 'numeric' };
dt.setLocale('fr').toLocaleString(f);
dt.setLocale('en-GB').toLocaleString(f);
dt.setLocale('en-US').toLocaleString(f);
DateTime.fromObject({ zone: 'America/Los_Angeles' });
DateTime.local().setZone('America/Los_Angeles');
DateTime.utc(2017, 5, 15);
DateTime.utc();
DateTime.local().toUTC();
DateTime.utc().toLocal();
DateTime.utc(2017, 5, 15); // $ExpectType DateTime
DateTime.utc(); // $ExpectType DateTime
DateTime.local().toUTC(); // $ExpectType DateTime
DateTime.utc().toLocal(); // $ExpectType DateTime
DateTime.fromMillis(1527780819458).toMillis();
DateTime.max(dt, now); // $ExpectType DateTime
DateTime.min(dt, now); // $ExpectType DateTime
const {input, result, zone} = DateTime.fromFormatExplain('Aug 6 1982', 'MMMM d yyyy');
const anything: any = 0;
if (DateTime.isDateTime(anything)) {
anything; // $ExpectType DateTime
}
const { input, result, zone } = DateTime.fromFormatExplain('Aug 6 1982', 'MMMM d yyyy');
/* Duration */
const dur = Duration.fromObject({ hours: 2, minutes: 7 });
dt.plus(dur);
dur.hours;
dur.minutes;
dur.seconds;
dt.plus(dur); // $ExpectType DateTime
dt.plus({ quarters: 2, month: 1 }); // $ExpectType DateTime
dur.hours; // $ExpectType number
dur.minutes; // $ExpectType number
dur.seconds; // $ExpectType number
dur.as('seconds');
dur.as('seconds'); // $ExpectType number
dur.toObject();
dur.toISO();
dur.toISO(); // $ExpectType string
dur.normalize(); // $ExpectType Duration
if (Duration.isDuration(anything)) {
anything; // $ExpectType Duration
}
/* Interval */
const later = DateTime.local();
const i = Interval.fromDateTimes(now, later);
i.length();
i.length('years');
i.contains(DateTime.local(2019));
i.set({end: DateTime.local(2020)});
i.mapEndpoints((d) => d);
i.length(); // $ExpectType number
i.length('years'); // $ExpectType number
i.contains(DateTime.local(2019)); // $ExpectType boolean
i.set({end: DateTime.local(2020)}); // $ExpectType Interval
i.mapEndpoints((d) => d); // $ExpectType Interval
i.toISO();
i.toString();
i.toISO(); // $ExpectType string
i.toString(); // $ExpectType string
i.toDuration('months'); // $ExpectType Duration
if (Interval.isInterval(anything)) {
anything; // $ExpectType Interval
}
/* Info */
Info.months();
@@ -128,6 +160,7 @@ Info.features().zones;
Settings.defaultLocale;
Settings.defaultLocale = 'en';
Settings.defaultZoneName = 'Europe/Paris';
Settings.throwOnInvalid = true;
Settings.now();
Settings.now = () => 0;
Settings.resetCaches();
@@ -135,4 +168,120 @@ Settings.resetCaches();
// $ExpectError
Settings.defaultZone = Settings.defaultZone;
/* Zone */
// The following tests were coped from the docs
// http://moment.github.io/luxon/docs/manual/
/* Intl */
DateTime.local().setLocale("el").toLocaleString(DateTime.DATE_FULL); // $ExpectType string
dt.locale; // $ExpectType string
DateTime.local().setLocale("fr").locale; // $ExpectType string
DateTime.local().reconfigure({ locale: "fr" }).locale; // $ExpectType string
Settings.defaultLocale = "fr";
DateTime.local().locale; // $ExpectType string
Settings.defaultLocale = DateTime.local().resolvedLocaleOpts().locale;
dt.setLocale("fr").toLocaleString(DateTime.DATE_FULL); // $ExpectType string
dt.toLocaleString({ locale: "es", ...DateTime.DATE_FULL }); // $ExpectType string
dt.setLocale("fr").toFormat("MMMM dd, yyyy GG"); // $ExpectType string
DateTime.fromFormat("septembre 25, 2017 après Jésus-Christ", "MMMM dd, yyyy GG", { locale: "fr" });
Info.months("long", { locale: "fr" }); // $ExpectType string[]
Info.weekdays("long", { locale: "fr" }); // $ExpectType string[]
Info.eras("long", { locale: "fr" }); // $ExpectType string[]
DateTime.local().reconfigure({ locale: "it", numberingSystem: "beng" });
Settings.defaultNumberingSystem = "beng";
/* Time zones and offsets */
Info.features().zones; // $ExpectType boolean
const bogus = DateTime.local().setZone("America/Bogus");
bogus.isValid; // $ExpectType boolean
bogus.invalidReason; // $ExpectType string | null
bogus.invalidExplanation; // $ExpectType string | null
const local = DateTime.local(2017, 5, 15, 09, 10, 23);
local.zoneName; // $ExpectType string
local.toString(); // $ExpectType string
local.setZone("America/Los_Angeles"); // $ExpectType DateTime
local.setZone("America/Los_Angeles", { keepLocalTime: true }); // $ExpectType DateTime
const iso = DateTime.fromISO("2017-05-15T09:10:23");
iso.zoneName; // $ExpectType string
iso.toString(); // $ExpectType string
DateTime.fromISO("2017-05-15T09:10:23", { zone: "Europe/Paris", setZone: true }); // $ExpectType DateTime
DateTime.fromFormat("2017-05-15T09:10:23 Europe/Paris", "yyyy-MM-dd'T'HH:mm:ss z"); // $ExpectType DateTime
Settings.defaultZoneName = "Asia/Tokyo";
/* Calendars */
DateTime.fromISO('2017-W23-3').plus({ weeks: 1, days: 2 }).toISOWeekDate(); // $ExpectType string
const dtHebrew = DateTime.local().reconfigure({ outputCalendar: 'hebrew' });
dtHebrew.outputCalendar; // $ExpectType string
dtHebrew.toLocaleString(); // $ExpectType string
DateTime.fromObject({ outputCalendar: 'buddhist' }).toLocaleString(DateTime.DATE_FULL);
Settings.defaultOutputCalendar = 'persian';
/* Formatting */
DateTime.fromISO('2014-08-06T13:07:04.054').toFormat('yyyy LLL dd'); // $ExpectType string
/* Parsing */
DateTime.fromObject({ zone: 'America/Los_Angeles' }); // $ExpectType DateTime
DateTime.fromISO('2016-05-25'); // $ExpectType DateTime
DateTime.fromJSDate(new Date()); // $ExpectType DateTime
DateTime.fromRFC2822('Tue, 01 Nov 2016 13:23:12 +0630'); // $ExpectType DateTime
DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT'); // $ExpectType DateTime
DateTime.fromSQL('2017-05-15 09:24:15'); // $ExpectType DateTime
DateTime.fromMillis(1542674993410); // $ExpectType DateTime
DateTime.fromSeconds(1542674993); // $ExpectType DateTime
DateTime.fromFormat('May 25 1982', 'LLLL dd yyyy'); // $ExpectType DateTime
DateTime.fromFormat('mai 25 1982', 'LLLL dd yyyy', { locale: 'fr' }); // $ExpectType DateTime
DateTime.fromFormatExplain("Aug 6 1982", "MMMM d yyyy").regex;
/* Math */
const d1: DateTime = DateTime.local(2017, 2, 13).plus({ days: 30 });
const d2: DateTime = DateTime.fromISO('2017-04-30').plus({days: 1}).plus({months: 1});
if (d1 < d2 || +d1 === +d2) {
//
}
d1.hasSame(d2, 'millisecond'); // $ExpectType boolean
d1.hasSame(d2, 'minute'); // $ExpectType boolean
d1.hasSame(d2, 'year'); // $ExpectType boolean
dur.toObject().days; // $ExpectType number | undefined
dur.as('minutes'); // $ExpectType number
dur.shiftTo('minutes').toObject().minutes; // $ExpectType number | undefined
DateTime.fromISO("2017-05-15").plus(dur).toISO(); // $ExpectType string
const end = DateTime.fromISO('2017-03-13');
const start = DateTime.fromISO('2017-02-13');
const diffInMonths = end.diff(start, 'months');
diffInMonths.toObject().months; // $ExpectType number | undefined
const diff = end.diff(start);
diff.toObject().milliseconds; // $ExpectType number | undefined
end.diff(start, ['months', 'days']).months; // $ExpectType number
end.diffNow(['months', 'days']); // $ExpectType Duration
dur.as('days'); // $ExpectType number
dur.shiftTo('days').toObject().days; // $ExpectType number | undefined
dur.shiftTo('week', 'hours').toObject().weeks; // $ExpectType number | undefined
DateTime.local().plus(dur.shiftTo('milliseconds')).year; // $ExpectType number
Duration.fromISO('PY23', { conversionAccuracy: 'longterm' }); // $ExpectType Duration
end.diff(start, 'hours', { conversionAccuracy: 'longterm' }); // $ExpectType Duration
end.diff(start, ['months', 'days', 'hours']); // $ExpectType Duration
dur.reconfigure({ conversionAccuracy: 'longterm' }); // $ExpectType Duration
start.until(end); // $ExpectType Interval
i.toDuration(['years', 'months', 'days']); // $ExpectType Duration
+1 -8
View File
@@ -1,8 +1 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-single-declare-module": false,
"interface-over-type-literal": false,
"no-declare-current-package": false
}
}
{ "extends": "dtslint/dt.json" }