-
-
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.
fix: add isToday, isTomorrow, isYesterday plugins (#857)
- Loading branch information
Konstantin Epishev
authored
Apr 8, 2020
1 parent
d568273
commit fc08ab6
Showing
9 changed files
with
115 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,9 @@ | ||
export default (o, c, d) => { | ||
const proto = c.prototype | ||
proto.isToday = function () { | ||
const comparisonTemplate = 'YYYY-MM-DD' | ||
const now = d() | ||
|
||
return this.format(comparisonTemplate) === now.format(comparisonTemplate) | ||
} | ||
} |
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.isTomorrow = function () { | ||
const comparisonTemplate = 'YYYY-MM-DD' | ||
const tomorrow = d().add(1, 'day') | ||
|
||
return ( | ||
this.format(comparisonTemplate) === tomorrow.format(comparisonTemplate) | ||
) | ||
} | ||
} |
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.isYesterday = function () { | ||
const comparisonTemplate = 'YYYY-MM-DD' | ||
const yesterday = d().subtract(1, 'day') | ||
|
||
return ( | ||
this.format(comparisonTemplate) === yesterday.format(comparisonTemplate) | ||
) | ||
} | ||
} |
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() | ||
}) |
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,10 @@ | ||
import { PluginFunc } from 'dayjs' | ||
|
||
declare const plugin: PluginFunc | ||
export = plugin | ||
|
||
declare module 'dayjs' { | ||
interface Dayjs { | ||
isToday(): boolean | ||
} | ||
} |
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,10 @@ | ||
import { PluginFunc } from 'dayjs' | ||
|
||
declare const plugin: PluginFunc | ||
export = plugin | ||
|
||
declare module 'dayjs' { | ||
interface Dayjs { | ||
isTomorrow(): boolean | ||
} | ||
} |
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,10 @@ | ||
import { PluginFunc } from 'dayjs' | ||
|
||
declare const plugin: PluginFunc | ||
export = plugin | ||
|
||
declare module 'dayjs' { | ||
interface Dayjs { | ||
isYesterday(): boolean | ||
} | ||
} |