Skip to content

Commit f16051d

Browse files
authored
🤖 Merge PR DefinitelyTyped#72322 [luxon]: Add changes from v 3.6.0 by @mattbishop
1 parent 9c98db7 commit f16051d

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

types/luxon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/luxon",
4-
"version": "3.4.9999",
4+
"version": "3.6.9999",
55
"projects": [
66
"https://github.com/moment/luxon#readme"
77
],

types/luxon/src/datetime.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import {
55
StringUnitLength,
66
ToISOFormat,
77
ToISOTimeDurationOptions,
8+
WeekSettings,
89
ZoneOptions,
910
} from "../index";
1011
import { CanBeInvalid, DefaultValidity, IfValid, Invalid, Valid } from "./_util";
1112
import { Duration, DurationLike, DurationUnits } from "./duration";
1213
import { Interval } from "./interval";
1314
import { Zone } from "./zone";
1415

16+
export {}; // Turn off default exports
17+
1518
export type DateTimeUnit = "year" | "quarter" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond";
1619
export type ToRelativeUnit = "years" | "quarters" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds";
1720

@@ -304,6 +307,7 @@ export interface LocaleOptions {
304307
locale?: string | undefined;
305308
outputCalendar?: CalendarSystem | undefined;
306309
numberingSystem?: NumberingSystem | undefined;
310+
weekSettings?: WeekSettings | undefined;
307311
}
308312

309313
export type ResolvedLocaleOptions = Required<LocaleOptions>;
@@ -397,6 +401,11 @@ export interface ExplainedFormat {
397401

398402
export type DateTimeMaybeValid = CanBeInvalid extends true ? (DateTime<Valid> | DateTime<Invalid>) : DateTime;
399403

404+
declare const tokenParserBrand: unique symbol;
405+
export interface TokenParser {
406+
[tokenParserBrand]: true;
407+
}
408+
400409
/**
401410
* A DateTime is an immutable data structure representing a specific date and time and accompanying methods.
402411
* It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
@@ -1616,6 +1625,25 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
16161625
*/
16171626
static fromStringExplain(text: string, fmt: string, options?: DateTimeOptions): ExplainedFormat;
16181627

1628+
/**
1629+
* 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.
1630+
*
1631+
* @param fmt - the format the string is expected to be in (see description)
1632+
* @param options - the Locale options
1633+
*/
1634+
static buildFormatParser(fmt: string, options?: LocaleOptions): TokenParser;
1635+
1636+
/**
1637+
* Create a DateTime from an input string and format parser.
1638+
*
1639+
* The format parser must have been created with the same locale as this call.
1640+
*
1641+
* @param text the string to parse
1642+
* @param formatParser - parser from {@link DateTime.buildFormatParser}
1643+
* @param opts options taken by fromFormat()
1644+
*/
1645+
static fromFormatParser(text: string, formatParser: TokenParser, opts?: DateTimeOptions): DateTimeMaybeValid;
1646+
16191647
// FORMAT PRESETS
16201648

16211649
/**

types/luxon/src/interval.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ export class Interval<IsValid extends boolean = DefaultValidity> {
100100
*/
101101
get end(): IfValid<DateTime<Valid>, null, IsValid>;
102102

103+
/**
104+
* Returns the last DateTime included in the interval (since end is not part of the interval)
105+
*/
106+
get lastDateTime(): IfValid<DateTime<Valid>, null, IsValid>;
107+
103108
/**
104109
* Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
105110
*/

types/luxon/test/luxon-tests.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ DateTime.utc(2019, { locale: "en-GB" }, 5);
3232
DateTime.isDateTime(0 as unknown); // $ExpectType boolean
3333
DateTime.parseFormatForOpts(DateTime.DATETIME_FULL); // $ExpectType string | null
3434
DateTime.expandFormat("d", { locale: "en-US" }); // $ExpectType string
35+
const parser = DateTime.buildFormatParser("dd/MM/yyyy", { locale: "en-US" });
36+
DateTime.fromFormatParser("22/11/1948", parser)
3537
// @ts-expect-error
3638
new DateTime();
3739

0 commit comments

Comments
 (0)