From 92efd7dc052b419da8f72603b54706f4da572c6d Mon Sep 17 00:00:00 2001 From: dotlouis <1891109+dotlouis@users.noreply.github.com> Date: Thu, 31 Jan 2019 15:43:51 +0100 Subject: [PATCH 1/2] Added shorthand units to UnitType --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 1ef70ca57..372c7c636 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,7 @@ declare namespace dayjs { export type OptionType = { locale: string } - export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date' + export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date' | 'd' | 'M' | 'y' | 'w' | 'h' | 'm' | 's' | 'ms' interface DayjsObject { years: number From 2c9256fe2ef1e04031b51f168d869d4c5adb30a3 Mon Sep 17 00:00:00 2001 From: dotlouis <1891109+dotlouis@users.noreply.github.com> Date: Thu, 31 Jan 2019 22:52:22 +0100 Subject: [PATCH 2/2] Diffenciate basic unit types and operative unit types --- index.d.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 372c7c636..024d47151 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,11 @@ declare namespace dayjs { export type OptionType = { locale: string } - export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date' | 'd' | 'M' | 'y' | 'w' | 'h' | 'm' | 's' | 'ms' + type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms' + export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'quarter' | 'year' | 'date' | UnitTypeShort; + + type OpUnitTypeShort = 'w' + export type OpUnitType = UnitType | "week" | OpUnitTypeShort; interface DayjsObject { years: number @@ -44,17 +48,17 @@ declare namespace dayjs { set(unit: UnitType, value: number): Dayjs - add(value: number, unit: UnitType): Dayjs + add(value: number, unit: OpUnitType): Dayjs - subtract(value: number, unit: UnitType): Dayjs + subtract(value: number, unit: OpUnitType): Dayjs - startOf(unit: UnitType): Dayjs + startOf(unit: OpUnitType): Dayjs - endOf(unit: UnitType): Dayjs + endOf(unit: OpUnitType): Dayjs format(template?: string): string - diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number + diff(dayjs: Dayjs, unit: OpUnitType, float?: boolean): number valueOf(): number @@ -74,11 +78,11 @@ declare namespace dayjs { toString(): string - isBefore(dayjs: Dayjs, unit?: UnitType): boolean + isBefore(dayjs: Dayjs, unit?: OpUnitType): boolean - isSame(dayjs: Dayjs, unit?: UnitType): boolean + isSame(dayjs: Dayjs, unit?: OpUnitType): boolean - isAfter(dayjs: Dayjs, unit?: UnitType): boolean + isAfter(dayjs: Dayjs, unit?: OpUnitType): boolean isLeapYear(): boolean