From 42e494b447cec61428d80fe258edf7ba7a7ec202 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 6 Jul 2021 07:41:21 +0000 Subject: [PATCH 01/14] chore(release): 1.10.6 [skip ci] ## [1.10.6](https://github.com/iamkun/dayjs/compare/v1.10.5...v1.10.6) (2021-07-06) ### Bug Fixes * add invalid date string override ([#1465](https://github.com/iamkun/dayjs/issues/1465)) ([#1470](https://github.com/iamkun/dayjs/issues/1470)) ([06f88f4](https://github.com/iamkun/dayjs/commit/06f88f425828b1ce96b737332d25145a95a4ee9d)) * add sv-fi Finland Swedish locale ([#1522](https://github.com/iamkun/dayjs/issues/1522)) ([8e32164](https://github.com/iamkun/dayjs/commit/8e32164855cff724642e24c37a631eb4c4d760c8)) * customParseFormat support parsing X x timestamp ([#1567](https://github.com/iamkun/dayjs/issues/1567)) ([eb087f5](https://github.com/iamkun/dayjs/commit/eb087f52861313b8dd8a5c1b77858665ec72859e)) * dayjs ConfigTypeMap add null & undefined ([#1560](https://github.com/iamkun/dayjs/issues/1560)) ([b5e40e6](https://github.com/iamkun/dayjs/commit/b5e40e6f16abeaea6a0facfa466d20aefaa8a444)) * Fix DayOfYear plugin when using BadMutable plugin ([#1511](https://github.com/iamkun/dayjs/issues/1511)) ([0b0c6a3](https://github.com/iamkun/dayjs/commit/0b0c6a31ec9c0aff991b0e8dd6eed116201274cc)) * Implement ordinal in Bulgarian translation (fixes [#1501](https://github.com/iamkun/dayjs/issues/1501)) ([#1502](https://github.com/iamkun/dayjs/issues/1502)) ([b728da5](https://github.com/iamkun/dayjs/commit/b728da5ed9ed08210004ed20ce5fcd52a92de7da)) * more strict delimiter in REGEX_PARSE ([#1555](https://github.com/iamkun/dayjs/issues/1555)) ([bfdab5c](https://github.com/iamkun/dayjs/commit/bfdab5c0d45a5736b68e8e1b1354fc021e05f607)) * parameter type ([#1549](https://github.com/iamkun/dayjs/issues/1549)) ([f369844](https://github.com/iamkun/dayjs/commit/f369844dd69d253c4c7cbf68150939db3db233be)) * update customParseFormat plugin to custom two-digit year parse function ([#1421](https://github.com/iamkun/dayjs/issues/1421)) ([bb5df55](https://github.com/iamkun/dayjs/commit/bb5df55cd3975dc7638b8f4e762afa470b6620f7)) * update names of weekdays and months in Bulgarian [bg] to lowercase ([#1438](https://github.com/iamkun/dayjs/issues/1438)) ([b246210](https://github.com/iamkun/dayjs/commit/b24621091fec9cf6704de21e4b323f6f0c4abbf1)) * update type file `.diff` ([#1505](https://github.com/iamkun/dayjs/issues/1505)) ([6508494](https://github.com/iamkun/dayjs/commit/6508494a4e62977b4397baaeef293d1bcf3c7235)) * update UTC plugin type file for strict parsing ([#1443](https://github.com/iamkun/dayjs/issues/1443)) ([b4f28df](https://github.com/iamkun/dayjs/commit/b4f28df219fe63202dffdbeeaec5677c4d2c9111)) --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05241588e..fbd5b5b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## [1.10.6](https://github.com/iamkun/dayjs/compare/v1.10.5...v1.10.6) (2021-07-06) + + +### Bug Fixes + +* add invalid date string override ([#1465](https://github.com/iamkun/dayjs/issues/1465)) ([#1470](https://github.com/iamkun/dayjs/issues/1470)) ([06f88f4](https://github.com/iamkun/dayjs/commit/06f88f425828b1ce96b737332d25145a95a4ee9d)) +* add sv-fi Finland Swedish locale ([#1522](https://github.com/iamkun/dayjs/issues/1522)) ([8e32164](https://github.com/iamkun/dayjs/commit/8e32164855cff724642e24c37a631eb4c4d760c8)) +* customParseFormat support parsing X x timestamp ([#1567](https://github.com/iamkun/dayjs/issues/1567)) ([eb087f5](https://github.com/iamkun/dayjs/commit/eb087f52861313b8dd8a5c1b77858665ec72859e)) +* dayjs ConfigTypeMap add null & undefined ([#1560](https://github.com/iamkun/dayjs/issues/1560)) ([b5e40e6](https://github.com/iamkun/dayjs/commit/b5e40e6f16abeaea6a0facfa466d20aefaa8a444)) +* Fix DayOfYear plugin when using BadMutable plugin ([#1511](https://github.com/iamkun/dayjs/issues/1511)) ([0b0c6a3](https://github.com/iamkun/dayjs/commit/0b0c6a31ec9c0aff991b0e8dd6eed116201274cc)) +* Implement ordinal in Bulgarian translation (fixes [#1501](https://github.com/iamkun/dayjs/issues/1501)) ([#1502](https://github.com/iamkun/dayjs/issues/1502)) ([b728da5](https://github.com/iamkun/dayjs/commit/b728da5ed9ed08210004ed20ce5fcd52a92de7da)) +* more strict delimiter in REGEX_PARSE ([#1555](https://github.com/iamkun/dayjs/issues/1555)) ([bfdab5c](https://github.com/iamkun/dayjs/commit/bfdab5c0d45a5736b68e8e1b1354fc021e05f607)) +* parameter type ([#1549](https://github.com/iamkun/dayjs/issues/1549)) ([f369844](https://github.com/iamkun/dayjs/commit/f369844dd69d253c4c7cbf68150939db3db233be)) +* update customParseFormat plugin to custom two-digit year parse function ([#1421](https://github.com/iamkun/dayjs/issues/1421)) ([bb5df55](https://github.com/iamkun/dayjs/commit/bb5df55cd3975dc7638b8f4e762afa470b6620f7)) +* update names of weekdays and months in Bulgarian [bg] to lowercase ([#1438](https://github.com/iamkun/dayjs/issues/1438)) ([b246210](https://github.com/iamkun/dayjs/commit/b24621091fec9cf6704de21e4b323f6f0c4abbf1)) +* update type file `.diff` ([#1505](https://github.com/iamkun/dayjs/issues/1505)) ([6508494](https://github.com/iamkun/dayjs/commit/6508494a4e62977b4397baaeef293d1bcf3c7235)) +* update UTC plugin type file for strict parsing ([#1443](https://github.com/iamkun/dayjs/issues/1443)) ([b4f28df](https://github.com/iamkun/dayjs/commit/b4f28df219fe63202dffdbeeaec5677c4d2c9111)) + ## [1.10.5](https://github.com/iamkun/dayjs/compare/v1.10.4...v1.10.5) (2021-05-26) From 9a4370812a47d8f5e8e32660f5f44be23b55e52e Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 10 Sep 2021 09:33:26 +0000 Subject: [PATCH 02/14] chore(release): 1.10.7 [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## [1.10.7](https://github.com/iamkun/dayjs/compare/v1.10.6...v1.10.7) (2021-09-10) ### Bug Fixes * Add Spanish (Mexico) [es-mx] locale ([#1614](https://github.com/iamkun/dayjs/issues/1614)) ([3393f2a](https://github.com/iamkun/dayjs/commit/3393f2ad55346d55902683a2e31c6f253d96c8c2)) * Add Arabic (Iraq) [ar-iq] locale ([#1627](https://github.com/iamkun/dayjs/issues/1627)) ([b5a1391](https://github.com/iamkun/dayjs/commit/b5a1391011b247d08863d291542db5937b23b427)) * add format object type to type file ([#1572](https://github.com/iamkun/dayjs/issues/1572)) ([5a79cc6](https://github.com/iamkun/dayjs/commit/5a79cc6408e825d9e123629eb44fc19c996d7751)) * duration plugin when parsing duration from ISO string, set missing components to 0 instead of NaN ([#1611](https://github.com/iamkun/dayjs/issues/1611)) ([252585b](https://github.com/iamkun/dayjs/commit/252585b4b2bd59508150e21bb994908a9d78f9b0)) * narrow type for `add` and `subtract` ([#1576](https://github.com/iamkun/dayjs/issues/1576)) ([1686962](https://github.com/iamkun/dayjs/commit/16869621b1a42563064dbf87f80c1ebfd74c1188)) * update customParseFormat plugin strict x X parsing ([#1571](https://github.com/iamkun/dayjs/issues/1571)) ([08adda5](https://github.com/iamkun/dayjs/commit/08adda54edbcca38601f57841921d0f87f84e49e)) * update Lithuanian [lt] locale spelling for single month ([#1609](https://github.com/iamkun/dayjs/issues/1609)) ([255dc54](https://github.com/iamkun/dayjs/commit/255dc54d9295de135a9037ce6ca13cae4bfd2cfb)) * Update Norwegian Bokmål [nb] local yearStart 4 ([#1608](https://github.com/iamkun/dayjs/issues/1608)) ([7a8467c](https://github.com/iamkun/dayjs/commit/7a8467c0b7d59821f7e19d4a6973bcda8e4c19b1)) * update plugin advancedFormat `isValid` validation ([#1566](https://github.com/iamkun/dayjs/issues/1566)) ([755fc8b](https://github.com/iamkun/dayjs/commit/755fc8bb1c532eb991459f180eee81367d12016c)) * update Sinhalese [si] locale month name ([#1475](https://github.com/iamkun/dayjs/issues/1475)) ([63de2a8](https://github.com/iamkun/dayjs/commit/63de2a8b7dcd7e68c132c85d88572d4c9d296907)) * update utcOffset plugin type file ([#1604](https://github.com/iamkun/dayjs/issues/1604)) ([f68e4b1](https://github.com/iamkun/dayjs/commit/f68e4b1a29fc33542f74cde10ec6d9fb045ca37e)) --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbd5b5b80..a2eba1691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +## [1.10.7](https://github.com/iamkun/dayjs/compare/v1.10.6...v1.10.7) (2021-09-10) + + +### Bug Fixes + +* Add Spanish (Mexico) [es-mx] locale ([#1614](https://github.com/iamkun/dayjs/issues/1614)) ([3393f2a](https://github.com/iamkun/dayjs/commit/3393f2ad55346d55902683a2e31c6f253d96c8c2)) +* Add Arabic (Iraq) [ar-iq] locale ([#1627](https://github.com/iamkun/dayjs/issues/1627)) ([b5a1391](https://github.com/iamkun/dayjs/commit/b5a1391011b247d08863d291542db5937b23b427)) +* add format object type to type file ([#1572](https://github.com/iamkun/dayjs/issues/1572)) ([5a79cc6](https://github.com/iamkun/dayjs/commit/5a79cc6408e825d9e123629eb44fc19c996d7751)) +* duration plugin when parsing duration from ISO string, set missing components to 0 instead of NaN ([#1611](https://github.com/iamkun/dayjs/issues/1611)) ([252585b](https://github.com/iamkun/dayjs/commit/252585b4b2bd59508150e21bb994908a9d78f9b0)) +* narrow type for `add` and `subtract` ([#1576](https://github.com/iamkun/dayjs/issues/1576)) ([1686962](https://github.com/iamkun/dayjs/commit/16869621b1a42563064dbf87f80c1ebfd74c1188)) +* update customParseFormat plugin strict x X parsing ([#1571](https://github.com/iamkun/dayjs/issues/1571)) ([08adda5](https://github.com/iamkun/dayjs/commit/08adda54edbcca38601f57841921d0f87f84e49e)) +* update Lithuanian [lt] locale spelling for single month ([#1609](https://github.com/iamkun/dayjs/issues/1609)) ([255dc54](https://github.com/iamkun/dayjs/commit/255dc54d9295de135a9037ce6ca13cae4bfd2cfb)) +* Update Norwegian Bokmål [nb] local yearStart 4 ([#1608](https://github.com/iamkun/dayjs/issues/1608)) ([7a8467c](https://github.com/iamkun/dayjs/commit/7a8467c0b7d59821f7e19d4a6973bcda8e4c19b1)) +* update plugin advancedFormat `isValid` validation ([#1566](https://github.com/iamkun/dayjs/issues/1566)) ([755fc8b](https://github.com/iamkun/dayjs/commit/755fc8bb1c532eb991459f180eee81367d12016c)) +* update Sinhalese [si] locale month name ([#1475](https://github.com/iamkun/dayjs/issues/1475)) ([63de2a8](https://github.com/iamkun/dayjs/commit/63de2a8b7dcd7e68c132c85d88572d4c9d296907)) +* update utcOffset plugin type file ([#1604](https://github.com/iamkun/dayjs/issues/1604)) ([f68e4b1](https://github.com/iamkun/dayjs/commit/f68e4b1a29fc33542f74cde10ec6d9fb045ca37e)) + ## [1.10.6](https://github.com/iamkun/dayjs/compare/v1.10.5...v1.10.6) (2021-07-06) From 4a7b7d07c885bb9338514c234dbb708e24e9863e Mon Sep 17 00:00:00 2001 From: cazualdev <36430724+cazualdev@users.noreply.github.com> Date: Thu, 16 Dec 2021 10:24:13 -0500 Subject: [PATCH 03/14] fix: Update locale German [de] monthsShort (#1746) --- src/locale/de.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/de.js b/src/locale/de.js index 90f3fa769..de2da91d5 100644 --- a/src/locale/de.js +++ b/src/locale/de.js @@ -29,7 +29,7 @@ const locale = { 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('_'), + monthsShort: 'Jan._Feb._März_Apr._Mai_Juni_Juli_Aug._Sep._Okt._Nov._Dez.'.split('_'), ordinal: n => `${n}.`, weekStart: 1, yearStart: 4, From 74e5247227a779fffde39bdfcd1ee19911496709 Mon Sep 17 00:00:00 2001 From: Muneza Karl <58635033+karl257@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:22:35 +0200 Subject: [PATCH 04/14] fix: Add Kirundi (rn) locale (#1793) --- src/locale/rn.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/locale/rn.js diff --git a/src/locale/rn.js b/src/locale/rn.js new file mode 100644 index 000000000..816e7f0b2 --- /dev/null +++ b/src/locale/rn.js @@ -0,0 +1,40 @@ +// Kirundi [rn] +import dayjs from 'dayjs' + +const locale = { + name: 'rn', + weekdays: 'Ku wa Mungu_Ku wa Mbere_Ku wa Kabiri_Ku wa Gatatu_Ku wa Kane_Ku wa Gatanu_Ku wa Gatandatu'.split('_'), + weekdaysShort: 'Kngu_Kmbr_Kbri_Ktat_Kkan_Ktan_Kdat'.split('_'), + weekdaysMin: 'K7_K1_K2_K3_K4_K5_K6'.split('_'), + months: 'Nzero_Ruhuhuma_Ntwarante_Ndamukiza_Rusama_Ruhenshi_Mukakaro_Myandagaro_Nyakanga_Gitugutu_Munyonyo_Kigarama'.split('_'), + monthsShort: 'Nzer_Ruhuh_Ntwar_Ndam_Rus_Ruhen_Muk_Myand_Nyak_Git_Muny_Kig'.split('_'), + weekStart: 1, + ordinal: n => n, + relativeTime: { + future: 'mu %s', + past: '%s', + s: 'amasegonda', + m: 'Umunota', + mm: '%d iminota', + h: 'isaha', + hh: '%d amasaha', + d: 'Umunsi', + dd: '%d iminsi', + M: 'ukwezi', + MM: '%d amezi', + y: 'umwaka', + yy: '%d imyaka' + }, + 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' + } +} + +dayjs.locale(locale, null, true) + +export default locale From f9055a77bf3d84c575e5fcf99e21611138ba64d7 Mon Sep 17 00:00:00 2001 From: epictecch <57089715+epictecch@users.noreply.github.com> Date: Mon, 28 Feb 2022 13:27:14 +0100 Subject: [PATCH 05/14] fix: update German locales (de-at, de-ch) (#1775) --- src/locale/de-at.js | 44 ++++++++++++++++++++++++++++++---------- src/locale/de-ch.js | 46 +++++++++++++++++++++++++++++++++++++----- test/locale/de.test.js | 43 ++++++++++++++++++++++++++++++--------- 3 files changed, 107 insertions(+), 26 deletions(-) diff --git a/src/locale/de-at.js b/src/locale/de-at.js index db932d078..e36999eef 100644 --- a/src/locale/de-at.js +++ b/src/locale/de-at.js @@ -1,6 +1,28 @@ // German (Austria) [de-at] import dayjs from 'dayjs' +const texts = { + s: 'ein paar Sekunden', + m: ['eine Minute', 'einer Minute'], + mm: '%d Minuten', + h: ['eine Stunde', 'einer Stunde'], + hh: '%d Stunden', + d: ['ein Tag', 'einem Tag'], + dd: ['%d Tage', '%d Tagen'], + M: ['ein Monat', 'einem Monat'], + MM: ['%d Monate', '%d Monaten'], + y: ['ein Jahr', 'einem Jahr'], + yy: ['%d Jahre', '%d Jahren'] +} + +function relativeTimeFormatter(number, withoutSuffix, key) { + let l = texts[key] + if (Array.isArray(l)) { + l = l[withoutSuffix ? 0 : 1] + } + return l.replace('%d', number) +} + const locale = { name: 'de-at', weekdays: 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'), @@ -21,17 +43,17 @@ const locale = { relativeTime: { future: 'in %s', past: 'vor %s', - s: 'ein paar Sekunden', - m: 'einer Minute', - mm: '%d Minuten', - h: 'einer Stunde', - hh: '%d Stunden', - d: 'einem Tag', - dd: '%d Tagen', - M: 'einem Monat', - MM: '%d Monaten', - y: 'einem Jahr', - yy: '%d Jahren' + s: relativeTimeFormatter, + m: relativeTimeFormatter, + mm: relativeTimeFormatter, + h: relativeTimeFormatter, + hh: relativeTimeFormatter, + d: relativeTimeFormatter, + dd: relativeTimeFormatter, + M: relativeTimeFormatter, + MM: relativeTimeFormatter, + y: relativeTimeFormatter, + yy: relativeTimeFormatter } } diff --git a/src/locale/de-ch.js b/src/locale/de-ch.js index 2c4b94d02..50308fa24 100644 --- a/src/locale/de-ch.js +++ b/src/locale/de-ch.js @@ -1,15 +1,37 @@ // German (Switzerland) [de-ch] import dayjs from 'dayjs' +const texts = { + s: 'ein paar Sekunden', + m: ['eine Minute', 'einer Minute'], + mm: '%d Minuten', + h: ['eine Stunde', 'einer Stunde'], + hh: '%d Stunden', + d: ['ein Tag', 'einem Tag'], + dd: ['%d Tage', '%d Tagen'], + M: ['ein Monat', 'einem Monat'], + MM: ['%d Monate', '%d Monaten'], + y: ['ein Jahr', 'einem Jahr'], + yy: ['%d Jahre', '%d Jahren'] +} + +function relativeTimeFormatter(number, withoutSuffix, key) { + let l = texts[key] + if (Array.isArray(l)) { + l = l[withoutSuffix ? 0 : 1] + } + return l.replace('%d', number) +} + const locale = { name: 'de-ch', weekdays: 'Sonntag_Montag_Dienstag_Mittwoch_Donnerstag_Freitag_Samstag'.split('_'), - months: 'Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'), - weekStart: 1, weekdaysShort: 'So_Mo_Di_Mi_Do_Fr_Sa'.split('_'), - monthsShort: 'Jan._Feb._März_Apr._Mai_Juni_Juli_Aug._Sep._Okt._Nov._Dez.'.split('_'), weekdaysMin: 'So_Mo_Di_Mi_Do_Fr_Sa'.split('_'), - ordinal: n => n, + 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._Sep._Okt._Nov._Dez.'.split('_'), + ordinal: n => `${n}.`, + weekStart: 1, formats: { LT: 'HH:mm', LTS: 'HH:mm:ss', @@ -17,10 +39,24 @@ const locale = { LL: 'D. MMMM YYYY', LLL: 'D. MMMM YYYY HH:mm', LLLL: 'dddd, D. MMMM YYYY HH:mm' + }, + relativeTime: { + future: 'in %s', + past: 'vor %s', + s: relativeTimeFormatter, + m: relativeTimeFormatter, + mm: relativeTimeFormatter, + h: relativeTimeFormatter, + hh: relativeTimeFormatter, + d: relativeTimeFormatter, + dd: relativeTimeFormatter, + M: relativeTimeFormatter, + MM: relativeTimeFormatter, + y: relativeTimeFormatter, + yy: relativeTimeFormatter } } dayjs.locale(locale, null, true) export default locale - diff --git a/test/locale/de.test.js b/test/locale/de.test.js index 699b05960..46265f151 100644 --- a/test/locale/de.test.js +++ b/test/locale/de.test.js @@ -3,6 +3,8 @@ import moment from 'moment' import dayjs from '../../src' import relativeTime from '../../src/plugin/relativeTime' import '../../src/locale/de' +import '../../src/locale/de-at' +import '../../src/locale/de-ch' dayjs.extend(relativeTime) @@ -39,11 +41,15 @@ it('German locale relative time in past and future with suffix', () => { [4, 'y', 'in 4 Jahren'], [-4, 'y', 'vor 4 Jahren'] ] - cases.forEach((c) => { - expect(dayjs().add(c[0], c[1]).locale('de').fromNow()) - .toBe(c[2]) - expect(dayjs().add(c[0], c[1]).locale('de').fromNow()) - .toBe(moment().add(c[0], c[1]).locale('de').fromNow()) + + const locales = ['de', 'de-at', 'de-ch'] + locales.forEach((locale) => { + cases.forEach((c) => { + expect(dayjs().add(c[0], c[1]).locale(locale).fromNow()) + .toBe(c[2]) + expect(dayjs().add(c[0], c[1]).locale(locale).fromNow()) + .toBe(moment().add(c[0], c[1]).locale(locale).fromNow()) + }) }) }) @@ -70,10 +76,27 @@ it('German locale relative time in past and future without suffix', () => { [4, 'y', '4 Jahre'], [-4, 'y', '4 Jahre'] ] - cases.forEach((c) => { - expect(dayjs().add(c[0], c[1]).locale('de').fromNow(true)) - .toBe(c[2]) - expect(dayjs().add(c[0], c[1]).locale('de').fromNow(true)) - .toBe(moment().add(c[0], c[1]).locale('de').fromNow(true)) + + const locales = ['de', 'de-at', 'de-ch'] + locales.forEach((locale) => { + cases.forEach((c) => { + expect(dayjs().add(c[0], c[1]).locale(locale).fromNow(true)) + .toBe(c[2]) + expect(dayjs().add(c[0], c[1]).locale(locale).fromNow(true)) + .toBe(moment().add(c[0], c[1]).locale(locale).fromNow(true)) + }) + }) +}) + +it('German locales use region specific names', () => { + const locales = [ + { locale: 'de', expectedFormattedDate: 'Mi., 19. Januar 2022' }, + { locale: 'de-at', expectedFormattedDate: 'Mi., 19. Jänner 2022' }, + { locale: 'de-ch', expectedFormattedDate: 'Mi, 19. Januar 2022' } + ] + + locales.forEach((locale) => { + const dayjsWithLocale = dayjs('2022-01-19').locale(locale.locale) + expect(dayjsWithLocale.format('ddd, D. MMMM YYYY')).toEqual(locale.expectedFormattedDate) }) }) From 9138dc28206875372da4fb74c64716437cd11b95 Mon Sep 17 00:00:00 2001 From: Johan Linderoth Date: Mon, 28 Feb 2022 13:31:35 +0100 Subject: [PATCH 06/14] feat: Fallback to language only locale + support uppercase locales (#1524) * Support uppercase region as in xx-ZZ + fallback to xx if xx-yy does not exist * code review fix, split preset just once * review fixes + don't recurse if split length is 1 Co-authored-by: Johan Linderoth --- src/index.js | 13 +++++++++---- test/plugin/localizedFormat.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 8c919b0d8..c965dd004 100644 --- a/src/index.js +++ b/src/index.js @@ -12,12 +12,17 @@ const parseLocale = (preset, object, isLocal) => { let l if (!preset) return L if (typeof preset === 'string') { - if (Ls[preset]) { - l = preset + const presetLower = preset.toLowerCase() + if (Ls[presetLower]) { + l = presetLower } if (object) { - Ls[preset] = object - l = preset + Ls[presetLower] = object + l = presetLower + } + const presetSplit = preset.split('-') + if (!l && presetSplit.length > 1) { + return parseLocale(presetSplit[0]) } } else { const { name } = preset diff --git a/test/plugin/localizedFormat.test.js b/test/plugin/localizedFormat.test.js index 1c7a89e14..da5b219e0 100644 --- a/test/plugin/localizedFormat.test.js +++ b/test/plugin/localizedFormat.test.js @@ -96,6 +96,16 @@ it('Uses the localized lowercase formats if defined', () => { ['l', 'll', 'lll', 'llll'].forEach(option => expect(znDate.format(option)).toBe(znDate.format(znCn.formats[option]))) }) +it('Uses fallback to xx if xx-yy not available', () => { + expect(dayjs('2019-02-01').locale('en-yy').format('MMMM')) + .toBe('February') +}) + +it('Uses xx-yy if xx-YY is provided', () => { + expect(dayjs('2019-02-01').locale('es-US').format('MMMM')) + .toBe('febrero') +}) + it('Uses the localized uppercase formats as a base for lowercase formats, if not defined', () => { const date = new Date() const spanishDate = dayjs(date, { locale: es }); From 76f9e1756de7e99c01e471dab30ea074b9ec9629 Mon Sep 17 00:00:00 2001 From: Hlynur Tryggvason Date: Mon, 28 Feb 2022 13:41:34 +0100 Subject: [PATCH 07/14] fix: update Icelandic [is] locale relativeTime config (#1796) --- src/locale/is.js | 55 +++++++++++++++++++- test/locale/is.test.js | 115 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 test/locale/is.test.js diff --git a/src/locale/is.js b/src/locale/is.js index 7b1409e67..d3a12d86d 100644 --- a/src/locale/is.js +++ b/src/locale/is.js @@ -1,6 +1,45 @@ // Icelandic [is] import dayjs from 'dayjs' +const texts = { + s: ['nokkrar sekúndur', 'nokkrar sekúndur', 'nokkrum sekúndum'], + m: ['mínúta', 'mínútu', 'mínútu'], + mm: ['mínútur', 'mínútur', 'mínútum'], + h: ['klukkustund', 'klukkustund', 'klukkustund'], + hh: ['klukkustundir', 'klukkustundir', 'klukkustundum'], + d: ['dagur', 'dag', 'degi'], + dd: ['dagar', 'daga', 'dögum'], + M: ['mánuður', 'mánuð', 'mánuði'], + MM: ['mánuðir', 'mánuði', 'mánuðum'], + y: ['ár', 'ár', 'ári'], + yy: ['ár', 'ár', 'árum'] +} + +function resolveTemplate(key, number, isFuture, withoutSuffix) { + const suffixIndex = isFuture + ? 1 + : 2 + + const index = withoutSuffix + ? 0 + : suffixIndex + + const keyShouldBeSingular = key.length === 2 && number % 10 === 1 + + const correctedKey = keyShouldBeSingular ? key[0] : key + const unitText = texts[correctedKey] + const text = unitText[index] + return key.length === 1 + ? text + : `%d ${text}` +} + +function relativeTimeFormatter(number, withoutSuffix, key, isFuture) { + const template = resolveTemplate(key, number, isFuture, withoutSuffix) + + return template.replace('%d', number) +} + const locale = { name: 'is', weekdays: 'sunnudagur_mánudagur_þriðjudagur_miðvikudagur_fimmtudagur_föstudagur_laugardagur'.split('_'), @@ -17,10 +56,24 @@ const locale = { LL: 'D. MMMM YYYY', LLL: 'D. MMMM YYYY [kl.] H:mm', LLLL: 'dddd, D. MMMM YYYY [kl.] H:mm' + }, + relativeTime: { + future: 'eftir %s', + past: 'fyrir %s síðan', + s: relativeTimeFormatter, + m: relativeTimeFormatter, + mm: relativeTimeFormatter, + h: relativeTimeFormatter, + hh: relativeTimeFormatter, + d: relativeTimeFormatter, + dd: relativeTimeFormatter, + M: relativeTimeFormatter, + MM: relativeTimeFormatter, + y: relativeTimeFormatter, + yy: relativeTimeFormatter } } dayjs.locale(locale, null, true) export default locale - diff --git a/test/locale/is.test.js b/test/locale/is.test.js new file mode 100644 index 000000000..0198b0f2b --- /dev/null +++ b/test/locale/is.test.js @@ -0,0 +1,115 @@ +import MockDate from 'mockdate' +import moment from 'moment' +import dayjs from '../../src' +import '../../src/locale/is' +import relativeTime from '../../src/plugin/relativeTime' + +dayjs.extend(relativeTime) + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +const expectations = [ + [1, 's', 'nokkrar sekúndur', 'fyrir nokkrum sekúndum síðan', 'eftir nokkrar sekúndur'], + [1, 'm', 'mínúta', 'fyrir mínútu síðan', 'eftir mínútu'], + [1, 'h', 'klukkustund', 'fyrir klukkustund síðan', 'eftir klukkustund'], + [1, 'd', 'dagur', 'fyrir degi síðan', 'eftir dag'], + [1, 'M', 'mánuður', 'fyrir mánuði síðan', 'eftir mánuð'], + [1, 'y', 'ár', 'fyrir ári síðan', 'eftir ár'], + [2, 'm', '2 mínútur', 'fyrir 2 mínútum síðan', 'eftir 2 mínútur'], + [2, 'h', '2 klukkustundir', 'fyrir 2 klukkustundum síðan', 'eftir 2 klukkustundir'], + [2, 'd', '2 dagar', 'fyrir 2 dögum síðan', 'eftir 2 daga'], + [2, 'M', '2 mánuðir', 'fyrir 2 mánuðum síðan', 'eftir 2 mánuði'], + [2, 'y', '2 ár', 'fyrir 2 árum síðan', 'eftir 2 ár'], + [21, 'm', '21 mínúta', 'fyrir 21 mínútu síðan', 'eftir 21 mínútu'], + [21, 'h', '21 klukkustund', 'fyrir 21 klukkustund síðan', 'eftir 21 klukkustund'], + [21, 'd', '21 dagur', 'fyrir 21 degi síðan', 'eftir 21 dag'], + [21, 'y', '21 ár', 'fyrir 21 ári síðan', 'eftir 21 ár'] +] + +describe('moment compatibility', () => { + it('without suffix', () => { + expectations.forEach((expectation) => { + const [offset, unit, expectationWithoutSuffix] = expectation + + const momentResult = moment() + .add(offset, unit) + .locale('is') + .fromNow(true) + + expect(expectationWithoutSuffix).toBe(momentResult) + }) + }) + + it('past', () => { + expectations.forEach((expectation) => { + const [offset, unit, , pastExpectation] = expectation + + const momentResult = moment() + .add(-offset, unit) + .locale('is') + .fromNow() + + expect(pastExpectation).toBe(momentResult) + }) + }) + + it('future', () => { + expectations.forEach((expectation) => { + const [offset, unit, , , futureExpectation] = expectation + + const momentResult = moment() + .add(offset, unit) + .locale('is') + .fromNow() + + expect(futureExpectation).toBe(momentResult) + }) + }) +}) + +describe('Icelandic output matches moment output', () => { + it('without suffix', () => { + expectations.forEach((expectation) => { + const [offset, unit, expectationWithoutSuffix] = expectation + + const result = dayjs() + .add(offset, unit) + .locale('is') + .fromNow(true) + + expect(result).toBe(expectationWithoutSuffix) + }) + }) + + it('past', () => { + expectations.forEach((expectation) => { + const [offset, unit, , pastExpectation] = expectation + + const result = dayjs() + .add(-offset, unit) + .locale('is') + .fromNow() + + expect(result).toBe(pastExpectation) + }) + }) + + it('future', () => { + expectations.forEach((expectation) => { + const [offset, unit, , , futureExpectation] = expectation + + const result = dayjs() + .add(offset, unit) + .locale('is') + .fromNow() + + expect(result).toBe(futureExpectation) + }) + }) +}) From e01930171c8235f58a114236f146086428f99569 Mon Sep 17 00:00:00 2001 From: Henrique Bruno Date: Mon, 28 Feb 2022 09:47:37 -0300 Subject: [PATCH 08/14] fix(): set locale pt, pt-br correct weekdays and months (#1697) --- src/locale/pt-br.js | 8 ++++---- src/locale/pt.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/locale/pt-br.js b/src/locale/pt-br.js index 1cc2d51ef..f5d4f4ee1 100644 --- a/src/locale/pt-br.js +++ b/src/locale/pt-br.js @@ -3,11 +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('_'), + 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('_'), - 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('_'), + 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', diff --git a/src/locale/pt.js b/src/locale/pt.js index d710c4a87..d78974114 100644 --- a/src/locale/pt.js +++ b/src/locale/pt.js @@ -3,11 +3,11 @@ import dayjs from 'dayjs' 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('_'), + 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('_'), + 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}º`, weekStart: 1, yearStart: 4, From a6eef52a97e83baee993a47e28b8960257999a9a Mon Sep 17 00:00:00 2001 From: Sasha Hulitskyi <59656367+alexgul1@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:49:45 +0300 Subject: [PATCH 09/14] chore: add references to another readme files (#1726) --- docs/es-es/README-es-es.md | 4 +++- docs/ja/README-ja.md | 4 +++- docs/ko/README-ko.md | 4 +++- docs/pt-br/README-pt-br.md | 4 +++- docs/ru/README-ru.md | 6 ++++-- docs/zh-cn/README.zh-CN.md | 4 +++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/es-es/README-es-es.md b/docs/es-es/README-es-es.md index 4e536343c..ae190e846 100644 --- a/docs/es-es/README-es-es.md +++ b/docs/es-es/README-es-es.md @@ -1,4 +1,6 @@ -

Day.js

Alternativa rápida y ligera 2kB a Moment.js, con la misma API moderna

diff --git a/docs/ja/README-ja.md b/docs/ja/README-ja.md index 1cc8ca36e..b40ceeb4b 100644 --- a/docs/ja/README-ja.md +++ b/docs/ja/README-ja.md @@ -1,4 +1,6 @@ -

Day.js

Moment.js と同じ API を備えた 2kB の軽量ライブラリ

diff --git a/docs/ko/README-ko.md b/docs/ko/README-ko.md index 6a6ccce1d..7d6228d28 100644 --- a/docs/ko/README-ko.md +++ b/docs/ko/README-ko.md @@ -1,4 +1,6 @@ -

Day.js

Moment.js와 호환되는 API를 가진 경량 라이브러리 (2kB)

diff --git a/docs/pt-br/README-pt-br.md b/docs/pt-br/README-pt-br.md index 275928dd4..78031b2d7 100644 --- a/docs/pt-br/README-pt-br.md +++ b/docs/pt-br/README-pt-br.md @@ -1,4 +1,6 @@ -

Day.js

Alternativa veloz ao Moment.js, com 2kB e a mesma API moderna

diff --git a/docs/ru/README-ru.md b/docs/ru/README-ru.md index 55f22c852..c8f9b83ca 100644 --- a/docs/ru/README-ru.md +++ b/docs/ru/README-ru.md @@ -1,4 +1,6 @@ -

Day.js

Быстрая 2kB альтернатива Moment.js с тем же современным API

@@ -27,7 +29,7 @@ dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); ``` -* 🕒 Хорошо знакомые API и паттерны Moment.js +* 🕒 Хорошо знакомые API и паттерны Moment.js * 💪 Неизменная * 🔥 Цепная * 🌐 Поддержка интернационализации (I18n) diff --git a/docs/zh-cn/README.zh-CN.md b/docs/zh-cn/README.zh-CN.md index af94085c2..b543a80f1 100644 --- a/docs/zh-cn/README.zh-CN.md +++ b/docs/zh-cn/README.zh-CN.md @@ -1,4 +1,6 @@ -

Day.js

Moment.js 的 2kB 轻量化方案,拥有同样强大的 API

From a9aa18ed3d4d7959fa5b8c1b048c21ff525f9296 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 28 Feb 2022 12:50:53 +0000 Subject: [PATCH 10/14] chore(release): 1.10.8 [skip ci] ## [1.10.8](https://github.com/iamkun/dayjs/compare/v1.10.7...v1.10.8) (2022-02-28) ### Bug Fixes * set locale pt, pt-br correct weekdays and months ([#1697](https://github.com/iamkun/dayjs/issues/1697)) ([e019301](https://github.com/iamkun/dayjs/commit/e01930171c8235f58a114236f146086428f99569)) --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2eba1691..e91383d78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.10.8](https://github.com/iamkun/dayjs/compare/v1.10.7...v1.10.8) (2022-02-28) + + +### Bug Fixes + +* set locale pt, pt-br correct weekdays and months ([#1697](https://github.com/iamkun/dayjs/issues/1697)) ([e019301](https://github.com/iamkun/dayjs/commit/e01930171c8235f58a114236f146086428f99569)) + ## [1.10.7](https://github.com/iamkun/dayjs/compare/v1.10.6...v1.10.7) (2021-09-10) From c7a3f73064dbb63b4d365b2ad4c792f075f4d8d8 Mon Sep 17 00:00:00 2001 From: Lukasz Szymanski Date: Mon, 28 Feb 2022 13:51:16 +0100 Subject: [PATCH 11/14] fix: update updateLocal plugin typescript types (#1692) Co-authored-by: Lukasz Szymanski --- types/plugin/updateLocale.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/plugin/updateLocale.d.ts b/types/plugin/updateLocale.d.ts index 44bce470d..ef1c01df9 100644 --- a/types/plugin/updateLocale.d.ts +++ b/types/plugin/updateLocale.d.ts @@ -4,5 +4,5 @@ declare const plugin: PluginFunc export = plugin declare module 'dayjs' { - export function updateLocale(localeName: String, customConfig: Object): any + export function updateLocale(localeName: string, customConfig: Record): Record } From efd3904ff8cbf0a4fc064911dda76fc86b669f7b Mon Sep 17 00:00:00 2001 From: Akam Foad <41629832+akamfoad@users.noreply.github.com> Date: Tue, 1 Mar 2022 17:55:15 +0300 Subject: [PATCH 12/14] fix: update meridiem function to Kurdish (ku) locale (#1725) --- src/locale/ku.js | 1 + test/locale/ku.test.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/locale/ku.test.js diff --git a/src/locale/ku.js b/src/locale/ku.js index 5f1ce6a60..07a6b2f16 100644 --- a/src/locale/ku.js +++ b/src/locale/ku.js @@ -18,6 +18,7 @@ const locale = { LLL: 'D MMMM YYYY HH:mm', LLLL: 'dddd, D MMMM YYYY HH:mm' }, + meridiem: hour => (hour < 12 ? 'پ.ن' : 'د.ن'), relativeTime: { future: 'له‌ %s', past: '%s', diff --git a/test/locale/ku.test.js b/test/locale/ku.test.js new file mode 100644 index 000000000..d3dec4c28 --- /dev/null +++ b/test/locale/ku.test.js @@ -0,0 +1,20 @@ +import MockDate from 'mockdate' +import dayjs from '../../src' +import '../../src/locale/ku' + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Format meridiem correctly', () => { + for (let i = 0; i <= 23; i += 1) { + const dayjsKu = dayjs() + .startOf('day') + .add(i, 'hour') + expect(dayjsKu.locale('ku').format('h A')).toBe(`${i % 12 || 12} ${i < 12 ? 'پ.ن' : 'د.ن'}`) + } +}) From dcbf1708400624addfbddbc71e0f6a9ac15fa961 Mon Sep 17 00:00:00 2001 From: anxogcd <79111201+anxogcd@users.noreply.github.com> Date: Tue, 1 Mar 2022 16:00:09 +0100 Subject: [PATCH 13/14] fix: Add relative time to Galician (gl) and fix ordinals (#1800) --- src/locale/gl.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/locale/gl.js b/src/locale/gl.js index 77f2dbb66..64d76b07d 100644 --- a/src/locale/gl.js +++ b/src/locale/gl.js @@ -9,7 +9,7 @@ const locale = { weekdaysShort: 'dom._lun._mar._mér._xov._ven._sáb.'.split('_'), monthsShort: 'xan._feb._mar._abr._mai._xuñ._xul._ago._set._out._nov._dec.'.split('_'), weekdaysMin: 'do_lu_ma_mé_xo_ve_sá'.split('_'), - ordinal: n => n, + ordinal: n => `${n}º`, formats: { LT: 'H:mm', LTS: 'H:mm:ss', @@ -17,6 +17,21 @@ const locale = { 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: 'fai %s', + s: 'uns segundos', + m: 'un minuto', + mm: '%d minutos', + h: 'unha hora', + hh: '%d horas', + d: 'un día', + dd: '%d días', + M: 'un mes', + MM: '%d meses', + y: 'un ano', + yy: '%d anos' } } From b045baf1646a81f7e4f446f355d02d5fb0ef4aa7 Mon Sep 17 00:00:00 2001 From: Sun <1652829889@qq.com> Date: Fri, 11 Mar 2022 20:53:54 +0800 Subject: [PATCH 14/14] fix: add missing date shorthand D type definition (#1752) --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 37901395c..86b3cfe0c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -19,7 +19,7 @@ declare namespace dayjs { export type OptionType = FormatObject | string | string[] - export type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms' + export type UnitTypeShort = 'd' | 'D' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms' export type UnitTypeLong = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year' | 'date'