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

Query method supports Dayjs constructor args #74

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 6 additions & 3 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,33 +455,36 @@ dayjs().toString();

* returns a Boolean

Check if a `Dayjs` object is before another `Dayjs` object.
Check if a `Dayjs` is before another `Dayjs`.

```js
dayjs().isBefore(Dayjs);
dayjs().isBefore(dayjs()); // false
dayjs().isBefore(Date.now()); // false
```

#### Is Same

* returns a Boolean

Check if a `Dayjs` object is same as another `Dayjs` object.
Check if a `Dayjs` is same as another `Dayjs`.

```js
dayjs().isSame(Dayjs);
dayjs().isSame(dayjs()); // true
dayjs().isSame(Date.now()); // true
```

#### Is After

* returns a Boolean

Check if a `Dayjs` object is after another `Dayjs` object.
Check if a `Dayjs` is after another `Dayjs`.

```js
dayjs().isAfter(Dayjs);
dayjs().isAfter(dayjs()); // false
dayjs().isAfter(Date.now()); // false
```

#### Is Leap Year
Expand Down
9 changes: 6 additions & 3 deletions ReadMe.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,26 +346,29 @@ dayjs().toString();
#### 是否之前
- return Boolean

检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之前
检查一个 `Dayjs` 是否在另一个 `Dayjs` 时间之前
```js
dayjs().isBefore(Dayjs);
dayjs().isBefore(dayjs()); // false
dayjs().isBefore(Date.now()); // false
```
#### 是否相同
- return Boolean

检查一个 `Dayjs` 对象是否和另一个 `Dayjs` 对象时间相同
检查一个 `Dayjs` 是否和另一个 `Dayjs` 时间相同
```js
dayjs().isSame(Dayjs);
dayjs().isSame(dayjs()); // true
dayjs().isSame(Date.now()); // true
```
#### 是否之后
- return Boolean

检查一个 `Dayjs` 对象是否在另一个 `Dayjs` 对象时间之后
检查一个 `Dayjs` 是否在另一个 `Dayjs` 时间之后
```js
dayjs().isAfter(Dayjs);
dayjs().isAfter(dayjs()); // false
dayjs().isAfter(Date.now()); // false
```
#### 是否闰年
- return Boolean
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class Dayjs {
}

isSame(that) {
return this.valueOf() === that.valueOf()
return this.valueOf() === (that instanceof Dayjs ? that : new Dayjs(that)).valueOf()
}

isBefore(that) {
return this.valueOf() < that.valueOf()
return this.valueOf() < (that instanceof Dayjs ? that : new Dayjs(that)).valueOf()
}

isAfter(that) {
return this.valueOf() > that.valueOf()
return this.valueOf() > (that instanceof Dayjs ? that : new Dayjs(that)).valueOf()
}

year() {
Expand Down
3 changes: 3 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ it('Is Before Is After Is Same', () => {
const dayB = dayA.clone().add(1, 'day')
const dayC = dayA.clone().subtract(1, 'day')
expect(dayC.isBefore(dayA)).toBe(true)
expect(dayC.isBefore(Date.now() + 1)).toBe(true)
expect(dayA.isSame(instance())).toBe(true)
expect(dayA.isSame(Date.now())).toBe(true)
expect(dayB.isAfter(dayA)).toBe(true)
expect(dayB.isAfter(Date.now() - 1)).toBe(true)
})
})