File tree 5 files changed +54
-1
lines changed
5 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ const locale = {
7
7
weekdaysMin : '日_一_二_三_四_五_六' . split ( '_' ) ,
8
8
months : '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月' . split ( '_' ) ,
9
9
monthsShort : '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月' . split ( '_' ) ,
10
- ordinal1 : n => `${ n } 日` ,
11
10
ordinal : ( number , period ) => {
12
11
switch ( period ) {
13
12
case 'W' :
Original file line number Diff line number Diff line change
1
+ export default ( o , c ) => {
2
+ const proto = c . prototype
3
+ proto . weekYear = function ( ) {
4
+ const month = this . month ( )
5
+ const weekOfYear = this . week ( )
6
+ const year = this . year ( )
7
+ if ( weekOfYear === 1 && month === 11 ) {
8
+ return year + 1
9
+ }
10
+ return year
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ import moment from 'moment'
2
+ import MockDate from 'mockdate'
3
+ import dayjs from '../../src'
4
+ import weekYear from '../../src/plugin/weekYear'
5
+ import weekOfYear from '../../src/plugin/weekOfYear'
6
+
7
+ dayjs . extend ( weekYear )
8
+ dayjs . extend ( weekOfYear )
9
+
10
+ beforeEach ( ( ) => {
11
+ MockDate . set ( new Date ( ) )
12
+ } )
13
+
14
+ afterEach ( ( ) => {
15
+ MockDate . reset ( )
16
+ } )
17
+
18
+ it ( 'Week Year' , ( ) => {
19
+ const daySet = [
20
+ [ '2018-12-01' , 2018 ] ,
21
+ [ '2018-12-30' , 2019 ] ,
22
+ [ '2018-12-31' , 2019 ] ,
23
+ [ '2019-01-01' , 2019 ]
24
+ ]
25
+ daySet . forEach ( ( d ) => {
26
+ const [ day , result ] = d
27
+ expect ( dayjs ( day ) . weekYear ( ) ) . toBe ( result )
28
+ expect ( dayjs ( day ) . weekYear ( ) ) . toBe ( moment ( day ) . weekYear ( ) )
29
+ } )
30
+ } )
Original file line number Diff line number Diff line change @@ -6,5 +6,7 @@ export = plugin
6
6
declare module 'dayjs' {
7
7
interface Dayjs {
8
8
week ( ) : number
9
+
10
+ week ( value : number ) : Dayjs
9
11
}
10
12
}
Original file line number Diff line number Diff line change
1
+ import { PluginFunc } from 'dayjs'
2
+
3
+ declare const plugin : PluginFunc
4
+ export = plugin
5
+
6
+ declare module 'dayjs' {
7
+ interface Dayjs {
8
+ weekYear ( ) : number
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments