File tree 4 files changed +35
-4
lines changed
4 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ const isDayjs = d => d instanceof Dayjs // eslint-disable-line no-use-before-def
10
10
11
11
const parseLocale = ( preset , object , isLocal ) => {
12
12
let l
13
- if ( ! preset ) return null
13
+ if ( ! preset ) return L
14
14
if ( typeof preset === 'string' ) {
15
15
if ( Ls [ preset ] ) {
16
16
l = preset
@@ -66,7 +66,7 @@ const parseDate = (cfg) => {
66
66
67
67
class Dayjs {
68
68
constructor ( cfg ) {
69
- this . $L = this . $L || parseLocale ( cfg . locale , null , true ) || L
69
+ this . $L = this . $L || parseLocale ( cfg . locale , null , true )
70
70
this . parse ( cfg ) // for plugin
71
71
}
72
72
Original file line number Diff line number Diff line change 1
- export default ( o , c ) => { // locale needed later
1
+ export default ( o , c , dayjs ) => { // locale needed later
2
2
const proto = c . prototype
3
3
const localeData = function ( ) {
4
4
return {
@@ -12,5 +12,12 @@ export default (o, c) => { // locale needed later
12
12
proto . localeData = function ( ) {
13
13
return localeData . bind ( this ) ( )
14
14
}
15
+
16
+ dayjs . localeData = ( ) => {
17
+ const localeObject = dayjs . Ls [ dayjs . locale ( ) ]
18
+ return {
19
+ firstDayOfWeek : ( ) => localeObject . weekStart || 0
20
+ }
21
+ }
15
22
}
16
23
Original file line number Diff line number Diff line change @@ -110,4 +110,14 @@ describe('Instance locale inheritance', () => {
110
110
expect ( esDayjs . add ( 1 , 'minute' ) . format ( format ) )
111
111
. toBe ( 'sábado 28, Abril' )
112
112
} )
113
+
114
+ it ( 'dayjs.locale() returns locale name' , ( ) => {
115
+ dayjs . locale ( es )
116
+ moment . locale ( 'es' )
117
+ expect ( dayjs . locale ( ) ) . toBe ( moment . locale ( ) )
118
+
119
+ dayjs . locale ( 'en' )
120
+ moment . locale ( 'en' )
121
+ expect ( dayjs . locale ( ) ) . toBe ( moment . locale ( ) )
122
+ } )
113
123
} )
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import MockDate from 'mockdate'
2
2
import moment from 'moment'
3
3
import dayjs from '../../src'
4
4
import localeData from '../../src/plugin/localeData'
5
+ import '../../src/locale/zh-cn'
5
6
6
7
dayjs . extend ( localeData )
7
8
@@ -13,7 +14,7 @@ afterEach(() => {
13
14
MockDate . reset ( )
14
15
} )
15
16
16
- it ( 'localeData' , ( ) => {
17
+ it ( 'instance localeData' , ( ) => {
17
18
const d = dayjs ( )
18
19
const m = moment ( )
19
20
const dayjsLocaleData = dayjs ( ) . localeData ( )
@@ -24,3 +25,16 @@ it('localeData', () => {
24
25
expect ( dayjsLocaleData . weekdaysMin ( d ) ) . toBe ( momentLocaleData . weekdaysMin ( m ) )
25
26
expect ( dayjsLocaleData . weekdaysShort ( d ) ) . toBe ( momentLocaleData . weekdaysShort ( m ) )
26
27
} )
28
+
29
+ it ( 'global localeData' , ( ) => {
30
+ dayjs . locale ( 'zh-cn' )
31
+ moment . locale ( 'zh-cn' )
32
+ let dayjsLocaleData = dayjs . localeData ( )
33
+ let momentLocaleData = moment . localeData ( )
34
+ expect ( dayjsLocaleData . firstDayOfWeek ( ) ) . toBe ( momentLocaleData . firstDayOfWeek ( ) )
35
+ dayjs . locale ( 'en' )
36
+ moment . locale ( 'en' )
37
+ dayjsLocaleData = dayjs . localeData ( )
38
+ momentLocaleData = moment . localeData ( )
39
+ expect ( dayjsLocaleData . firstDayOfWeek ( ) ) . toBe ( momentLocaleData . firstDayOfWeek ( ) )
40
+ } )
You can’t perform that action at this time.
0 commit comments