Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d.ts] first parameter date is optional in isSame(), isBefore(), isAfter() #2272

Merged
merged 2 commits into from
Apr 16, 2023
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
7 changes: 7 additions & 0 deletions test/plugin/isSameOrAfter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/plugin/isSameOrBefore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* ```
Expand All @@ -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.
* ```
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion types/plugin/isSameOrAfter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export = plugin

declare module 'dayjs' {
interface Dayjs {
isSameOrAfter(date: ConfigType, unit?: OpUnitType): boolean
isSameOrAfter(date?: ConfigType, unit?: OpUnitType): boolean
}
}
2 changes: 1 addition & 1 deletion types/plugin/isSameOrBefore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export = plugin

declare module 'dayjs' {
interface Dayjs {
isSameOrBefore(date: ConfigType, unit?: OpUnitType): boolean
isSameOrBefore(date?: ConfigType, unit?: OpUnitType): boolean
}
}
6 changes: 3 additions & 3 deletions types/plugin/isoWeek.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 3 additions & 3 deletions types/plugin/quarterOfYear.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}