Skip to content

Commit

Permalink
Add missing opts + useLocaleWeeks param to luxon methods
Browse files Browse the repository at this point in the history
Covers changes added in this luxon PR: moment/luxon#1454
  • Loading branch information
jackkoppa committed Jan 4, 2024
1 parent 9adf194 commit da8cb93
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
21 changes: 18 additions & 3 deletions types/luxon/src/datetime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ export interface DiffOptions {
conversionAccuracy?: ConversionAccuracy | undefined;
}

export interface HasSameOptions {
/** If true, use weeks based on the locale, i.e. use the locale-dependent start of the week */
useLocaleWeeks?: boolean
}
export interface StartOfOptions {
/** If true, use weeks based on the locale, i.e. use the locale-dependent start of the week */
useLocaleWeeks?: boolean
}
export interface EndOfOptions {
/** If true, use weeks based on the locale, i.e. use the locale-dependent start of the week */
useLocaleWeeks?: boolean
}

export interface ExplainedFormat {
input: string;
tokens: Array<{ literal: boolean; val: string }>;
Expand Down Expand Up @@ -1145,6 +1158,7 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
* "Set" this DateTime to the beginning of the given unit.
*
* @param unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
* @param opts - options
*
* @example
* DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
Expand All @@ -1157,12 +1171,13 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
* @example
* DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
*/
startOf(unit: DateTimeUnit): this;
startOf(unit: DateTimeUnit, opts?: HasSameOptions): this;

/**
* "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
*
* @param unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
* @param opts - options
*
* @example
* DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
Expand All @@ -1175,7 +1190,7 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
* @example
* DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
*/
endOf(unit: DateTimeUnit): this;
endOf(unit: DateTimeUnit, opts?: EndOfOptions): this;

// OUTPUT

Expand Down Expand Up @@ -1470,7 +1485,7 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
* @example
* DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
*/
hasSame(otherDateTime: DateTime, unit: DateTimeUnit): IfValid<boolean, false, IsValid>;
hasSame(otherDateTime: DateTime, unit: DateTimeUnit, opts: HasSameOptions): IfValid<boolean, false, IsValid>;

/**
* An equality check.
Expand Down
7 changes: 6 additions & 1 deletion types/luxon/src/interval.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type DateInput = DateTime | DateObjectUnits | Date;

export type IntervalMaybeValid = CanBeInvalid extends true ? (Interval<Valid> | Interval<Invalid>) : Interval;

export interface CountOptions {
/** If true, use weeks based on the locale, i.e. use the locale-dependent start of the week */
useLocaleWeeks?: boolean
}

/**
* An Interval object represents a half-open interval of time, where each endpoint is a {@link DateTime}.
* Conceptually, it is a container for those two endpoints, accompanied by methods for
Expand Down Expand Up @@ -119,7 +124,7 @@ export class Interval<IsValid extends boolean = DefaultValidity> {
*
* @param unit - the unit of time to count. Defaults to 'milliseconds'.
*/
count(unit?: DurationUnit): IfValid<number, typeof NaN, IsValid>;
count(unit?: DurationUnit, opts?: CountOptions): IfValid<number, typeof NaN, IsValid>;

/**
* Returns whether this Interval's start and end are both in the same unit of time
Expand Down
3 changes: 3 additions & 0 deletions types/luxon/test/luxon-tests.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ dt.toRelativeCalendar({
dt.plus({ hours: 3, minutes: 2 });
dt.minus({ days: 7 });
dt.startOf("day");
dt.startOf("day", { useLocaleWeeks: true});
// @ts-expect-error
dt.startOf("day", { nonExistentProp: true});
dt.endOf("hour");
dt.zone;
dt.zoneName; // $ExpectType string | null
Expand Down

0 comments on commit da8cb93

Please sign in to comment.