Skip to content

Commit

Permalink
fix: fix it locale error (#458)
Browse files Browse the repository at this point in the history
* fix: fix it locale error

* fix: fix es locale monthsShort error

* test: fix test

* fix: add missing es-do and es-us locale file
  • Loading branch information
iamkun committed Feb 2, 2019
1 parent 7e04004 commit f6d9a64
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/locale/es-es.js → src/locale/es-do.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import dayjs from 'dayjs'

const locale = {
name: 'es-es',
weekdays: 'Domingo_Lunes_Martes_Miércoles_Jueves_Viernes_Sábado'.split('_'),
name: 'es-do',
weekdays: 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
weekdaysShort: 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
weekdaysMin: 'do_lu_ma_mi_ju_vi_sá'.split('_'),
months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
monthsShort: 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
relativeTime: {
future: 'en %s',
past: 'hace %s',
Expand Down
30 changes: 30 additions & 0 deletions src/locale/es-us.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import dayjs from 'dayjs'

const locale = {
name: 'es-us',
weekdays: 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
weekdaysShort: 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
weekdaysMin: 'do_lu_ma_mi_ju_vi_sá'.split('_'),
months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
monthsShort: 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
relativeTime: {
future: 'en %s',
past: 'hace %s',
s: 'unos segundos',
m: 'un minuto',
mm: '%d minutos',
h: 'una hora',
hh: '%d horas',
d: 'un día',
dd: '%d días',
M: 'un mes',
MM: '%d meses',
y: 'un año',
yy: '%d años'
},
ordinal: n => `${n}º`
}

dayjs.locale(locale, null, true)

export default locale
6 changes: 4 additions & 2 deletions src/locale/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import dayjs from 'dayjs'

const locale = {
name: 'es',
weekdays: 'Domingo_Lunes_Martes_Miércoles_Jueves_Viernes_Sábado'.split('_'),
monthsShort: 'ene_feb_mar_abr_may_jun_jul_ago_sep_oct_nov_dic'.split('_'),
weekdays: 'domingo_lunes_martes_miércoles_jueves_viernes_sábado'.split('_'),
weekdaysShort: 'dom._lun._mar._mié._jue._vie._sáb.'.split('_'),
weekdaysMin: 'do_lu_ma_mi_ju_vi_sá'.split('_'),
months: 'Enero_Febrero_Marzo_Abril_Mayo_Junio_Julio_Agosto_Septiembre_Octubre_Noviembre_Diciembre'.split('_'),
monthsShort: 'enero_feb_marzo_abr_mayo_jun_jul_agosto_sept_oct_nov_dic'.split('_'),
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
Expand Down
8 changes: 5 additions & 3 deletions src/locale/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import dayjs from 'dayjs'

const locale = {
name: 'it',
weekdays: 'Domenica_Lunedì_Martedì_Mercoledì_Giovedì_Venerdì_Sabato'.split('_'),
months: 'Gennaio_Febbraio_Marzo_Aprile_Maggio_Giugno_Luglio_Agosto_Settembre_Ottobre_Novembre_Dicembre'.split('_'),
monthsShort: 'genn_febbr_mar_apr_magg_giugno_luglio_ag_sett_ott_nov_dic'.split('_'),
weekdays: 'domenica_lunedì_martedì_mercoledì_giovedì_venerdì_sabato'.split('_'),
weekdaysShort: 'dom_lun_mar_mer_gio_ven_sab'.split('_'),
weekdaysMin: 'do_lu_ma_me_gi_ve_sa'.split('_'),
months: 'gennaio_febbraio_marzo_aprile_maggio_giugno_luglio_agosto_settembre_ottobre_novembre_dicembre'.split('_'),
monthsShort: 'gen_feb_mar_apr_mag_giu_lug_ago_set_ott_nov_dic'.split('_'),
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
Expand Down
26 changes: 13 additions & 13 deletions test/locale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const format = 'dddd D, MMMM'
it('Uses spanish locale through constructor', () => { // not recommend
expect(dayjs('2018-4-28', { locale: es })
.format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
})

it('set locale for one instance only', () => {
Expand All @@ -25,7 +25,7 @@ it('set locale for one instance only', () => {

expect(dayjs('2018-4-28')
.locale(es).format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')

expect(dayjs('2018-4-28')
.format(format))
Expand All @@ -38,7 +38,7 @@ it('set global locale', () => {
.toBe('Saturday 28, April')
dayjs.locale(es)
expect(dayjs('2018-4-28').format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
dayjs.locale('en')
expect(dayjs('2018-4-28').format(format))
.toBe('Saturday 28, April')
Expand All @@ -50,10 +50,10 @@ it('immutable instance locale', () => {
expect(origin.format(format))
.toBe('Saturday 28, April')
expect(origin.locale('es').format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
const changed = origin.locale('es')
expect(changed.format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
expect(origin.format(format))
.toBe('Saturday 28, April')
})
Expand All @@ -73,29 +73,29 @@ describe('Instance locale inheritance', () => {

it('Clone', () => {
expect(esDayjs.clone().format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
expect(dayjs(esDayjs).format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
})

it('StartOf EndOf', () => {
expect(esDayjs.startOf('year').format(format))
.toBe('Lunes 1, Enero')
.toBe('lunes 1, Enero')
expect(esDayjs.endOf('day').format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
})

it('Set', () => {
expect(esDayjs.set('year', 2017).format(format))
.toBe('Viernes 28, Abril')
.toBe('viernes 28, Abril')
})

it('Add', () => {
expect(esDayjs.add(1, 'year').format(format))
.toBe('Domingo 28, Abril')
.toBe('domingo 28, Abril')
expect(esDayjs.add(1, 'month').format(format))
.toBe('Lunes 28, Mayo')
.toBe('lunes 28, Mayo')
expect(esDayjs.add(1, 'minute').format(format))
.toBe('Sábado 28, Abril')
.toBe('sábado 28, Abril')
})
})

0 comments on commit f6d9a64

Please sign in to comment.