[@types/luxon] Fix and simplify Duration units.

The units that can be passed as keys in a an object for methods like
`plus` are the same unit that can be passed by string in methods like
`as`. And in both cases both singular and plural versions are accepted
as they [get normalized](https://github.com/moment/luxon/blob/5c449fef840f8023e2444cbb3497272078623a2c/src/duration.js#L233).
This commit is contained in:
Matt R. Wilson
2019-01-22 16:46:35 -05:00
parent a4556aaa16
commit ba50a776ee
2 changed files with 16 additions and 21 deletions
+14 -20
View File
@@ -244,7 +244,9 @@ export class DateTime {
minus(duration: Duration | number | DurationObject): DateTime;
plus(duration: Duration | number | DurationObject): DateTime;
reconfigure(properties: LocaleOptions): DateTime;
resolvedLocaleOpts(options?: DateTimeFormatOptions): Intl.ResolvedDateTimeFormatOptions;
resolvedLocaleOpts(
options?: DateTimeFormatOptions
): Intl.ResolvedDateTimeFormatOptions;
set(values: DateObjectUnits): DateTime;
setLocale(locale: string): DateTime;
setZone(zone: string | Zone, options?: ZoneOptions): DateTime;
@@ -283,37 +285,29 @@ export interface DurationOptions {
}
export interface DurationObjectUnits {
year?: number;
years?: number;
quarter?: number;
quarters?: number;
month?: number;
months?: number;
week?: number;
weeks?: number;
day?: number;
days?: number;
hour?: number;
hours?: number;
minute?: number;
minutes?: number;
second?: number;
seconds?: number;
millisecond?: number;
milliseconds?: number;
}
export interface DurationObject extends DurationObjectUnits, DurationOptions {}
export type DurationUnit =
| "year"
| "years"
| "quarter"
| "quarters"
| "month"
| "months"
| "week"
| "weeks"
| "day"
| "days"
| "hour"
| "hours"
| "minute"
| "minutes"
| "second"
| "seconds"
| "millisecond"
| "milliseconds";
export type DurationUnit = keyof DurationObjectUnits;
export interface DurationToFormatOptions extends DateTimeFormatOptions {
floor?: boolean;
+2 -1
View File
@@ -118,6 +118,7 @@ const { input, result, zone } = DateTime.fromFormatExplain('Aug 6 1982', 'MMMM d
/* Duration */
const dur = Duration.fromObject({ hours: 2, minutes: 7 });
dt.plus(dur); // $ExpectType DateTime
dt.plus({ quarters: 2, month: 1 }); // $ExpectType DateTime
dur.hours; // $ExpectType number
dur.minutes; // $ExpectType number
dur.seconds; // $ExpectType number
@@ -274,7 +275,7 @@ end.diffNow(['months', 'days']); // $ExpectType Duration
dur.as('days'); // $ExpectType number
dur.shiftTo('days').toObject().days; // $ExpectType number | undefined
dur.shiftTo('weeks', 'hours').toObject().weeks; // $ExpectType number | undefined
dur.shiftTo('week', 'hours').toObject().weeks; // $ExpectType number | undefined
DateTime.local().plus(dur.shiftTo('milliseconds')).year; // $ExpectType number
Duration.fromISO('PY23', { conversionAccuracy: 'longterm' }); // $ExpectType Duration