Skip to content

Commit 4d56f3e

Browse files
authored
fix: type file first parameter date is optional in isSame(), isBefore(), isAfter() (#2272)
1 parent 00c223b commit 4d56f3e

7 files changed

+25
-11
lines changed

test/plugin/isSameOrAfter.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ test('is same or after without units', () => {
4949
expect(+m).toEqual(+mCopy, 'isSameOrAfter second should not change moment')
5050
})
5151

52+
test('is same or after without date', () => {
53+
const past = dayjs().subtract(1, 'day')
54+
const future = dayjs().add(1, 'day')
55+
expect(past.isSameOrAfter()).toBe(false, 'past is before now')
56+
expect(future.isSameOrAfter()).toBe(true, 'future is not before now')
57+
})
58+
5259
test('is same or after month', () => {
5360
const m = dayjs(new Date(2011, 2, 3, 4, 5, 6, 7))
5461
const mCopy = dayjs(m)

test/plugin/isSameOrBefore.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ test('is same or before without units', () => {
3434
expect(+m).toEqual(+mCopy, 'isSameOrBefore second should not change moment')
3535
})
3636

37+
test('is same or before without date', () => {
38+
const past = dayjs().subtract(1, 'day')
39+
const future = dayjs().add(1, 'day')
40+
expect(past.isSameOrBefore()).toBe(true, 'past is before now')
41+
expect(future.isSameOrBefore()).toBe(false, 'future is not before now')
42+
})
43+
3744
test('is same or before year', () => {
3845
const m = dayjs(new Date(2011, 1, 2, 3, 4, 5, 6))
3946
const mCopy = dayjs(m)

types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ declare namespace dayjs {
382382
*
383383
* Docs: https://day.js.org/docs/en/query/is-before
384384
*/
385-
isBefore(date: ConfigType, unit?: OpUnitType): boolean
385+
isBefore(date?: ConfigType, unit?: OpUnitType): boolean
386386
/**
387387
* This indicates whether the Day.js object is the same as the other supplied date-time.
388388
* ```
@@ -394,7 +394,7 @@ declare namespace dayjs {
394394
* ```
395395
* Docs: https://day.js.org/docs/en/query/is-same
396396
*/
397-
isSame(date: ConfigType, unit?: OpUnitType): boolean
397+
isSame(date?: ConfigType, unit?: OpUnitType): boolean
398398
/**
399399
* This indicates whether the Day.js object is after the other supplied date-time.
400400
* ```
@@ -408,7 +408,7 @@ declare namespace dayjs {
408408
*
409409
* Docs: https://day.js.org/docs/en/query/is-after
410410
*/
411-
isAfter(date: ConfigType, unit?: OpUnitType): boolean
411+
isAfter(date?: ConfigType, unit?: OpUnitType): boolean
412412

413413
locale(): string
414414

types/plugin/isSameOrAfter.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export = plugin
55

66
declare module 'dayjs' {
77
interface Dayjs {
8-
isSameOrAfter(date: ConfigType, unit?: OpUnitType): boolean
8+
isSameOrAfter(date?: ConfigType, unit?: OpUnitType): boolean
99
}
1010
}

types/plugin/isSameOrBefore.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export = plugin
55

66
declare module 'dayjs' {
77
interface Dayjs {
8-
isSameOrBefore(date: ConfigType, unit?: OpUnitType): boolean
8+
isSameOrBefore(date?: ConfigType, unit?: OpUnitType): boolean
99
}
1010
}

types/plugin/isoWeek.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ declare module 'dayjs' {
1818

1919
endOf(unit: ISOUnitType): Dayjs
2020

21-
isSame(date: ConfigType, unit?: ISOUnitType): boolean
21+
isSame(date?: ConfigType, unit?: ISOUnitType): boolean
2222

23-
isBefore(date: ConfigType, unit?: ISOUnitType): boolean
23+
isBefore(date?: ConfigType, unit?: ISOUnitType): boolean
2424

25-
isAfter(date: ConfigType, unit?: ISOUnitType): boolean
25+
isAfter(date?: ConfigType, unit?: ISOUnitType): boolean
2626
}
2727
}

types/plugin/quarterOfYear.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ declare module 'dayjs' {
1717

1818
endOf(unit: QUnitType | OpUnitType): Dayjs
1919

20-
isSame(date: ConfigType, unit?: QUnitType): boolean
20+
isSame(date?: ConfigType, unit?: QUnitType): boolean
2121

22-
isBefore(date: ConfigType, unit?: QUnitType): boolean
22+
isBefore(date?: ConfigType, unit?: QUnitType): boolean
2323

24-
isAfter(date: ConfigType, unit?: QUnitType): boolean
24+
isAfter(date?: ConfigType, unit?: QUnitType): boolean
2525
}
2626
}

0 commit comments

Comments
 (0)