-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lamartire
committed
Apr 7, 2020
1 parent
7e2dcc0
commit c5fb0a1
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default (o, c, d) => { | ||
const proto = c.prototype | ||
proto.isToday = function () { | ||
const comparisonKey = ['$y', '$D', '$m'] | ||
const now = d() | ||
|
||
return comparisonKey.filter(function (key) { | ||
return now[key] !== this[key] | ||
}, this).length === 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default (o, c, d) => { | ||
const proto = c.prototype | ||
proto.isTomorrow = function () { | ||
const comparisonKey = ['$y', '$D', '$m'] | ||
const tomorrow = d().add(1, 'day') | ||
|
||
return comparisonKey.filter(function (key) { | ||
return tomorrow[key] === this[key] | ||
}, this).length === 3 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default (o, c, d) => { | ||
const proto = c.prototype | ||
proto.isYesterday = function () { | ||
const comparisonKey = ['$y', '$D', '$m'] | ||
const yesterday = d().subtract(1, 'day') | ||
|
||
return comparisonKey.filter(function (key) { | ||
return yesterday[key] === this[key] | ||
}, this).length === 3 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import isToday from '../../src/plugin/isToday' | ||
|
||
dayjs.extend(isToday) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('is today', () => { | ||
expect(dayjs(new Date()).isToday()).toBeTruthy() | ||
expect(dayjs('2017-01-01').isToday()).toBeFalsy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import isTomorrow from '../../src/plugin/isTomorrow' | ||
|
||
dayjs.extend(isTomorrow) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('is tomorrow', () => { | ||
expect(dayjs().add(1, 'day').isTomorrow()).toBeTruthy() | ||
expect(dayjs('2017-01-01').isTomorrow('2019-01-01', '2017-01-01')).toBeFalsy() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import isYesterday from '../../src/plugin/isYesterday' | ||
|
||
dayjs.extend(isYesterday) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('is yesterday', () => { | ||
expect(dayjs().subtract(1, 'day').isYesterday()).toBeTruthy() | ||
expect(dayjs('2017-01-01').isYesterday()).toBeFalsy() | ||
}) |