Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/luxon/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/luxon",
"version": "3.4.9999",
"version": "3.6.9999",
"projects": [
"https://github.com/moment/luxon#readme"
],
Expand Down
28 changes: 28 additions & 0 deletions types/luxon/src/datetime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import {
StringUnitLength,
ToISOFormat,
ToISOTimeDurationOptions,
WeekSettings,
ZoneOptions,
} from "../index";
import { CanBeInvalid, DefaultValidity, IfValid, Invalid, Valid } from "./_util";
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";

Expand Down Expand Up @@ -304,6 +307,7 @@ export interface LocaleOptions {
locale?: string | undefined;
outputCalendar?: CalendarSystem | undefined;
numberingSystem?: NumberingSystem | undefined;
weekSettings?: WeekSettings | undefined;
}

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

export type DateTimeMaybeValid = CanBeInvalid extends true ? (DateTime<Valid> | DateTime<Invalid>) : 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.
Expand Down Expand Up @@ -1616,6 +1625,25 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
*/
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

/**
Expand Down
5 changes: 5 additions & 0 deletions types/luxon/src/interval.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export class Interval<IsValid extends boolean = DefaultValidity> {
*/
get end(): IfValid<DateTime<Valid>, null, IsValid>;

/**
* Returns the last DateTime included in the interval (since end is not part of the interval)
*/
get lastDateTime(): IfValid<DateTime<Valid>, null, IsValid>;

/**
* Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'.
*/
Expand Down
2 changes: 2 additions & 0 deletions types/luxon/test/luxon-tests.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down