Skip to content

Commit

Permalink
Merge branch 'dev' into fix/diff
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun authored Feb 2, 2019
2 parents e8e3929 + 3bd06f2 commit b56c77d
Show file tree
Hide file tree
Showing 36 changed files with 411 additions and 32 deletions.
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ package-lock.json
coverage

# dev
src
test
build
.babelrc
Expand Down
1 change: 1 addition & 0 deletions docs/en/API-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ dayjs("2019-01-25").format("DD/MM/YYYY"); // '25/01/2019'
| `a` | am pm | |

- More available formats `Q Do k kk X x ...` in plugin [`AdvancedFormat`](./Plugin.md#advancedformat)
- Localized format options `L LT LTS ...` in plugin [`LocalizedFormat`](./Plugin.md#localizedFormat)

### Difference `.diff(compared: Dayjs, unit: string (default: 'milliseconds'), float?: boolean)`

Expand Down
8 changes: 8 additions & 0 deletions docs/en/I18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ const localeObject = {
months: 'Enero_Febrero ... '.split('_'), // months Array
monthsShort: 'Jan_F'.split('_'), // OPTIONAL, short months Array, use first three letters if not provided
ordinal: n => `${n}º`, // ordinal Function (number) => return number + output
formats: { // abbreviated format options allowing localization
LTS: 'h:mm:ss A',
LT: 'h:mm A',
L: 'MM/DD/YYYY',
LL: 'MMMM D, YYYY',
LLL: 'MMMM D, YYYY h:mm A',
LLLL: 'dddd, MMMM D, YYYY h:mm A'
},
relativeTime: { // relative time format strings, keep %s %d as the same
future: 'in %s', // e.g. in 2 hours, %s been replaced with 2hours
past: '%s ago',
Expand Down
22 changes: 22 additions & 0 deletions docs/en/Plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ List of added formats:
| `X` | 1360013296 | Unix Timestamp in second |
| `x` | 1360013296123 | Unix Timestamp in millisecond |

### LocalizedFormat
- LocalizedFormat extends `dayjs().format` API to supply localized format options known from Moment.js.

```javascript
import LocalizedFormat from 'dayjs/plugin/localizedFormat'

dayjs.extend(LocalizedFormat)

dayjs().format('L LT')
```

List of added formats:

| Format | English Locale | Sample Output |
| ------ | ------------------------- | --------------------------------- |
| `LT` | h:mm A | 8:02 PM |
| `LTS` | h:mm:ss A | 8:02:18 PM |
| `L` | MM/DD/YYYY | 08/16/2018 |
| `LL` | MMMM D, YYYY | August 16, 2018 |
| `LLL` | MMMM D, YYYY h:mm A | August 16, 2018 8:02 PM |
| `LLLL` | dddd, MMMM D, YYYY h:mm A | Thursday, August 16, 2018 8:02 PM |

### RelativeTime
- RelativeTime adds `.from` `.to` `.fromNow` `.toNow` APIs to formats date to relative time strings (e.g. 3 hours ago).

Expand Down
24 changes: 14 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
export = dayjs;

declare function dayjs (config?: dayjs.ConfigType, option?: dayjs.OptionType): dayjs.Dayjs
export default dayjs

declare namespace dayjs {
export type ConfigType = string | number | Date | Dayjs

export type OptionType = { locale: string }

export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date'
type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms'
export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'quarter' | 'year' | 'date' | UnitTypeShort;

type OpUnitTypeShort = 'w'
export type OpUnitType = UnitType | "week" | OpUnitTypeShort;

interface DayjsObject {
years: number
Expand Down Expand Up @@ -44,17 +48,17 @@ declare namespace dayjs {

set(unit: UnitType, value: number): Dayjs

add(value: number, unit: UnitType): Dayjs
add(value: number, unit: OpUnitType): Dayjs

subtract(value: number, unit: UnitType): Dayjs
subtract(value: number, unit: OpUnitType): Dayjs

startOf(unit: UnitType): Dayjs
startOf(unit: OpUnitType): Dayjs

endOf(unit: UnitType): Dayjs
endOf(unit: OpUnitType): Dayjs

format(template?: string): string

diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number
diff(dayjs: Dayjs, unit: OpUnitType, float?: boolean): number

valueOf(): number

Expand All @@ -74,11 +78,11 @@ declare namespace dayjs {

toString(): string

isBefore(dayjs: Dayjs, unit?: UnitType): boolean
isBefore(dayjs: Dayjs, unit?: OpUnitType): boolean

isSame(dayjs: Dayjs, unit?: UnitType): boolean
isSame(dayjs: Dayjs, unit?: OpUnitType): boolean

isAfter(dayjs: Dayjs, unit?: UnitType): boolean
isAfter(dayjs: Dayjs, unit?: OpUnitType): boolean

isLeapYear(): boolean

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "2KB immutable date time library alternative to Moment.js with the same modern API ",
"main": "dayjs.min.js",
"types": "index.d.ts",
"module": "./src/index.js",
"scripts": {
"test": "jest",
"test-dst": "TZ=Pacific/Auckland npm run dst-test && TZ=Europe/London npm run dst-test && npm run dst-test",
Expand Down
10 changes: 9 additions & 1 deletion src/locale/bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ const locale = {
name: 'bg',
weekdays: 'Неделя_Понеделник_Вторник_Сряда_Четвъртък_Петък_Събота'.split('_'),
months: 'Януари_Февруари_Март_Април_Май_Юни_Юли_Август_Септември_Октомври_Ноември_Декември'.split('_'),
ordinal: n => `${n}.`
ordinal: n => `${n}.`,
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
L: 'D.MM.YYYY',
LL: 'D MMMM YYYY',
LLL: 'D MMMM YYYY H:mm',
LLLL: 'dddd, D MMMM YYYY H:mm'
}
}

dayjs.locale(locale, null, true)
Expand Down
8 changes: 8 additions & 0 deletions src/locale/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const locale = {
name: 'ca',
weekdays: 'Diumenge_Dilluns_Dimarts_Dimecres_Dijous_Divendres_Dissabte'.split('_'),
months: 'Gener_Febrer_Març_Abril_Maig_Juny_Juliol_Agost_Setembre_Octubre_Novembre_Desembre'.split('_'),
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
L: 'DD/MM/YYYY',
LL: 'D MMMM [de] YYYY',
LLL: 'D MMMM [de] YYYY [a les] H:mm',
LLLL: 'dddd D MMMM [de] YYYY [a les] H:mm'
},
relativeTime: {
future: 'en %s',
past: 'fa %s',
Expand Down
35 changes: 35 additions & 0 deletions src/locale/cs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import dayjs from 'dayjs'

const locale = {
name: 'cs',
weekdays: 'neděle_pondělí_úterý_středa_čtvrtek_pátek_sobota'.split('_'),
months: 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split('_'),
ordinal: n => `${n}.`,
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY H:mm',
LLLL: 'dddd D. MMMM YYYY H:mm'
},
relativeTime: {
future: 'za %s',
past: 'před %s',
s: 'několik sekund',
m: 'minuta',
mm: '%d minut',
h: 'hodina',
hh: '%d hodin',
d: 'den',
dd: '%d dnů',
M: 'měsíc',
MM: '%d měsíců',
y: 'rok',
yy: '%d roků'
}
}

dayjs.locale(locale, null, true)

export default locale
8 changes: 8 additions & 0 deletions src/locale/da.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const locale = {
weekdays: 'søndag_mandag_tirsdag_onsdag_torsdag_fredag_lørdag'.split('_'),
months: 'januar_februar_marts_april_maj_juni_juli_august_september_oktober_november_december'.split('_'),
ordinal: n => `${n}.`,
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY HH:mm',
LLLL: 'dddd [d.] D. MMMM YYYY [kl.] HH:mm'
},
relativeTime: {
future: 'om %s',
past: '%s siden',
Expand Down
8 changes: 8 additions & 0 deletions src/locale/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const locale = {
months: 'Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'),
monthsShort: 'Jan_Feb_März_Apr_Mai_Juni_Juli_Aug_Sept_Okt_Nov_Dez'.split('_'),
ordinal: n => `${n}.`,
formats: {
LTS: 'HH:mm:ss',
LT: 'HH:mm',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY HH:mm',
LLLL: 'dddd, D. MMMM YYYY HH:mm'
},
relativeTime: {
future: 'in %s',
past: 'vor %s',
Expand Down
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
14 changes: 12 additions & 2 deletions src/locale/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ 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',
L: 'DD/MM/YYYY',
LL: 'D [de] MMMM [de] YYYY',
LLL: 'D [de] MMMM [de] YYYY H:mm',
LLLL: 'dddd, D [de] MMMM [de] YYYY H:mm'
},
relativeTime: {
future: 'en %s',
past: 'hace %s',
Expand Down
8 changes: 8 additions & 0 deletions src/locale/fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const locale = {
weekdays: 'یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه'.split('_'),
months: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
ordinal: n => n,
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD/MM/YYYY',
LL: 'D MMMM YYYY',
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd, D MMMM YYYY HH:mm'
},
relativeTime: {
future: '%s در',
past: 'پیش %s',
Expand Down
8 changes: 8 additions & 0 deletions src/locale/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const locale = {
weekdays: 'Dimanche_Lundi_Mardi_Mercredi_Jeudi_Vendredi_Samedi'.split('_'),
months: 'Janvier_Février_Mars_Avril_Mai_Juin_Juillet_Août_Septembre_Octobre_Novembre_Décembre'.split('_'),
monthsShort: 'janv_févr_mars_avril_mai_juin_juil_août_sept_oct_nov_déc'.split('_'),
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'DD/MM/YYYY',
LL: 'D MMMM YYYY',
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
relativeTime: {
future: 'dans %s',
past: 'il y a %s',
Expand Down
8 changes: 8 additions & 0 deletions src/locale/hr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const locale = {
name: 'hr',
weekdays: 'Nedjelja_Ponedjeljak_Utorak_Srijeda_Četvrtak_Petak_Subota'.split('_'),
months: 'Siječanj_Veljača_Ožujak_Travanj_Svibanj_Lipanj_Srpanj_Kolovoz_Rujan_Listopad_Studeni_Prosinac'.split('_'),
formats: {
LT: 'H:mm',
LTS: 'H:mm:ss',
L: 'DD.MM.YYYY',
LL: 'D. MMMM YYYY',
LLL: 'D. MMMM YYYY H:mm',
LLLL: 'dddd, D. MMMM YYYY H:mm'
},
relativeTime: {
future: 'za %s',
past: 'prije %s',
Expand Down
8 changes: 8 additions & 0 deletions src/locale/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const locale = {
name: 'id',
weekdays: 'Minggu_Senin_Selasa_Rabu_Kamis_Jumat_Sabtu'.split('_'),
months: 'Januari_Februari_Maret_April_Mei_Juni_Juli_Agustus_September_Oktober_November_Desember'.split('_'),
formats: {
LT: 'HH.mm',
LTS: 'HH.mm.ss',
L: 'DD/MM/YYYY',
LL: 'D MMMM YYYY',
LLL: 'D MMMM YYYY [pukul] HH.mm',
LLLL: 'dddd, D MMMM YYYY [pukul] HH.mm'
},
relativeTime: {
future: 'dalam %s',
past: '%s yang lalu',
Expand Down
16 changes: 13 additions & 3 deletions src/locale/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ 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',
L: 'DD/MM/YYYY',
LL: 'D MMMM YYYY',
LLL: 'D MMMM YYYY HH:mm',
LLLL: 'dddd D MMMM YYYY HH:mm'
},
relativeTime: {
future: 'tra %s',
past: 'da %s',
Expand Down
8 changes: 8 additions & 0 deletions src/locale/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const locale = {
weekdaysMin: '日_月_火_水_木_金_土'.split('_'),
months: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
ordinal: n => `${n}日`,
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'YYYY/MM/DD',
LL: 'YYYY年M月D日',
LLL: 'YYYY年M月D日 HH:mm',
LLLL: 'YYYY年M月D日 dddd HH:mm'
},
relativeTime: {
future: '%s後',
past: '%s前',
Expand Down
Loading

0 comments on commit b56c77d

Please sign in to comment.