Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: iamkun/dayjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.8.15
Choose a base ref
...
head repository: iamkun/dayjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.8.16
Choose a head ref
  • 15 commits
  • 43 files changed
  • 9 contributors

Commits on Jul 10, 2019

  1. fix: Update Danish (da) locale (#626)

    DerJacques authored and iamkun committed Jul 10, 2019
    Copy the full SHA
    ac2ec77 View commit details

Commits on Jul 12, 2019

  1. Create FUNDING.yml

    iamkun authored Jul 12, 2019
    Copy the full SHA
    3032a62 View commit details

Commits on Jul 13, 2019

  1. fix: update pt-br locale (#628)

    * Add weekdays short for portuguese (br) locale.
    
    * Removing dots from 'weekdaysShort' and adding 'weekdaysMin'.
    
    * Add 'weekStart' and 'monthsShort' to pt-br language.
    
    * Removing 'monthsShort' from pt-br locale.
    
    * Removing 'weekdaysShort' from pt-br locale.
    reebr authored and iamkun committed Jul 13, 2019
    Copy the full SHA
    ccf596d View commit details
  2. docs: Improving pt-br documentation. (#629)

    reebr authored and iamkun committed Jul 13, 2019
    Copy the full SHA
    0accdf1 View commit details

Commits on Jul 15, 2019

  1. fix: update Occitan locale Catalan locale (#630)

    * Update
    
    Hormanisation with other time/date framworks
    
    * Correction and harmonisation
    
    Harmonisation + correction for the same reason as #615
    
    * Update ca.js
    
    * Update oc-lnc.js
    Quenty31 authored and iamkun committed Jul 15, 2019
    Copy the full SHA
    fef135e View commit details

Commits on Jul 16, 2019

  1. fix: Return null in toJSON if not valid (#633)

    * fix: toJSON returns null if not valid
    
    * fix: typo in locale
    
    * fix: adding test on toJSON
    guillaumebriday authored and iamkun committed Jul 16, 2019
    Copy the full SHA
    19affc8 View commit details

Commits on Jul 29, 2019

  1. Copy the full SHA
    b457146 View commit details
  2. fix: Update weekdaysShort to some locale files (#643)

    This PR adds weekdaysShort to those locale files that they do not have this variable defined.
    vigosan authored and iamkun committed Jul 29, 2019
    Copy the full SHA
    cc1f15f View commit details

Commits on Jul 31, 2019

  1. Copy the full SHA
    a385d5c View commit details

Commits on Aug 6, 2019

  1. 2
    Copy the full SHA
    95e70b4 View commit details

Commits on Aug 15, 2019

  1. chore: add .editorconfig (#660)

    g1eny0ung authored and iamkun committed Aug 15, 2019
    Copy the full SHA
    572e5a4 View commit details

Commits on Aug 19, 2019

  1. Copy the full SHA
    0e45b0a View commit details

Commits on Aug 27, 2019

  1. Copy the full SHA
    4c862f6 View commit details
  2. Merge pull request #667 from iamkun/dev

    D2M
    iamkun authored Aug 27, 2019
    Copy the full SHA
    d622377 View commit details
  3. chore(release): 1.8.16 [skip ci]

    ## [1.8.16](v1.8.15...v1.8.16) (2019-08-27)
    
    ### Bug Fixes
    
    * Fix relativeTime Plugin .FromNow() result error in UTC mode ([a385d5c](a385d5c))
    * Handle locale in WeekOfYear plugin ([#658](#658)) ([0e45b0a](0e45b0a))
    * LocaleData plugin returns all months and weekdays data when pas no argument ([#645](#645)) ([95e70b4](95e70b4))
    * Return null in toJSON if not valid ([#633](#633)) ([19affc8](19affc8))
    * Update Danish (da) locale ([#626](#626)) ([ac2ec77](ac2ec77))
    * Update Korean locale meridiem ([#642](#642)) ([b457146](b457146))
    * update Occitan locale Catalan locale ([#630](#630)) ([fef135e](fef135e))
    * update pt-br locale ([#628](#628)) ([ccf596d](ccf596d))
    * Update weekdaysShort to some locale files ([#643](#643)) ([cc1f15f](cc1f15f))
    semantic-release-bot committed Aug 27, 2019
    Copy the full SHA
    7241da9 View commit details
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: dayjs
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [1.8.16](https://github.com/iamkun/dayjs/compare/v1.8.15...v1.8.16) (2019-08-27)


### Bug Fixes

* Fix relativeTime Plugin .FromNow() result error in UTC mode ([a385d5c](https://github.com/iamkun/dayjs/commit/a385d5c))
* Handle locale in WeekOfYear plugin ([#658](https://github.com/iamkun/dayjs/issues/658)) ([0e45b0a](https://github.com/iamkun/dayjs/commit/0e45b0a))
* LocaleData plugin returns all months and weekdays data when pas no argument ([#645](https://github.com/iamkun/dayjs/issues/645)) ([95e70b4](https://github.com/iamkun/dayjs/commit/95e70b4))
* Return null in toJSON if not valid ([#633](https://github.com/iamkun/dayjs/issues/633)) ([19affc8](https://github.com/iamkun/dayjs/commit/19affc8))
* Update Danish (da) locale ([#626](https://github.com/iamkun/dayjs/issues/626)) ([ac2ec77](https://github.com/iamkun/dayjs/commit/ac2ec77))
* Update Korean locale meridiem ([#642](https://github.com/iamkun/dayjs/issues/642)) ([b457146](https://github.com/iamkun/dayjs/commit/b457146))
* update Occitan locale Catalan locale ([#630](https://github.com/iamkun/dayjs/issues/630)) ([fef135e](https://github.com/iamkun/dayjs/commit/fef135e))
* update pt-br locale ([#628](https://github.com/iamkun/dayjs/issues/628)) ([ccf596d](https://github.com/iamkun/dayjs/commit/ccf596d))
* Update weekdaysShort to some locale files ([#643](https://github.com/iamkun/dayjs/issues/643)) ([cc1f15f](https://github.com/iamkun/dayjs/commit/cc1f15f))

## [1.8.15](https://github.com/iamkun/dayjs/compare/v1.8.14...v1.8.15) (2019-07-08)


28 changes: 14 additions & 14 deletions docs/pt-br/I18n.md
Original file line number Diff line number Diff line change
@@ -21,11 +21,11 @@ Você será bem-vindo para adicionar um _locale_ abrindo um pull request. :+1:
```js
import 'dayjs/locale/es'
import de from 'dayjs/locale/de'
dayjs.locale('es') // usar o locale es globalmente
dayjs.locale('de-german', de) // usar o locale de e alterar a string padrão
dayjs.locale('es') // usar a localidade 'es' globalmente
dayjs.locale('de-german', de) // usar a localidade 'de' e alterar a string padrão
const customizedLocaleObject = { ... } // mais detalhes podem ser vistos na sessão de customização abaixo
dayjs.locale(customizedLocaleObject) // usar locale customizado
dayjs.locale('en') // switch back to default English locale globally
dayjs.locale(customizedLocaleObject) // usar uma localidade customizada
dayjs.locale('en') // alterna de volta a localidade globalmente para padrão em inglês
```

- Mudar o _locale_ global não afeta instâncias já existentes.
@@ -40,23 +40,23 @@ Exatamente o mesmo que `dayjs#locale`, porém utilizando somente o _locale_ em u
import 'dayjs/locale/es'
dayjs()
.locale('es')
.format() // usar locale localmente
dayjs('2018-4-28', { locale: 'es' }) // também pode ser feito no constructor
.format() // usar a localidade localmente
dayjs('2018-4-28', { locale: 'es' }) // também pode ser feito no construtor
```

## Instalação

- Via NPM:

```javascript
import 'dayjs/locale/es' // carregar locale es
import 'dayjs/locale/es' // carrega a localidade 'es'
// require('dayjs/locale/es') // se estiver usando CommonJS
// import locale_es from 'dayjs/locale/es' -> carregar e obter objeto locale locale_es
// import locale_es from 'dayjs/locale/es' -> carrega e obtém o objeto de localidade locale_es

dayjs.locale('es') // usar locale globalmente
dayjs.locale('es') // usa a localidade globalmente
dayjs()
.locale('es')
.format() // usar locale em uma instância específica
.format() // usa a localidade em uma instância específica
```

- Via CDN:
@@ -70,7 +70,7 @@ dayjs()
dayjs()
.locale('pt-br')
.format()
// obter objeto locale
// obtém o objeto de localidade
var customLocale = window.dayjs_locale_zh_cn // pt-br -> pt-br
</script>
```
@@ -89,7 +89,7 @@ const objetoLocale = {
weekdays: 'Domingo_Lunes ...'.split('_'), // dias da semana: Array
weekdaysShort: 'Sun_M'.split('_'), // OPCIONAL, dias da semana com nome curto: Array, utiliza as três primeiras letras se nenhuma for especificada
weekdaysMin: 'Su_Mo'.split('_'), // OPCIONAL, dias da semana com nome mínimo: Array, utiliza as duas primeiras letras se nenhuma for especificada
weekStart: 1, // OPTIONAL, set the start of a week. If the value is 1, Monday will be the start of week instead of Sunday
weekStart: 1, // OPCIONAL, define o início da semana. Se o valor for 1, Segunda-feira será o início da semana ao invés de Domingo
months: 'Enero_Febrero ... '.split('_'), // meses: Array
monthsShort: 'Jan_F'.split('_'), // OPCIONAL, meses com nome curto: Array, utiliza as três primeiras letras se nenhuma for especificada
ordinal: n => `${n}º`, // ordinal: Function (number) => retorna number + saída
@@ -135,9 +135,9 @@ Modelo de um arquivo _locale_ do Day.js.
```javascript
import dayjs from 'dayjs'

const locale = { ... } // seu objeto de locale
const locale = { ... } // seu objeto de localidade

dayjs.locale(locale, null, true) // carregar locale para uso posterior
dayjs.locale(locale, null, true) // carrega a localidade para uso posterior

export default locale
```
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -374,7 +374,7 @@ class Dayjs {
}

toJSON() {
return this.toISOString()
return this.isValid() ? this.toISOString() : null
}

toISOString() {
8 changes: 6 additions & 2 deletions src/locale/ar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import dayjs from 'dayjs'

const months = 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'.split('_')

const locale = {
name: 'ar',
weekdays: 'الأحد_الإثنين_الثلاثاء_الأربعاء_الخميس_الجمعة_السبت'.split('_'),
months: 'يناير_فبراير_مارس_أبريل_مايو_يونيو_يوليو_أغسطس_سبتمبر_أكتوبر_نوفمبر_ديسمبر'.split('_'),
weekdaysShort: 'أحد_إثنين_ثلاثاء_أربعاء_خميس_جمعة_سبت'.split('_'),
weekdaysMin: 'ح_ن_ث_ر_خ_ج_س'.split('_'),
months,
monthsShort: months,
weekStart: 6,
relativeTime: {
future: 'بعد %s',
@@ -34,4 +39,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/bg.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'bg',
weekdays: 'Неделя_Понеделник_Вторник_Сряда_Четвъртък_Петък_Събота'.split('_'),
weekdaysShort: 'нед_пон_вто_сря_чет_пет_съб'.split('_'),
weekdaysMin: 'нд_пн_вт_ср_чт_пт_сб'.split('_'),
months: 'Януари_Февруари_Март_Април_Май_Юни_Юли_Август_Септември_Октомври_Ноември_Декември'.split('_'),
monthsShort: 'Янр_Фев_Мар_Апр_Май_Юни_Юли_Авг_Сеп_Окт_Ное_Дек'.split('_'),
weekStart: 1,
ordinal: n => `${n}.`,
formats: {
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

6 changes: 4 additions & 2 deletions src/locale/ca.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'ca',
weekdays: 'Diumenge_Dilluns_Dimarts_Dimecres_Dijous_Divendres_Dissabte'.split('_'),
weekdaysShort: 'Dg._Dl._Dt._Dc._Dj._Dv._Ds.'.split('_'),
weekdaysMin: 'Dg_Dl_Dt_Dc_Dj_Dv_Ds'.split('_'),
months: 'Gener_Febrer_Març_Abril_Maig_Juny_Juliol_Agost_Setembre_Octubre_Novembre_Desembre'.split('_'),
monthsShort: 'Gen._Febr._Març_Abr._Maig_Juny_Jul._Ag._Set._Oct._Nov._Des.'.split('_'),
weekStart: 1,
formats: {
LT: 'H:mm',
@@ -17,7 +20,7 @@ const locale = {
llll: 'ddd D MMM YYYY, H:mm'
},
relativeTime: {
future: 'en %s',
future: 'd\'aquí %s',
past: 'fa %s',
s: 'uns segons',
m: 'un minut',
@@ -37,4 +40,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/cs.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'cs',
weekdays: 'neděle_pondělí_úterý_středa_čtvrtek_pátek_sobota'.split('_'),
weekdaysShort: 'ne_po_út_st_čt_pá_so'.split('_'),
weekdaysMin: 'ne_po_út_st_čt_pá_so'.split('_'),
months: 'leden_únor_březen_duben_květen_červen_červenec_srpen_září_říjen_listopad_prosinec'.split('_'),
monthsShort: 'led_úno_bře_dub_kvě_čvn_čvc_srp_zář_říj_lis_pro'.split('_'),
weekStart: 1,
ordinal: n => `${n}.`,
formats: {
@@ -35,4 +38,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

3 changes: 3 additions & 0 deletions src/locale/da.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'da',
weekdays: 'søndag_mandag_tirsdag_onsdag_torsdag_fredag_lørdag'.split('_'),
weekdaysShort: 'søn._man._tirs._ons._tors._fre._lør.'.split('_'),
weekdaysMin: 'sø._ma._ti._on._to._fr._lø.'.split('_'),
months: 'januar_februar_marts_april_maj_juni_juli_august_september_oktober_november_december'.split('_'),
monthsShort: 'jan._feb._mar._apr._maj_juni_juli_aug._sept._okt._nov._dec.'.split('_'),
weekStart: 1,
ordinal: n => `${n}.`,
formats: {
3 changes: 2 additions & 1 deletion src/locale/de-at.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import dayjs from 'dayjs'
const locale = {
name: 'de-at',
weekdays: 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'),
weekdaysShort: 'So._Mo._Di._Mi._Do._Fr._Sa.'.split('_'),
weekdaysMin: 'So_Mo_Di_Mi_Do_Fr_Sa'.split('_'),
months: 'Jänner_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'),
monthsShort: 'Jän._Feb._März_Apr._Mai_Juni_Juli_Aug._Sep._Okt._Nov._Dez.'.split('_'),
ordinal: n => `${n}.`,
@@ -35,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

3 changes: 2 additions & 1 deletion src/locale/de.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import dayjs from 'dayjs'
const locale = {
name: 'de',
weekdays: 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'),
weekdaysShort: 'So._Mo._Di._Mi._Do._Fr._Sa.'.split('_'),
weekdaysMin: 'So_Mo_Di_Mi_Do_Fr_Sa'.split('_'),
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}.`,
@@ -35,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

3 changes: 2 additions & 1 deletion src/locale/el.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import dayjs from 'dayjs'
const locale = {
name: 'el',
weekdays: 'Κυριακή_Δευτέρα_Τρίτη_Τετάρτη_Πέμπτη_Παρασκευή_Σάββατο'.split('_'),
weekdaysShort: 'Κυρ_Δευ_Τρι_Τετ_Πεμ_Παρ_Σαβ'.split('_'),
weekdaysMin: 'Κυ_Δε_Τρ_Τε_Πε_Πα_Σα'.split('_'),
months: 'Ιανουάριος_Φεβρουάριος_Μάρτιος_Απρίλιος_Μάιος_Ιούνιος_Ιούλιος_Αύγουστος_Σεπτέμβριος_Οκτώβριος_Νοέμβριος_Δεκέμβριος'.split('_'),
monthsShort: 'Ιαν_Φεβ_Μαρ_Απρ_Μαι_Ιουν_Ιουλ_Αυγ_Σεπτ_Οκτ_Νοε_Δεκ'.split('_'),
ordinal: n => n,
@@ -35,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

1 change: 1 addition & 0 deletions src/locale/en.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// We don't need weekdaysShort, weekdaysMin, monthsShort in en.js locale
export default {
name: 'en',
weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
4 changes: 3 additions & 1 deletion src/locale/fa.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'fa',
weekdays: 'یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه'.split('_'),
weekdaysShort: 'یک\u200cشنبه_دوشنبه_سه\u200cشنبه_چهارشنبه_پنج\u200cشنبه_جمعه_شنبه'.split('_'),
weekdaysMin: 'ی_د_س_چ_پ_ج_ش'.split('_'),
months: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
monthsShort: 'ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر'.split('_'),
ordinal: n => n,
formats: {
LT: 'HH:mm',
@@ -33,4 +36,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

3 changes: 2 additions & 1 deletion src/locale/fr.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import dayjs from 'dayjs'
const locale = {
name: 'fr',
weekdays: 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
weekdaysShort: 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
weekdaysMin: 'di_lu_ma_me_je_ve_sa'.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('_'),
weekStart: 1,
@@ -38,4 +40,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

2 changes: 1 addition & 1 deletion src/locale/fy.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const locale = {
name: 'fy',
weekdays: 'snein_moandei_tiisdei_woansdei_tongersdei_freed_sneon'.split('_'),
months: 'jannewaris_febrewaris_maart_april_maaie_juny_july_augustus_septimber_oktober_novimber_desimber'.split('_'),
monthsShort: 'jan._feb._mrt._apr._mai_jun._jul._aug._sep._okt._nov._des.'.split('_'),
weekStart: 1,
weekdaysShort: 'si._mo._ti._wo._to._fr._so.'.split('_'),
weekdaysMin: 'Si_Mo_Ti_Wo_To_Fr_So'.split('_'),
@@ -36,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

2 changes: 1 addition & 1 deletion src/locale/he.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import dayjs from 'dayjs'
const locale = {
name: 'he',
weekdays: 'ראשון_שני_שלישי_רביעי_חמישי_שישי_שבת'.split('_'),
weekdaysShort: 'א׳_ב׳_ג׳_ד׳_ה׳_ו׳_ש׳'.split('_'),
weekdaysMin: 'א׳_ב׳_ג׳_ד׳_ה׳_ו_ש׳'.split('_'),
months: 'ינואר_פברואר_מרץ_אפריל_מאי_יוני_יולי_אוגוסט_ספטמבר_אוקטובר_נובמבר_דצמבר'.split('_'),
monthsShort: 'ינו_פבר_מרץ_אפר_מאי_יונ_יול_אוג_ספט_אוק_נוב_דצמ'.split('_'),
@@ -51,4 +52,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/hr.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'hr',
weekdays: 'Nedjelja_Ponedjeljak_Utorak_Srijeda_Četvrtak_Petak_Subota'.split('_'),
weekdaysShort: 'Ned._Pon._Uto._Sri._Čet._Pet._Sub.'.split('_'),
weekdaysMin: 'Ne_Po_Ut_Sr_Če_Pe_Su'.split('_'),
months: 'Siječanj_Veljača_Ožujak_Travanj_Svibanj_Lipanj_Srpanj_Kolovoz_Rujan_Listopad_Studeni_Prosinac'.split('_'),
monthsShort: 'Sij._Velj._Ožu._Tra._Svi._Lip._Srp._Kol._Ruj._Lis._Stu._Pro.'.split('_'),
weekStart: 1,
formats: {
LT: 'H:mm',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

2 changes: 1 addition & 1 deletion src/locale/ja.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const locale = {
weekdaysShort: '日_月_火_水_木_金_土'.split('_'),
weekdaysMin: '日_月_火_水_木_金_土'.split('_'),
months: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
ordinal: n => `${n}日`,
formats: {
LT: 'HH:mm',
@@ -40,4 +41,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/ka.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'ka',
weekdays: 'კვირა_ორშაბათი_სამშაბათი_გარემო_ხუთშაბათი_პარასკევი_შაბათს'.split('_'),
weekdaysShort: 'კვი_ორშ_სამ_ოთხ_ხუთ_პარ_შაბ'.split('_'),
weekdaysMin: 'კვ_ორ_სა_ოთ_ხუ_პა_შა'.split('_'),
months: 'იანვარი_თებერვალი_მარტი_აპრილი_მაისი_ივნისი_ივლისი_აგვისტო_სექტემბერი_ოქტომბერი_ნოემბერი_დეკემბერი'.split('_'),
monthsShort: 'იან_თებ_მარ_აპრ_მაი_ივნ_ივლ_აგვ_სექ_ოქტ_ნოე_დეკ'.split('_'),
weekStart: 1,
formats: {
LT: 'h:mm A',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/ko.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@ const locale = {
name: 'ko',
weekdays: '일요일_월요일_화요일_수요일_목요일_금요일_토요일'.split('_'),
weekdaysShort: '일_월_화_수_목_금_토'.split('_'),
weekdaysMin: '일_월_화_수_목_금_토'.split('_'),
months: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
monthsShort: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
ordinal: n => n,
formats: {
LT: 'A h:mm',
@@ -18,6 +20,7 @@ const locale = {
lll: 'YYYY년 MMMM D일 A h:mm',
llll: 'YYYY년 MMMM D일 dddd A h:mm'
},
meridiem: hour => (hour < 12 ? '오전' : '오후'),
relativeTime: {
future: '%s 후',
past: '%s 전',
@@ -38,4 +41,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/lt.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'lt',
weekdays: 'sekmadienis_pirmadienis_antradienis_trečiadienis_ketvirtadienis_penktadienis_šeštadienis'.split('_'),
weekdaysShort: 'sek_pir_ant_tre_ket_pen_šeš'.split('_'),
weekdaysMin: 's_p_a_t_k_pn_š'.split('_'),
months: 'sausis_vasaris_kovas_balandis_gegužė_birželis_liepa_rugpjūtis_rugsėjis_spalis_lapkritis_gruodis'.split('_'),
monthsShort: 'sau_vas_kov_bal_geg_bir_lie_rgp_rgs_spa_lap_grd'.split('_'),
ordinal: n => `${n}.`,
weekStart: 1,
relativeTime: {
@@ -50,4 +53,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/ms.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'ms',
weekdays: 'Ahad_Isnin_Selasa_Rabu_Khamis_Jumaat_Sabtu'.split('_'),
weekdaysShort: 'Ahd_Isn_Sel_Rab_Kha_Jum_Sab'.split('_'),
weekdaysMin: 'Ah_Is_Sl_Rb_Km_Jm_Sb'.split('_'),
months: 'Januari_Februari_Mac_April_Mei_Jun_Julai_Ogos_September_Oktober_November_Disember'.split('_'),
monthsShort: 'Jan_Feb_Mac_Apr_Mei_Jun_Jul_Ogs_Sep_Okt_Nov_Dis'.split('_'),
weekStart: 1,
formats: {
LT: 'HH.mm',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/ne.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'ne',
weekdays: 'आइतबार_सोमबार_मङ्गलबार_बुधबार_बिहिबार_शुक्रबार_शनिबार'.split('_'),
weekdaysShort: 'आइत._सोम._मङ्गल._बुध._बिहि._शुक्र._शनि.'.split('_'),
weekdaysMin: 'आ._सो._मं._बु._बि._शु._श.'.split('_'),
months: 'जनवरी_फेब्रुवरी_मार्च_अप्रिल_मे_जुन_जुलाई_अगष्ट_सेप्टेम्बर_अक्टोबर_नोभेम्बर_डिसेम्बर'.split('_'),
monthsShort: 'जन._फेब्रु._मार्च_अप्रि._मई_जुन_जुलाई._अग._सेप्ट._अक्टो._नोभे._डिसे.'.split('_'),
relativeTime: {
future: '%s पछि',
past: '%s अघि',
@@ -33,4 +36,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

2 changes: 1 addition & 1 deletion src/locale/nl-be.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const locale = {
name: 'nl-be',
weekdays: 'zondag_maandag_dinsdag_woensdag_donderdag_vrijdag_zaterdag'.split('_'),
months: 'januari_februari_maart_april_mei_juni_juli_augustus_september_oktober_november_december'.split('_'),
monthsShort: 'jan._feb._mrt._apr._mei_jun._jul._aug._sep._okt._nov._dec.'.split('_'),
weekStart: 1,
weekdaysShort: 'zo._ma._di._wo._do._vr._za.'.split('_'),
weekdaysMin: 'zo_ma_di_wo_do_vr_za'.split('_'),
@@ -36,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

3 changes: 2 additions & 1 deletion src/locale/nl.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import dayjs from 'dayjs'
const locale = {
name: 'nl',
weekdays: 'zondag_maandag_dinsdag_woensdag_donderdag_vrijdag_zaterdag'.split('_'),
weekdaysShort: 'zo._ma._di._wo._do._vr._za.'.split('_'),
weekdaysMin: 'zo_ma_di_wo_do_vr_za'.split('_'),
months: 'januari_februari_maart_april_mei_juni_juli_augustus_september_oktober_november_december'.split('_'),
monthsShort: 'jan_feb_mrt_apr_mei_jun_jul_aug_sep_okt_nov_dec'.split('_'),
ordinal: n => `${n}.`,
@@ -35,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

9 changes: 5 additions & 4 deletions src/locale/oc-lnc.js
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@ import dayjs from 'dayjs'

const locale = {
name: 'oc-lnc',
weekdays: 'Dimenge_Diluns_Dimars_Dimècres_Dijòus_Divendres_Dissabte'.split('_'),
weekdays: 'dimenge_diluns_dimars_dimècres_dijòus_divendres_dissabte'.split('_'),
weekdaysShort: 'Dg_Dl_Dm_Dc_Dj_Dv_Ds'.split('_'),
months: 'Genièr_Febrièr_Març_Abrial_Mai_Junh_Julhet_Agost_Setembre_Octòbre_Novembre_Decembre'.split('_'),
monthsShort: 'Gen_Feb_Març_Abr_Mai_Junh_Julh_Ago_Set_Oct_Nov_Dec'.split('_'),
weekdaysMin: 'dg_dl_dm_dc_dj_dv_ds'.split('_'),
months: 'genièr_febrièr_març_abrial_mai_junh_julhet_agost_setembre_octòbre_novembre_decembre'.split('_'),
monthsShort: 'gen_feb_març_abr_mai_junh_julh_ago_set_oct_nov_dec'.split('_'),
weekStart: 1,
formats: {
LT: 'H:mm',
@@ -16,7 +17,7 @@ const locale = {
LLLL: 'dddd D MMMM [de] YYYY [a] H:mm'
},
relativeTime: {
future: 'en %s',
future: 'd\'aquí %s',
past: 'fa %s',
s: 'unas segondas',
m: 'una minuta',
2 changes: 1 addition & 1 deletion src/locale/pl.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const locale = {
weekdaysShort: 'Ndz_Pon_Wt_Śr_Czw_Pt_Sob'.split('_'),
weekdaysMin: 'Nd_Pn_Wt_Śr_Cz_Pt_So'.split('_'),
months: 'Styczeń_Luty_Marzec_Kwiecień_Maj_Czerwiec_Lipiec_Sierpień_Wrzesień_Październik_Listopad_Grudzień'.split('_'),
monthsShort: 'sty_lut_mar_kwi_maj_cze_lip_sie_wrz_paź_lis_gru'.split('_'),
ordinal: n => `${n}.`,
weekStart: 1,
relativeTime: {
@@ -36,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

5 changes: 4 additions & 1 deletion src/locale/pt-br.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,11 @@ import dayjs from 'dayjs'
const locale = {
name: 'pt-br',
weekdays: 'Domingo_Segunda-feira_Terça-feira_Quarta-feira_Quinta-feira_Sexta-feira_Sábado'.split('_'),
weekdaysShort: 'Dom_Seg_Ter_Qua_Qui_Sex_Sáb'.split('_'),
weekdaysMin: 'Do_2ª_3ª_4ª_5ª_6ª_Sá'.split('_'),
weekStart: 1,
months: 'Janeiro_Fevereiro_Março_Abril_Maio_Junho_Julho_Agosto_Setembro_Outubro_Novembro_Dezembro'.split('_'),
monthsShort: 'Jan_Fev_Mar_Abr_Mai_Jun_Jul_Ago_Set_Out_Nov_Dez'.split('_'),
ordinal: n => `${n}º`,
formats: {
LT: 'HH:mm',
@@ -33,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

2 changes: 1 addition & 1 deletion src/locale/pt.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ const locale = {
name: 'pt',
weekdays: 'Domingo_Segunda-feira_Terça-feira_Quarta-feira_Quinta-feira_Sexta-feira_Sábado'.split('_'),
weekdaysShort: 'Dom_Seg_Ter_Qua_Qui_Sex_Sab'.split('_'),
weekdaysMin: 'Do_2ª_3ª_4ª_5ª_6ª_Sa'.split('_'),
months: 'Janeiro_Fevereiro_Março_Abril_Maio_Junho_Julho_Agosto_Setembro_Outubro_Novembro_Dezembro'.split('_'),
monthsShort: 'Jan_Fev_Mar_Abr_Mai_Jun_Jul_Ago_Set_Out_Nov_Dez'.split('_'),
ordinal: n => `${n}º`,
@@ -36,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/ro.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'ro',
weekdays: 'Duminică_Luni_Marți_Miercuri_Joi_Vineri_Sâmbătă'.split('_'),
weekdaysShort: 'Dum_Lun_Mar_Mie_Joi_Vin_Sâm'.split('_'),
weekdaysMin: 'Du_Lu_Ma_Mi_Jo_Vi_Sâ'.split('_'),
months: 'Ianuarie_Februarie_Martie_Aprilie_Mai_Iunie_Iulie_August_Septembrie_Octombrie_Noiembrie_Decembrie'.split('_'),
monthsShort: 'Ian._Febr._Mart._Apr._Mai_Iun._Iul._Aug._Sept._Oct._Nov._Dec.'.split('_'),
weekStart: 1,
formats: {
LT: 'H:mm',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/sk.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'sk',
weekdays: 'Nedeľa_Pondelok_Utorok_Streda_Štvrtok_Piatok_Sobota'.split('_'),
weekdaysShort: 'Ne_Po_Ut_St_Št_Pi_So'.split('_'),
weekdaysMin: 'ne_po_ut_st_št_pi_so'.split('_'),
months: 'január_február_marec_apríl_máj_jún_júl_august_september_október_november_december'.split('_'),
monthsShort: 'jan_feb_mar_apr_máj_jún_júl_aug_sep_okt_nov_dec'.split('_'),
weekStart: 1,
relativeTime: {
future: 'o %s',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/sr-cyrl.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'sr-cyrl',
weekdays: 'Недеља_Понедељак_Уторак_Среда_Четвртак_Петак_Субота'.split('_'),
weekdaysShort: 'Нед._Пон._Уто._Сре._Чет._Пет._Суб.'.split('_'),
weekdaysMin: 'не_по_ут_ср_че_пе_су'.split('_'),
months: 'Јануар_Фебруар_Март_Април_Мај_Јун_Јул_Август_Септембар_Октобар_Новембар_Децембар'.split('_'),
monthsShort: 'Јан._Феб._Мар._Апр._Мај_Јун_Јул_Авг._Сеп._Окт._Нов._Дец.'.split('_'),
weekStart: 1,
relativeTime: {
future: 'за %s',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/sr.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'sr',
weekdays: 'Nedelja_Ponedeljak_Utorak_Sreda_Četvrtak_Petak_Subota'.split('_'),
weekdaysShort: 'Ned._Pon._Uto._Sre._Čet._Pet._Sub.'.split('_'),
weekdaysMin: 'ne_po_ut_sr_če_pe_su'.split('_'),
months: 'Januar_Februar_Mart_April_Maj_Jun_Jul_Avgust_Septembar_Oktobar_Novembar_Decembar'.split('_'),
monthsShort: 'Jan._Feb._Mar._Apr._Maj_Jun_Jul_Avg._Sep._Okt._Nov._Dec.'.split('_'),
weekStart: 1,
relativeTime: {
future: 'za %s',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

4 changes: 3 additions & 1 deletion src/locale/tr.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,10 @@ import dayjs from 'dayjs'
const locale = {
name: 'tr',
weekdays: 'Pazar_Pazartesi_Salı_Çarşamba_Perşembe_Cuma_Cumartesi'.split('_'),
weekdaysShort: 'Paz_Pts_Sal_Çar_Per_Cum_Cts'.split('_'),
weekdaysMin: 'Pz_Pt_Sa_Ça_Pe_Cu_Ct'.split('_'),
months: 'Ocak_Şubat_Mart_Nisan_Mayıs_Haziran_Temmuz_Ağustos_Eylül_Ekim_Kasım_Aralık'.split('_'),
monthsShort: 'Oca_Şub_Mar_Nis_May_Haz_Tem_Ağu_Eyl_Eki_Kas_Ara'.split('_'),
weekStart: 1,
formats: {
LT: 'HH:mm',
@@ -34,4 +37,3 @@ const locale = {
dayjs.locale(locale, null, true)

export default locale

20 changes: 15 additions & 5 deletions src/plugin/localeData/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
export default (o, c, dayjs) => { // locale needed later
const proto = c.prototype
const getShort = (ins, target, full, num) => {
const locale = ins.$locale()
if (!locale[target]) {
return locale[full].map(f => f.substr(0, num))
}
return locale[target]
}
const localeData = function () {
return {
months: instance => instance.format('MMMM'),
monthsShort: instance => instance.format('MMM'),
months: instance =>
(instance ? instance.format('MMMM') : getShort(this, 'months')),
monthsShort: instance =>
(instance ? instance.format('MMM') : getShort(this, 'monthsShort', 'months', 3)),
firstDayOfWeek: () => this.$locale().weekStart || 0,
weekdaysMin: instance => instance.format('dd'),
weekdaysShort: instance => instance.format('ddd')
weekdaysMin: instance =>
(instance ? instance.format('dd') : getShort(this, 'weekdaysMin', 'weekdays', 2)),
weekdaysShort: instance =>
(instance ? instance.format('ddd') : getShort(this, 'weekdaysShort', 'weekdays', 3))
}
}
proto.localeData = function () {
@@ -20,4 +31,3 @@ export default (o, c, dayjs) => { // locale needed later
}
}
}

7 changes: 5 additions & 2 deletions src/plugin/relativeTime/index.js
Original file line number Diff line number Diff line change
@@ -59,10 +59,13 @@ export default (o, c, d) => {
proto.from = function (input, withoutSuffix) {
return fromTo(input, withoutSuffix, this)
}

const makeNow = thisDay => (thisDay.$u ? d.utc() : d())

proto.toNow = function (withoutSuffix) {
return this.to(d(), withoutSuffix)
return this.to(makeNow(this), withoutSuffix)
}
proto.fromNow = function (withoutSuffix) {
return this.from(d(), withoutSuffix)
return this.from(makeNow(this), withoutSuffix)
}
}
13 changes: 11 additions & 2 deletions src/plugin/weekOfYear/index.js
Original file line number Diff line number Diff line change
@@ -6,13 +6,22 @@ export default (o, c, d) => {
if (week !== null) {
return this.add((week - this.week()) * 7, 'day')
}

const weekStart = this.$locale().weekStart || 0

// d(this) clone is for badMutable plugin
const endOfYear = d(this).endOf(Y)
if (endOfYear.day() !== 6 && this.month() === 11 && (31 - this.date()) <= endOfYear.day()) {
if (
weekStart === 0 &&
endOfYear.day() !== 6 &&
this.month() === 11 &&
31 - this.date() <= endOfYear.day()
) {
return 1
}

const startOfYear = d(this).startOf(Y)
const compareDay = startOfYear.subtract(startOfYear.day(), D).subtract(1, MS)
const compareDay = startOfYear.subtract(startOfYear.day() - weekStart, D).subtract(1, MS)
const diffInWeek = this.diff(compareDay, W, true)
return Math.ceil(diffInWeek)
}
3 changes: 3 additions & 0 deletions test/display.test.js
Original file line number Diff line number Diff line change
@@ -248,6 +248,9 @@ it('As Javascript Date -> toDate', () => {

it('As JSON -> toJSON', () => {
expect(dayjs().toJSON()).toBe(moment().toJSON())
global.console.warn = jest.genMockFunction()// moment.js otherString will throw warn
expect(dayjs('otherString').toJSON()).toBe(moment('otherString').toJSON())
expect(dayjs('otherString').toJSON()).toBe(null)
})

it('As ISO 8601 String -> toISOString e.g. 2013-02-04T22:44:30.652Z', () => {
4 changes: 4 additions & 0 deletions test/plugin/localeData.test.js
Original file line number Diff line number Diff line change
@@ -21,9 +21,13 @@ it('instance localeData', () => {
const momentLocaleData = moment().localeData()
expect(dayjsLocaleData.firstDayOfWeek()).toBe(momentLocaleData.firstDayOfWeek())
expect(dayjsLocaleData.months(d)).toBe(momentLocaleData.months(m))
expect(dayjsLocaleData.months()).toEqual(momentLocaleData.months())
expect(dayjsLocaleData.monthsShort(d)).toBe(momentLocaleData.monthsShort(m))
expect(dayjsLocaleData.monthsShort()).toEqual(momentLocaleData.monthsShort())
expect(dayjsLocaleData.weekdaysMin(d)).toBe(momentLocaleData.weekdaysMin(m))
expect(dayjsLocaleData.weekdaysMin()).toEqual(momentLocaleData.weekdaysMin())
expect(dayjsLocaleData.weekdaysShort(d)).toBe(momentLocaleData.weekdaysShort(m))
expect(dayjsLocaleData.weekdaysShort()).toEqual(momentLocaleData.weekdaysShort())
})

it('global localeData', () => {
25 changes: 24 additions & 1 deletion test/plugin/relativeTime.test.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import MockDate from 'mockdate'
import moment from 'moment'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import utc from '../../src/plugin/utc'

dayjs.extend(relativeTime)

@@ -70,7 +71,6 @@ it('Time from now', () => {
expect(dayjs().fromNow(true)).toBe(moment().fromNow(true))
})


it('Time to now', () => {
expect(dayjs().toNow()).toBe(moment().toNow())
expect(dayjs().toNow(true)).toBe(moment().toNow(true))
@@ -82,3 +82,26 @@ it('Time to X', () => {
// past date
expect(dayjs().to(dayjs().subtract(3, 'year'))).toBe(moment().to(moment().subtract(3, 'year')))
})

// https://github.com/iamkun/dayjs/issues/646
it('Time from now with UTC', () => {
dayjs.extend(utc)

expect(dayjs.utc().fromNow()).toBe(moment.utc().fromNow())

const currentTime = new Date()
const currentTimestamp = currentTime.getTime()
const currentTimestampAfter37hrs = currentTimestamp + (37 * 60 * 60 * 1000)

let dutc = dayjs.utc(currentTimestampAfter37hrs)
let mutc = moment.utc(currentTimestampAfter37hrs)

expect(dutc.fromNow()).toBe(mutc.fromNow())

// More precise
const currentTimestampAfter36hrs = currentTimestamp + (36.0001 * 60 * 60 * 1000)
dutc = dayjs.utc(currentTimestampAfter36hrs)
mutc = moment.utc(currentTimestampAfter36hrs)

expect(dutc.fromNow()).toBe(mutc.fromNow())
})
15 changes: 15 additions & 0 deletions test/plugin/weekOfYear.test.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import moment from 'moment'
import MockDate from 'mockdate'
import dayjs from '../../src'
import weekOfYear from '../../src/plugin/weekOfYear'
import '../../src/locale/en-gb'

dayjs.extend(weekOfYear)

@@ -14,6 +15,8 @@ afterEach(() => {
})

it('Week of year', () => {
dayjs.locale('en')

const day = '2018-12-31T10:59:09+08:00'
const week = 27
expect(dayjs(day).week()).toBe(moment(day).week())
@@ -24,3 +27,15 @@ it('Week of year', () => {
expect(dayjs().weeks(55).week()).toBe(moment().weeks(55).week())
expect(dayjs().weeks()).toBe(moment().weeks())
})

it('Week of year with locale', () => {
dayjs.locale('en-gb')
moment.locale('en-gb')

const day = '2019-07-28'
expect(dayjs(day).week()).toBe(moment(day).week())

// Edges
expect(dayjs('2018-12-30').week()).toBe(moment('2018-12-30').week())
expect(dayjs('2019-12-29').week()).toBe(moment('2019-12-29').week())
})