-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
54 additions
and
1 deletion.
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
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) => { | ||
const proto = c.prototype | ||
proto.weekYear = function () { | ||
const month = this.month() | ||
const weekOfYear = this.week() | ||
const year = this.year() | ||
if (weekOfYear === 1 && month === 11) { | ||
return year + 1 | ||
} | ||
return year | ||
} | ||
} |
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,30 @@ | ||
import moment from 'moment' | ||
import MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import weekYear from '../../src/plugin/weekYear' | ||
import weekOfYear from '../../src/plugin/weekOfYear' | ||
|
||
dayjs.extend(weekYear) | ||
dayjs.extend(weekOfYear) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('Week Year', () => { | ||
const daySet = [ | ||
['2018-12-01', 2018], | ||
['2018-12-30', 2019], | ||
['2018-12-31', 2019], | ||
['2019-01-01', 2019] | ||
] | ||
daySet.forEach((d) => { | ||
const [day, result] = d | ||
expect(dayjs(day).weekYear()).toBe(result) | ||
expect(dayjs(day).weekYear()).toBe(moment(day).weekYear()) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -6,5 +6,7 @@ export = plugin | |
declare module 'dayjs' { | ||
interface Dayjs { | ||
week(): number | ||
|
||
week(value : number): Dayjs | ||
} | ||
} |
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 { | ||
weekYear(): number | ||
} | ||
} |