-
-
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
Showing
3 changed files
with
52 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,12 @@ | ||
export default (o, c) => { | ||
const proto = c.prototype | ||
proto.isoWeeksInYear = function () { | ||
const isLeapYear = this.isLeapYear() | ||
const last = this.endOf('y') | ||
const day = last.day() | ||
if (day === 4 || (isLeapYear && day === 5)) { | ||
return 53 | ||
} | ||
return 52 | ||
} | ||
} |
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 MockDate from 'mockdate' | ||
import dayjs from '../../src' | ||
import isoWeeksInYear from '../../src/plugin/isoWeeksInYear' | ||
import isLeapYear from '../../src/plugin/isLeapYear' | ||
|
||
dayjs.extend(isoWeeksInYear) | ||
dayjs.extend(isLeapYear) | ||
|
||
beforeEach(() => { | ||
MockDate.set(new Date()) | ||
}) | ||
|
||
afterEach(() => { | ||
MockDate.reset() | ||
}) | ||
|
||
it('isoWeeksInYear', () => { | ||
expect(dayjs('2004').isoWeeksInYear()).toBe(53) | ||
expect(dayjs('2005').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2006').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2007').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2008').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2009').isoWeeksInYear()).toBe(53) | ||
expect(dayjs('2010').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2011').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2012').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2013').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2014').isoWeeksInYear()).toBe(52) | ||
expect(dayjs('2015').isoWeeksInYear()).toBe(53) | ||
}) |
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 { | ||
isoWeeksInYear(): number | ||
} | ||
} |