diff --git a/types/luxon/package.json b/types/luxon/package.json index cf3994cae77fdc..470a668c116ac0 100644 --- a/types/luxon/package.json +++ b/types/luxon/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/luxon", - "version": "3.4.9999", + "version": "3.6.9999", "projects": [ "https://github.com/moment/luxon#readme" ], diff --git a/types/luxon/src/datetime.d.ts b/types/luxon/src/datetime.d.ts index fbb66fce3ea373..f7ef8b2f24e2eb 100644 --- a/types/luxon/src/datetime.d.ts +++ b/types/luxon/src/datetime.d.ts @@ -5,6 +5,7 @@ import { StringUnitLength, ToISOFormat, ToISOTimeDurationOptions, + WeekSettings, ZoneOptions, } from "../index"; import { CanBeInvalid, DefaultValidity, IfValid, Invalid, Valid } from "./_util"; @@ -12,6 +13,8 @@ import { Duration, DurationLike, DurationUnits } from "./duration"; import { Interval } from "./interval"; import { Zone } from "./zone"; +export {}; // Turn off default exports + export type DateTimeUnit = "year" | "quarter" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond"; export type ToRelativeUnit = "years" | "quarters" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds"; @@ -304,6 +307,7 @@ export interface LocaleOptions { locale?: string | undefined; outputCalendar?: CalendarSystem | undefined; numberingSystem?: NumberingSystem | undefined; + weekSettings?: WeekSettings | undefined; } export type ResolvedLocaleOptions = Required; @@ -397,6 +401,11 @@ export interface ExplainedFormat { export type DateTimeMaybeValid = CanBeInvalid extends true ? (DateTime | DateTime) : DateTime; +declare const tokenParserBrand: unique symbol; +export interface TokenParser { + [tokenParserBrand]: true; +} + /** * A DateTime is an immutable data structure representing a specific date and time and accompanying methods. * It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them. @@ -1616,6 +1625,25 @@ export class DateTime { */ static fromStringExplain(text: string, fmt: string, options?: DateTimeOptions): ExplainedFormat; + /** + * Build a parser for fmt using the given locale. This parser can be passed to {@link DateTime.fromFormatParser} to a parse a date in this format. This can be used to optimize cases where many dates need to be parsed in a specific format. + * + * @param fmt - the format the string is expected to be in (see description) + * @param options - the Locale options + */ + static buildFormatParser(fmt: string, options?: LocaleOptions): TokenParser; + + /** + * Create a DateTime from an input string and format parser. + * + * The format parser must have been created with the same locale as this call. + * + * @param text the string to parse + * @param formatParser - parser from {@link DateTime.buildFormatParser} + * @param opts options taken by fromFormat() + */ + static fromFormatParser(text: string, formatParser: TokenParser, opts?: DateTimeOptions): DateTimeMaybeValid; + // FORMAT PRESETS /** diff --git a/types/luxon/src/interval.d.ts b/types/luxon/src/interval.d.ts index 8956b437fc91c5..2847bfe5b646ef 100644 --- a/types/luxon/src/interval.d.ts +++ b/types/luxon/src/interval.d.ts @@ -100,6 +100,11 @@ export class Interval { */ get end(): IfValid, null, IsValid>; + /** + * Returns the last DateTime included in the interval (since end is not part of the interval) + */ + get lastDateTime(): IfValid, null, IsValid>; + /** * Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'. */ diff --git a/types/luxon/test/luxon-tests.module.ts b/types/luxon/test/luxon-tests.module.ts index cc767ecd8d2680..37305394c9091b 100644 --- a/types/luxon/test/luxon-tests.module.ts +++ b/types/luxon/test/luxon-tests.module.ts @@ -32,6 +32,8 @@ DateTime.utc(2019, { locale: "en-GB" }, 5); DateTime.isDateTime(0 as unknown); // $ExpectType boolean DateTime.parseFormatForOpts(DateTime.DATETIME_FULL); // $ExpectType string | null DateTime.expandFormat("d", { locale: "en-US" }); // $ExpectType string +const parser = DateTime.buildFormatParser("dd/MM/yyyy", { locale: "en-US" }); +DateTime.fromFormatParser("22/11/1948", parser); // @ts-expect-error new DateTime();