File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 4040 "rollup" : " ^0.57.1" ,
4141 "rollup-plugin-babel" : " ^4.0.0-beta.4" ,
4242 "rollup-plugin-uglify" : " ^3.0.0"
43+ },
44+ "dependencies" : {
45+ "lodash" : " ^4.17.5"
4346 }
4447}
Original file line number Diff line number Diff line change 1+ import { cloneDeep } from 'lodash'
12import * as Constant from './constant'
23
34const padStart = ( string , length , pad ) => {
@@ -83,6 +84,9 @@ class Dayjs {
8384 case 'month' :
8485 this . $date . setMonth ( int )
8586 break
87+ case 'year' :
88+ this . $date . setFullYear ( int )
89+ break
8690 default :
8791 break
8892 }
@@ -179,7 +183,7 @@ class Dayjs {
179183 }
180184
181185 clone ( ) {
182- return Object . assign ( Object . create ( this ) , this )
186+ return cloneDeep ( this )
183187 }
184188}
185189
Original file line number Diff line number Diff line change @@ -27,3 +27,17 @@ test('String Other', () => {
2727 global . console . warn = jest . genMockFunction ( ) // moment.js otherString will throw warn
2828 expect ( dayjs ( 'otherString' ) . toString ( ) . toLowerCase ( ) ) . toBe ( moment ( 'otherString' ) . toString ( ) . toLowerCase ( ) )
2929} )
30+
31+ it ( 'Clone not affect each other' , ( ) => {
32+ const base = dayjs ( )
33+ const year = base . year ( )
34+ const another = base . clone ( )
35+ another . set ( 'year' , year + 1 )
36+ expect ( another . unix ( ) - base . unix ( ) ) . toBe ( 31536000 )
37+ } )
38+
39+ it ( 'Clone with same value' , ( ) => {
40+ const base = dayjs ( '20170101' )
41+ const another = base . clone ( )
42+ expect ( base . toString ( ) ) . toBe ( another . toString ( ) )
43+ } )
You can’t perform that action at this time.
0 commit comments