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
1 change: 0 additions & 1 deletion attw.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
"leveldown",
"lint-staged",
"locutus",
"luxon",
"mapbox__mapbox-sdk",
"mapboxgl-spiderifier",
"marv",
Expand Down
1 change: 1 addition & 0 deletions types/luxon/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./index.js";
2 changes: 0 additions & 2 deletions types/luxon/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Minimum TypeScript Version: 4.3

export * from "./src/luxon";

export as namespace luxon;
10 changes: 9 additions & 1 deletion types/luxon/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"private": true,
"name": "@types/luxon",
"version": "3.6.9999",
"version": "3.7.9999",
"projects": [
"https://github.com/moment/luxon#readme"
],
"exports": {
".": {
"import": "./index.d.mts",
"require": "./index.d.ts"
},
"./package.json": "./package.json"
},
"minimumTypeScriptVersion": "4.3",
"devDependencies": {
"@types/luxon": "workspace:."
},
Expand Down
73 changes: 51 additions & 22 deletions types/luxon/src/datetime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
DateTimeFormatOptions,
NumberingSystem,
StringUnitLength,
ToISOFormat,
ToISOTimeDurationOptions,
WeekSettings,
ZoneOptions,
Expand Down Expand Up @@ -220,22 +219,31 @@ export type _ToObjectUnit = Exclude<DateTimeUnit, "quarter" | "week">;

export interface ToRelativeOptions extends Omit<ToRelativeCalendarOptions, "unit"> {
/**
* The style of units, must be "long", "short", or "narrow".
* @default long
*/
style?: StringUnitLength | undefined;
/** @default true */
/**
* A single unit or an array of units. If an array is supplied, the method will pick the best one
* to use from the array. If omitted, the method will pick the unit from a default set.
*/
unit?: ToRelativeUnit | ToRelativeUnit[] | undefined;
/**
* Whether or not to round the numbers in the output.
* @default true
*/
round?: boolean | undefined;
/**
* Rounding method to use when rounding the numbers in the output
* @default 'trunc'
*/
rounding?: "trunc" | "expand" | "round" | "floor" | "ceil" | undefined;
/**
* Padding in milliseconds. This allows you to round up the result if it fits inside the threshold.
* Do not use this in combination with `{round: false}` because the decimal output will include the padding.
* @default 0
*/
padding?: number | undefined;
/**
* A single unit or an array of units. If an array is supplied, the method will pick the best one
* to use from the array. If omitted, the method will pick the unit from a default set.
*/
unit?: ToRelativeUnit | ToRelativeUnit[] | undefined;
}

export interface ToRelativeCalendarOptions {
Expand Down Expand Up @@ -275,12 +283,12 @@ export interface ToSQLOptions {
includeOffsetSpace?: boolean;
}

export interface ToISODateOptions {
export interface ToISODateOptions extends Pick<ToISOTimeDurationOptions, "format"> {
/**
* Choose between the basic and extended format
* @default 'extended'
* Truncate output to desired presicion.
* @default 'day'
*/
format?: ToISOFormat | undefined;
precision?: "year" | "years" | "month" | "months" | "day" | "days" | undefined;
}

export interface ToISOTimeOptions extends ToISOTimeDurationOptions {
Expand All @@ -295,6 +303,29 @@ export interface ToISOTimeOptions extends ToISOTimeDurationOptions {
* @default false
*/
extendedZone?: boolean | undefined;

/**
* Truncate output to desired presicion.
* When precision and suppressSeconds or suppressMilliseconds are used together,
* precision sets the maximum unit shown in the output,
* however seconds or milliseconds will still be suppressed if they are 0.
* @default 'milliseconds'
*/
precision?:
| "year"
| "years"
| "month"
| "months"
| "day"
| "days"
| "hour"
| "hours"
| "minute"
| "minutes"
| "second"
| "seconds"
| "millisecond"
| "milliseconds";
}

/** @deprecated alias for backwards compatibility */
Expand Down Expand Up @@ -1427,19 +1458,22 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
* DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
* @example
* DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
* @example
* DateTime.now().toISO({ precision: 'day' }) //=> '2017-04-22Z'
* @example
* DateTime.now().toISO({ precision: 'minute' }) //=> '2017-04-22T20:47Z'
*/
toISO(opts?: ToISOTimeOptions): IfValid<string, null, IsValid>;

/**
* Returns an ISO 8601-compliant string representation of this DateTime's date component
*
* @param opts - options
* @param opts.format - choose between the basic and extended format. Defaults to 'extended'.
*
* @example
* DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
* @example
* DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
* @example
* DateTime.utc(1982, 5, 25).toISODate({ precision: 'month' }) //=> '1982-05'
*/
toISODate(opts?: ToISODateOptions): IfValid<string, null, IsValid>;

Expand All @@ -1454,13 +1488,6 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
/**
* Returns an ISO 8601-compliant string representation of this DateTime's time component
*
* @param opts - options
* @param opts.suppressMilliseconds - exclude milliseconds from the format if they're 0. Defaults to false.
* @param opts.suppressSeconds - exclude seconds from the format if they're 0. Defaults to false.
* @param opts.includeOffset - include the offset, such as 'Z' or '-04:00'. Defaults to true.
* @param opts.includePrefix - include the `T` prefix. Defaults to false.
* @param opts.format - choose between the basic and extended format. Defaults to 'extended'.
*
* @example
* DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
* @example
Expand All @@ -1469,6 +1496,8 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
* DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
* @example
* DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
* @example
* DateTime.utc().set({ hour: 7, minute: 34, second: 56 }).toISOTime({ precision: 'minute' }) //=> '07:34Z'
*/
toISOTime(opts?: ToISOTimeOptions): IfValid<string, null, IsValid>;

Expand Down Expand Up @@ -1650,7 +1679,7 @@ export class DateTime<IsValid extends boolean = DefaultValidity> {
/**
* Returns a string representation of this time relative to now, such as "in two days".
* Can only internationalize if your platform supports Intl.RelativeTimeFormat.
* Rounds down by default.
* Rounds towards zero by default.
*
* @example
* DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
Expand Down
52 changes: 43 additions & 9 deletions types/luxon/src/duration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ export interface ToISOTimeDurationOptions {
}

export interface ToHumanDurationOptions extends Intl.NumberFormatOptions {
/**
* How to format the merged list.
* Corresponds to the `style` property of the options parameter of the native `Intl.ListFormat` constructor.
* @default 'narrow'
*/
listStyle?: "long" | "short" | "narrow" | undefined;
/**
* Show all units previously used by the duration even if they are zero.
* @default true
*/
showZeros?: boolean | undefined;
}

/**
Expand All @@ -78,6 +88,19 @@ export type DurationLike = Duration | DurationLikeObject | number;

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

export interface DurationFormatOptions {
/**
* Whether or not to floor numerical values.
* @default true
*/
floor?: boolean | undefined;
/**
* How to handle signs
* @default 'negative'
*/
signMode?: "negative" | "all" | "negativeLargestOnly" | undefined;
}

/**
* A Duration object represents a period of time, like "2 months" or "1 day, 1 hour".
* Conceptually, it is just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them.
Expand Down Expand Up @@ -218,29 +241,32 @@ export class Duration<IsValid extends boolean = DefaultValidity> {
* * Add padding by repeating the token, e.g. "yy" pads the years to two digits, "hhhh" pads the hours out to four digits
* * The duration will be converted to the set of units in the format string using {@link Duration.shiftTo} and the Duration's conversion accuracy setting.
*
* @param fmt - the format string
* @param opts - options
* @param opts.floor - floor numerical values. Defaults to true.
*
* @example
* Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("y d s") //=> "1 6 2"
* @example
* Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("yy dd sss") //=> "01 06 002"
* @example
* Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("M S") //=> "12 518402000"
* @example
* Duration.fromObject({ days: 6, seconds: 2 }).toFormat("d s", { signMode: "all" }) //=> "+6 +2"
* @example
* Duration.fromObject({ days: -6, seconds: -2 }).toFormat("d s", { signMode: "all" }) //=> "-6 -2"
* @example
* Duration.fromObject({ days: -6, seconds: -2 }).toFormat("d s", { signMode: "negativeLargestOnly" }) //=> "-6 2"
*/
toFormat(fmt: string, opts?: { floor?: boolean | undefined }): IfValid<string, "Invalid Duration", IsValid>;
toFormat(fmt: string, opts?: DurationFormatOptions): IfValid<string, "Invalid Duration", IsValid>;

/**
* Returns a string representation of a Duration with all units included
* To modify its behavior use the `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant. See {@link Intl.NumberFormat}.
*
* @example
* ```js
* var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
* dur.toHuman() //=> '1 day, 5 hours, 6 minutes'
* dur.toHuman({ listStyle: "long" }) //=> '1 day, 5 hours, and 6 minutes'
* dur.toHuman({ unitDisplay: "short" }) //=> '1 day, 5 hr, 6 min'
* var dur = Duration.fromObject({ months: 1, weeks: 0, hours: 5, minutes: 6 })
* dur.toHuman() //=> '1 month, 0 weeks, 5 hours, 6 minutes'
* dur.toHuman({ listStyle: "long" }) //=> '1 month, 0 weeks, 5 hours, and 6 minutes'
* dur.toHuman({ unitDisplay: "short" }) //=> '1 mth, 0 wks, 5 hr, 6 min'
* dur.toHuman({ showZeros: false }) //=> '1 month, 5 hours, 6 minutes'
* ```
*/
toHuman(opts?: ToHumanDurationOptions): string;
Expand Down Expand Up @@ -425,6 +451,14 @@ export class Duration<IsValid extends boolean = DefaultValidity> {
*/
negate(): this;

/**
* Removes all units with values equal to 0 from this Duration.
*
* @example
* Duration.fromObject({ years: 2, days: 0, hours: 0, minutes: 0 }).removeZeros().toObject() //=> { years: 2 }
*/
removeZeros(): this;

/**
* Get the years.
*/
Expand Down
3 changes: 2 additions & 1 deletion types/luxon/src/interval.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class Interval<IsValid extends boolean = DefaultValidity> {
get start(): IfValid<DateTime<Valid>, null, IsValid>;

/**
* Returns the end of the Interval
* Returns the end of the Interval. This is the first instant which is not part of the interval.
* (Interval is half-open).
*/
get end(): IfValid<DateTime<Valid>, null, IsValid>;

Expand Down
Loading