From 4d56f3eb2b3770879d60f824590bf1b32f237d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=91=ED=98=84=EC=84=9D?= Date: Sun, 16 Apr 2023 22:53:30 +0900 Subject: [PATCH] fix: type file first parameter date is optional in isSame(), isBefore(), isAfter() (#2272) --- test/plugin/isSameOrAfter.test.js | 7 +++++++ test/plugin/isSameOrBefore.test.js | 7 +++++++ types/index.d.ts | 6 +++--- types/plugin/isSameOrAfter.d.ts | 2 +- types/plugin/isSameOrBefore.d.ts | 2 +- types/plugin/isoWeek.d.ts | 6 +++--- types/plugin/quarterOfYear.d.ts | 6 +++--- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/test/plugin/isSameOrAfter.test.js b/test/plugin/isSameOrAfter.test.js index fd504c2f8..f5533d763 100644 --- a/test/plugin/isSameOrAfter.test.js +++ b/test/plugin/isSameOrAfter.test.js @@ -49,6 +49,13 @@ test('is same or after without units', () => { expect(+m).toEqual(+mCopy, 'isSameOrAfter second should not change moment') }) +test('is same or after without date', () => { + const past = dayjs().subtract(1, 'day') + const future = dayjs().add(1, 'day') + expect(past.isSameOrAfter()).toBe(false, 'past is before now') + expect(future.isSameOrAfter()).toBe(true, 'future is not before now') +}) + test('is same or after month', () => { const m = dayjs(new Date(2011, 2, 3, 4, 5, 6, 7)) const mCopy = dayjs(m) diff --git a/test/plugin/isSameOrBefore.test.js b/test/plugin/isSameOrBefore.test.js index a8e18215a..3ceff55fa 100644 --- a/test/plugin/isSameOrBefore.test.js +++ b/test/plugin/isSameOrBefore.test.js @@ -34,6 +34,13 @@ test('is same or before without units', () => { expect(+m).toEqual(+mCopy, 'isSameOrBefore second should not change moment') }) +test('is same or before without date', () => { + const past = dayjs().subtract(1, 'day') + const future = dayjs().add(1, 'day') + expect(past.isSameOrBefore()).toBe(true, 'past is before now') + expect(future.isSameOrBefore()).toBe(false, 'future is not before now') +}) + test('is same or before year', () => { const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6)) const mCopy = dayjs(m) diff --git a/types/index.d.ts b/types/index.d.ts index 1ac6c8dac..766bd7943 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -382,7 +382,7 @@ declare namespace dayjs { * * Docs: https://day.js.org/docs/en/query/is-before */ - isBefore(date: ConfigType, unit?: OpUnitType): boolean + isBefore(date?: ConfigType, unit?: OpUnitType): boolean /** * This indicates whether the Day.js object is the same as the other supplied date-time. * ``` @@ -394,7 +394,7 @@ declare namespace dayjs { * ``` * Docs: https://day.js.org/docs/en/query/is-same */ - isSame(date: ConfigType, unit?: OpUnitType): boolean + isSame(date?: ConfigType, unit?: OpUnitType): boolean /** * This indicates whether the Day.js object is after the other supplied date-time. * ``` @@ -408,7 +408,7 @@ declare namespace dayjs { * * Docs: https://day.js.org/docs/en/query/is-after */ - isAfter(date: ConfigType, unit?: OpUnitType): boolean + isAfter(date?: ConfigType, unit?: OpUnitType): boolean locale(): string diff --git a/types/plugin/isSameOrAfter.d.ts b/types/plugin/isSameOrAfter.d.ts index 1c8c26497..916bc801c 100644 --- a/types/plugin/isSameOrAfter.d.ts +++ b/types/plugin/isSameOrAfter.d.ts @@ -5,6 +5,6 @@ export = plugin declare module 'dayjs' { interface Dayjs { - isSameOrAfter(date: ConfigType, unit?: OpUnitType): boolean + isSameOrAfter(date?: ConfigType, unit?: OpUnitType): boolean } } diff --git a/types/plugin/isSameOrBefore.d.ts b/types/plugin/isSameOrBefore.d.ts index 1df5492c0..d52b0955c 100644 --- a/types/plugin/isSameOrBefore.d.ts +++ b/types/plugin/isSameOrBefore.d.ts @@ -5,6 +5,6 @@ export = plugin declare module 'dayjs' { interface Dayjs { - isSameOrBefore(date: ConfigType, unit?: OpUnitType): boolean + isSameOrBefore(date?: ConfigType, unit?: OpUnitType): boolean } } diff --git a/types/plugin/isoWeek.d.ts b/types/plugin/isoWeek.d.ts index 26c591ba6..3f4d88f62 100644 --- a/types/plugin/isoWeek.d.ts +++ b/types/plugin/isoWeek.d.ts @@ -18,10 +18,10 @@ declare module 'dayjs' { endOf(unit: ISOUnitType): Dayjs - isSame(date: ConfigType, unit?: ISOUnitType): boolean + isSame(date?: ConfigType, unit?: ISOUnitType): boolean - isBefore(date: ConfigType, unit?: ISOUnitType): boolean + isBefore(date?: ConfigType, unit?: ISOUnitType): boolean - isAfter(date: ConfigType, unit?: ISOUnitType): boolean + isAfter(date?: ConfigType, unit?: ISOUnitType): boolean } } diff --git a/types/plugin/quarterOfYear.d.ts b/types/plugin/quarterOfYear.d.ts index 8a9cc1e3d..317e0ad2d 100644 --- a/types/plugin/quarterOfYear.d.ts +++ b/types/plugin/quarterOfYear.d.ts @@ -17,10 +17,10 @@ declare module 'dayjs' { endOf(unit: QUnitType | OpUnitType): Dayjs - isSame(date: ConfigType, unit?: QUnitType): boolean + isSame(date?: ConfigType, unit?: QUnitType): boolean - isBefore(date: ConfigType, unit?: QUnitType): boolean + isBefore(date?: ConfigType, unit?: QUnitType): boolean - isAfter(date: ConfigType, unit?: QUnitType): boolean + isAfter(date?: ConfigType, unit?: QUnitType): boolean } }