File tree 3 files changed +15
-0
lines changed
3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,7 @@ class Dayjs {
346
346
}
347
347
348
348
locale ( preset , object ) {
349
+ if ( ! preset ) return this . $L
349
350
const that = this . clone ( )
350
351
that . $L = parseLocale ( preset , object , true )
351
352
return that
Original file line number Diff line number Diff line change 1
1
import MockDate from 'mockdate'
2
+ import moment from 'moment'
2
3
import dayjs from '../src'
3
4
import es from '../src/locale/es'
4
5
@@ -44,6 +45,17 @@ it('set global locale', () => {
44
45
. toBe ( 'Saturday 28, April' )
45
46
} )
46
47
48
+ it ( 'get instance locale name' , ( ) => {
49
+ expect ( dayjs ( ) . locale ( ) ) . toBe ( 'en' )
50
+ expect ( dayjs ( ) . locale ( ) ) . toBe ( moment ( ) . locale ( ) )
51
+ expect ( dayjs ( ) . locale ( 'es' ) . locale ( ) ) . toBe ( 'es' )
52
+ expect ( dayjs ( ) . locale ( 'es' ) . locale ( ) ) . toBe ( moment ( ) . locale ( 'es' ) . locale ( ) )
53
+ dayjs . locale ( es )
54
+ moment . locale ( 'es' )
55
+ expect ( dayjs ( ) . locale ( ) ) . toBe ( 'es' )
56
+ expect ( dayjs ( ) . locale ( ) ) . toBe ( moment ( ) . locale ( ) )
57
+ } )
58
+
47
59
it ( 'immutable instance locale' , ( ) => {
48
60
dayjs . locale ( 'en' )
49
61
const origin = dayjs ( '2018-4-28' )
Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ declare namespace dayjs {
85
85
86
86
isAfter ( date : ConfigType , unit ?: OpUnitType ) : boolean
87
87
88
+ locale ( ) : string
89
+
88
90
locale ( preset : string | { name : string , [ key : string ] : any } , object ?: { [ key : string ] : any } ) : Dayjs
89
91
}
90
92
You can’t perform that action at this time.
0 commit comments