From 32b7fe321415b394f0f62e0f000ef5dca78fdc34 Mon Sep 17 00:00:00 2001 From: iamkun Date: Mon, 11 Apr 2022 22:40:13 +0800 Subject: [PATCH 1/8] chore: add sponsors (#1851) --- README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ef306253c..ee5c5cb0d 100644 --- a/README.md +++ b/README.md @@ -100,12 +100,21 @@ dayjs().format('Q Do k kk X x') // more available formats ## Sponsors -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/dayjs#sponsor)] - - - - - +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. + +[[Become a sponsor via Github](https://github.com/sponsors/iamkun/)] [[Become a sponsor via OpenCollective](https://opencollective.com/dayjs#sponsor)] + + + + +         + +         + +         + +         + ## Contributors From 840ed76eedc085afefc4dedd05f31d44196b63b0 Mon Sep 17 00:00:00 2001 From: Shahibuzzaman <54662315+shahibuzzaman@users.noreply.github.com> Date: Thu, 14 Apr 2022 18:41:54 +0600 Subject: [PATCH 2/8] fix: add Bengali (Bangladesh) [bn-bd] locale (#1806) --- src/locale/bn-bd.js | 91 +++++++++++++++++++++++++++++++++++++++ test/locale/bn-bd.test.js | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/locale/bn-bd.js create mode 100644 test/locale/bn-bd.test.js diff --git a/src/locale/bn-bd.js b/src/locale/bn-bd.js new file mode 100644 index 000000000..4d94b96e9 --- /dev/null +++ b/src/locale/bn-bd.js @@ -0,0 +1,91 @@ +// Bengali (Bangladesh) [bn-bd] +import dayjs from 'dayjs' + +const symbolMap = { + 1: '১', + 2: '২', + 3: '৩', + 4: '৪', + 5: '৫', + 6: '৬', + 7: '৭', + 8: '৮', + 9: '৯', + 0: '০' +} + +const numberMap = { + '১': '1', + '২': '2', + '৩': '3', + '৪': '4', + '৫': '5', + '৬': '6', + '৭': '7', + '৮': '8', + '৯': '9', + '০': '0' +} + +const locale = { + name: 'bn-bd', + weekdays: 'রবিবার_সোমবার_মঙ্গলবার_বুধবার_বৃহস্পতিবার_শুক্রবার_শনিবার'.split('_'), + months: 'জানুয়ারি_ফেব্রুয়ারি_মার্চ_এপ্রিল_মে_জুন_জুলাই_আগস্ট_সেপ্টেম্বর_অক্টোবর_নভেম্বর_ডিসেম্বর'.split('_'), + weekdaysShort: 'রবি_সোম_মঙ্গল_বুধ_বৃহস্পতি_শুক্র_শনি'.split('_'), + monthsShort: 'জানু_ফেব্রু_মার্চ_এপ্রিল_মে_জুন_জুলাই_আগস্ট_সেপ্ট_অক্টো_নভে_ডিসে'.split('_'), + weekdaysMin: 'রবি_সোম_মঙ্গ_বুধ_বৃহঃ_শুক্র_শনি'.split('_'), + weekStart: 0, + preparse(string) { + return string.replace(/[১২৩৪৫৬৭৮৯০]/g, match => numberMap[match]) + }, + postformat(string) { + return string.replace(/\d/g, match => symbolMap[match]) + }, + ordinal: (n) => { + const s = ['ই', 'লা', 'রা', 'ঠা', 'শে'] + const v = n % 100 + return `[${n}${s[(v - 20) % 10] || s[v] || s[0]}]` + }, + formats: { + LT: 'A h:mm সময়', + LTS: 'A h:mm:ss সময়', + L: 'DD/MM/YYYY খ্রিস্টাব্দ', + LL: 'D MMMM YYYY খ্রিস্টাব্দ', + LLL: 'D MMMM YYYY খ্রিস্টাব্দ, A h:mm সময়', + LLLL: 'dddd, D MMMM YYYY খ্রিস্টাব্দ, A h:mm সময়' + }, + meridiem: hour => + /* eslint-disable no-nested-ternary */ + (hour < 4 + ? 'রাত' + : hour < 6 + ? 'ভোর' + : hour < 12 + ? 'সকাল' + : hour < 15 + ? 'দুপুর' + : hour < 18 + ? 'বিকাল' + : hour < 20 + ? 'সন্ধ্যা' + : 'রাত'), + relativeTime: { + future: '%s পরে', + past: '%s আগে', + s: 'কয়েক সেকেন্ড', + m: 'এক মিনিট', + mm: '%d মিনিট', + h: 'এক ঘন্টা', + hh: '%d ঘন্টা', + d: 'এক দিন', + dd: '%d দিন', + M: 'এক মাস', + MM: '%d মাস', + y: 'এক বছর', + yy: '%d বছর' + } +} + +dayjs.locale(locale, null, true) + +export default locale diff --git a/test/locale/bn-bd.test.js b/test/locale/bn-bd.test.js new file mode 100644 index 000000000..e57c6a3ad --- /dev/null +++ b/test/locale/bn-bd.test.js @@ -0,0 +1,81 @@ +import moment from 'moment' +import MockDate from 'mockdate' +import dayjs from '../../src' +import relativeTime from '../../src/plugin/relativeTime' +import localeData from '../../src/plugin/localeData' +import preParsePostFormat from '../../src/plugin/preParsePostFormat' +import '../../src/locale/bn-bd' + +dayjs.extend(localeData) +dayjs.extend(relativeTime) +dayjs.extend(preParsePostFormat) + +beforeEach(() => { + MockDate.set(new Date()) +}) + +afterEach(() => { + MockDate.reset() +}) + +it('Format Month with locale function', () => { + for (let i = 0; i <= 7; i += 1) { + const dayjsBN = dayjs() + .locale('bn-bd') + .add(i, 'day') + const momentBN = moment() + .locale('bn-bd') + .add(i, 'day') + const testFormat1 = 'DD MMMM YYYY MMM' + const testFormat2 = 'MMMM' + const testFormat3 = 'MMM' + expect(dayjsBN.format(testFormat1)).toEqual(momentBN.format(testFormat1)) + expect(dayjsBN.format(testFormat2)).toEqual(momentBN.format(testFormat2)) + expect(dayjsBN.format(testFormat3)).toEqual(momentBN.format(testFormat3)) + } +}) + +it('Month short', () => { + const date = '2021-02-01T05:54:32.005Z' + const dayjsBN = dayjs(date) + .locale('bn-bd') + const momentBN = moment(date) + .locale('bn-bd') + const testFormat1 = 'DD MMMM YYYY MMM' + expect(dayjsBN.format(testFormat1)).toEqual(momentBN.format(testFormat1)) +}) + +it('Preparse with locale function', () => { + for (let i = 0; i <= 7; i += 1) { + dayjs.locale('bn-bd') + const momentBN = moment() + .locale('bn-bd') + .add(i, 'day') + expect(dayjs(momentBN.format()).format()).toEqual(momentBN.format()) + } +}) + +it('RelativeTime: Time from X', () => { + const T = [ + [44.4, 'second'], // a few seconds + [89.5, 'second'], // a minute + [130, 'second'], // two minutes + [43, 'minute'], // 44 minutes + [1, 'hour'], // 1 hour + [21, 'hour'], // 21 hours + [2, 'day'], // 2 days + [25, 'day'], // 25 days + [2, 'month'], // 2 months + [10, 'month'], // 10 months + [18, 'month'], // 2 years + [15, 'year'] // 15 years + ] + + T.forEach((t) => { + dayjs.locale('bn-bd') + moment.locale('bn-bd') + expect(dayjs().from(dayjs().add(t[0], t[1]))).toBe(moment().from(moment().add(t[0], t[1]))) + expect(dayjs().from(dayjs().add(t[0], t[1]), true)) + .toBe(moment().from(moment().add(t[0], t[1]), true)) + }) +}) From d2783a4d225d02c0fc47f88397c90f67add42fe4 Mon Sep 17 00:00:00 2001 From: Engincan VESKE <43685404+EngincanV@users.noreply.github.com> Date: Thu, 14 Apr 2022 15:50:57 +0300 Subject: [PATCH 3/8] chore: Add Turkish README.md (#1840) --- README.md | 2 +- docs/tr/README-tr.md | 136 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 docs/tr/README-tr.md diff --git a/README.md b/README.md index ee5c5cb0d..728dadfbe 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/README-ja.md) | [Português Brasileiro](./docs/pt-br/README-pt-br.md) | [한국어](./docs/ko/README-ko.md) | [Español (España)](./docs/es-es/README-es-es.md) | [Русский](./docs/ru/README-ru.md) +English | [简体中文](./docs/zh-cn/README.zh-CN.md) | [日本語](./docs/ja/README-ja.md) | [Português Brasileiro](./docs/pt-br/README-pt-br.md) | [한국어](./docs/ko/README-ko.md) | [Español (España)](./docs/es-es/README-es-es.md) | [Русский](./docs/ru/README-ru.md) | [Türkçe](./docs/tr/README-tr.md)

Day.js

+

Aynı modern API ile 2kB hızlı bir Moment.js alternatifi

+
+

+ Gzip Size + NPM Version + Build Status + Codecov + License +
+ + Sauce Test Status + +

+ +> Day.js, büyük ölçüde Moment.js uyumlu bir API ile modern tarayıcılar için tarih ve saatleri dönüştüren, doğrulayan, işleyen ve görüntüleyen minimalist bir JavaScript kütüphanesidir. Moment.js kullanıyorsanız, Day.js'i nasıl kullanacağınızı zaten biliyorsunuzdur. + +```js +dayjs() + .startOf('month') + .add(1, 'day') + .set('year', 2018) + .format('YYYY-MM-DD HH:mm:ss') +``` + +- 🕒 Benzer Moment.js API & Kalıpları +- 💪 Değişmez +- 🔥 Zincirlenebilir +- 🌐 I18n destekler +- 📦 2kB boyutunda küçük bir kütaphane +- 👫 Bütün tarayıcılarda desteklenir + +--- + +# Başlarken + +### Dökümantasyon + +Daha fazla bilgiye, API ve diğer dökümanlara [day.js.org](https://day.js.org/) websitesinden ulaşabilirsiniz. + +## Kurulum + +```console +npm install dayjs --save +``` + +📚[Kurulum Rehberi](https://day.js.org/docs/en/installation/installation) + +## API + +Tarihleri ve saatleri dönüştürmek, doğrulamak, işlemek ve görüntülemek için Day.js API'larını kullanmak kolaydır. + +```javascript +dayjs('2018-08-08') // dönüştürme + +dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // belirli bir formatta görüntüleme + +dayjs() + .set('month', 3) + .month() // görüntüleme & değer atama + +dayjs().add(1, 'year') // değiştirme + +dayjs().isBefore(dayjs()) // sorgulama +``` + +📚[API Referansı](https://day.js.org/docs/en/parse/parse) + +## I18n + +Day.js, uluslararasılaştırma için büyük desteğe sahiptir. + +Ancak siz kullanmadığınız sürece bunların hiçbiri yapınıza dahil edilmeyecektir. + +```javascript +import 'dayjs/locale/es' // isteğe göre yükle + +dayjs.locale('tr') // yerel ayarı Türkçe olarak kullan + +dayjs('2018-05-05') + .locale('zh-cn') + .format() //belirli bir durum için Basitleştirilmiş Çince formatında görüntüleme +``` + +📚[Uluslararasılaştırma](https://day.js.org/docs/en/i18n/i18n) + +## Eklenti + +Eklenti, işlevselliği genişletmek veya yeni özellikler eklemek için Day.js'e eklenebilen bağımsız bir modüldür. + +```javascript +import advancedFormat from 'dayjs/plugin/advancedFormat' // isteğe göre yükle + +dayjs.extend(advancedFormat) // eklentiyi kullan + +dayjs().format('Q Do k kk X x') // diğer mevcut formatlar +``` + +📚[Eklenti Listesi](https://day.js.org/docs/en/plugin/plugin) + +## Sponsorlar + +Sponsor olarak bu projeye destek olun. Logonuz, web sayfanızın linki ile birlikte burada görünür. [[Sponsor Ol](https://opencollective.com/dayjs#sponsor)] + + + + + + +## Katkıda Bulunanlar + +Bu proje, katkıda bulunan tüm insanlar sayesinde mevcut. + +Lütfen bize destek olmak için projeye 💖 yıldız 💖 verin. Teşekkürler. + +Ve tüm destekçilerimize teşekkür ederiz! 🙏 + + + + + + + +## Lisans + +Day.js, bir [MIT Lisansı](../../LICENSE) altında lisanslanmıştır. \ No newline at end of file From 627fa393e4daf83c92431162dbe18534b23fcbae Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Thu, 14 Apr 2022 14:53:29 +0200 Subject: [PATCH 4/8] fix: refactor replace deprecated String.prototype.substr() (#1836) --- src/index.js | 2 +- src/plugin/customParseFormat/index.js | 4 ++-- src/plugin/localeData/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index c965dd004..19c409078 100644 --- a/src/index.js +++ b/src/index.js @@ -267,7 +267,7 @@ class Dayjs { weekdays, months, meridiem } = locale const getShort = (arr, index, full, length) => ( - (arr && (arr[index] || arr(this, str))) || full[index].substr(0, length) + (arr && (arr[index] || arr(this, str))) || full[index].slice(0, length) ) const get$H = num => ( Utils.s($H % 12 || 12, num, '0') diff --git a/src/plugin/customParseFormat/index.js b/src/plugin/customParseFormat/index.js index fc3b788f4..f662a4ab8 100644 --- a/src/plugin/customParseFormat/index.js +++ b/src/plugin/customParseFormat/index.js @@ -100,7 +100,7 @@ const expressions = { MMM: [matchWord, function (input) { const months = getLocalePart('months') const monthsShort = getLocalePart('monthsShort') - const matchIndex = (monthsShort || months.map(_ => _.substr(0, 3))).indexOf(input) + 1 + const matchIndex = (monthsShort || months.map(_ => _.slice(0, 3))).indexOf(input) + 1 if (matchIndex < 1) { throw new Error() } @@ -161,7 +161,7 @@ function makeParser(format) { start += token.length } else { const { regex, parser } = token - const part = input.substr(start) + const part = input.slice(start) const match = regex.exec(part) const value = match[0] parser.call(time, value) diff --git a/src/plugin/localeData/index.js b/src/plugin/localeData/index.js index 034dbea13..763bfdb6d 100644 --- a/src/plugin/localeData/index.js +++ b/src/plugin/localeData/index.js @@ -7,7 +7,7 @@ export default (o, c, dayjs) => { // locale needed later const locale = ins.name ? ins : ins.$locale() const targetLocale = getLocalePart(locale[target]) const fullLocale = getLocalePart(locale[full]) - const result = targetLocale || fullLocale.map(f => f.substr(0, num)) + const result = targetLocale || fullLocale.map(f => f.slice(0, num)) if (!localeOrder) return result const { weekStart } = locale return result.map((_, index) => (result[(index + (weekStart || 0)) % 7])) From 4e2802cc3bec2941ffb737a15fb531c90951eafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Mei=C3=9Fner?= Date: Thu, 14 Apr 2022 14:58:13 +0200 Subject: [PATCH 5/8] fix: Update German [de] locale, adds the abbreviations for month including a . in the end, as in September -> Sept. (#1831) --- 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 de2da91d5..d48d5e1ee 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._Sep._Okt._Nov._Dez.'.split('_'), + monthsShort: 'Jan._Feb._März_Apr._Mai_Juni_Juli_Aug._Sept._Okt._Nov._Dez.'.split('_'), ordinal: n => `${n}.`, weekStart: 1, yearStart: 4, From 8e6d11d053393d97bee1ba411adb2d82de1a58c4 Mon Sep 17 00:00:00 2001 From: Max Hellwig <54803377+maxhellwig@users.noreply.github.com> Date: Thu, 14 Apr 2022 15:00:44 +0200 Subject: [PATCH 6/8] fix: update Italian (Switzerland) [it-ch] locale relativeTime (#1829) --- src/locale/it-ch.js | 15 +++++++++ test/locale/it-ch.test.js | 71 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 test/locale/it-ch.test.js diff --git a/src/locale/it-ch.js b/src/locale/it-ch.js index b71bdc323..b3fc82f59 100644 --- a/src/locale/it-ch.js +++ b/src/locale/it-ch.js @@ -17,6 +17,21 @@ const locale = { LL: 'D MMMM YYYY', LLL: 'D MMMM YYYY HH:mm', LLLL: 'dddd D MMMM YYYY HH:mm' + }, + relativeTime: { + future: 'tra %s', + past: '%s fa', + s: 'alcuni secondi', + m: 'un minuto', + mm: '%d minuti', + h: 'un\'ora', + hh: '%d ore', + d: 'un giorno', + dd: '%d giorni', + M: 'un mese', + MM: '%d mesi', + y: 'un anno', + yy: '%d anni' } } diff --git a/test/locale/it-ch.test.js b/test/locale/it-ch.test.js new file mode 100644 index 000000000..c31632927 --- /dev/null +++ b/test/locale/it-ch.test.js @@ -0,0 +1,71 @@ +import moment from 'moment' +import MockDate from 'mockdate' +import dayjs from '../../src' +import '../../src/locale/it-ch' +import relativeTime from '../../src/plugin/relativeTime' +import localizedFormat from '../../src/plugin/localizedFormat' + +dayjs.extend(relativeTime) +dayjs.extend(localizedFormat) + +describe('Italian formats in Switzerland', () => { + beforeEach(() => { + dayjs.locale('it-ch') + moment.locale('it-ch') + + MockDate.set(new Date()) + }) + + afterEach(() => { + MockDate.reset() + }) + + + it('Format month with locale function', () => { + for (let i = 0; i <= 7; i += 1) { + const dayjsWithLocale = dayjs().add(i, 'day') + const momentWithLocale = moment().add(i, 'day') + const testFormat1 = 'DD MMMM YYYY MMM' + const testFormat2 = 'dddd, MMMM D YYYY' + const testFormat3 = 'MMMM' + const testFormat4 = 'MMM' + const testFormat5 = 'L' + expect(dayjsWithLocale.format(testFormat1)).toEqual(momentWithLocale.format(testFormat1)) + expect(dayjsWithLocale.format(testFormat2)).toEqual(momentWithLocale.format(testFormat2)) + expect(dayjsWithLocale.format(testFormat3)).toEqual(momentWithLocale.format(testFormat3)) + expect(dayjsWithLocale.format(testFormat4)).toEqual(momentWithLocale.format(testFormat4)) + expect(dayjsWithLocale.format(testFormat5)).toEqual(momentWithLocale.format(testFormat5)) + } + }) + + it('RelativeTime: Time from X', () => { + const T = [ + [44.4, 'second'], // a few seconds + [89.5, 'second'], // a minute + [2, 'minute'], // 2 minutes + [5, 'minute'], // 5 minutes + [43, 'minute'], // 44 minutes + [45, 'minute'], // an hour + [3, 'hour'], // 3 hours + [21, 'hour'], // 21 hours + [1, 'day'], // a day + [3, 'day'], // 3 day + [25, 'day'], // 25 days + [1, 'month'], // a month + [2, 'month'], // 2 month + [10, 'month'], // 10 month + [1, 'year'], // a year + [2, 'year'], // 2 year + [5, 'year'], // 5 year + [18, 'month'] // 2 years + ] + + + T.forEach((t) => { + expect(dayjs().from(dayjs().add(t[0], t[1]))) + .toBe(moment().from(moment().add(t[0], t[1]))) + expect(dayjs().from(dayjs().add(t[0], t[1]), true)) + .toBe(moment().from(moment().add(t[0], t[1]), true)) + }) + }) +}) From e79051617af6787358f6c9b5443d987b8b53a9e1 Mon Sep 17 00:00:00 2001 From: KalDhondup <46901192+KalDhondup@users.noreply.github.com> Date: Thu, 14 Apr 2022 18:37:18 +0530 Subject: [PATCH 7/8] fix: update locale bo [Tibetan]: corrected the orders in formats (#1823) --- src/locale/bo.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/locale/bo.js b/src/locale/bo.js index 1e939b12c..df0c5e077 100644 --- a/src/locale/bo.js +++ b/src/locale/bo.js @@ -4,10 +4,10 @@ import dayjs from 'dayjs' const locale = { name: 'bo', weekdays: 'གཟའ་ཉི་མ་_གཟའ་ཟླ་བ་_གཟའ་མིག་དམར་_གཟའ་ལྷག་པ་_གཟའ་ཕུར་བུ_གཟའ་པ་སངས་_གཟའ་སྤེན་པ་'.split('_'), - months: 'ཟླ་བ་དང་པོ_ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), weekdaysShort: 'ཉི་མ་_ཟླ་བ་_མིག་དམར་_ལྷག་པ་_ཕུར་བུ_པ་སངས་_སྤེན་པ་'.split('_'), - monthsShort: 'ཟླ་བ་དང་པོ_ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), weekdaysMin: 'ཉི་མ་_ཟླ་བ་_མིག་དམར་_ལྷག་པ་_ཕུར་བུ_པ་སངས་_སྤེན་པ་'.split('_'), + months: 'ཟླ་བ་དང་པོ_ཟླ་བ་གཉིས་པ_ཟླ་བ་གསུམ་པ_ཟླ་བ་བཞི་པ_ཟླ་བ་ལྔ་པ_ཟླ་བ་དྲུག་པ_ཟླ་བ་བདུན་པ_ཟླ་བ་བརྒྱད་པ_ཟླ་བ་དགུ་པ_ཟླ་བ་བཅུ་པ_ཟླ་བ་བཅུ་གཅིག་པ_ཟླ་བ་བཅུ་གཉིས་པ'.split('_'), + monthsShort: 'ཟླ་དང་པོ_ཟླ་གཉིས་པ_ཟླ་གསུམ་པ_ཟླ་བཞི་པ_ཟླ་ལྔ་པ_ཟླ་དྲུག་པ_ཟླ་བདུན་པ_ཟླ་བརྒྱད་པ_ཟླ་དགུ་པ_ཟླ་བཅུ་པ_ཟླ་བཅུ་གཅིག་པ_ཟླ་བཅུ་གཉིས་པ'.split('_'), ordinal: n => n, formats: { LT: 'A h:mm', @@ -19,18 +19,18 @@ const locale = { }, relativeTime: { future: '%s ལ་', - past: '%s སྔན་ལ', - s: 'ལམ་སང', - m: 'སྐར་མ་གཅིག', - mm: '%d སྐར་མ', - h: 'ཆུ་ཚོད་གཅིག', - hh: '%d ཆུ་ཚོད', - d: 'ཉིན་གཅིག', - dd: '%d ཉིན་', - M: 'ཟླ་བ་གཅིག', - MM: '%d ཟླ་བ', - y: 'ལོ་གཅིག', - yy: '%d ལོ' + past: '%s སྔོན་ལ་', + s: 'ཏོག་ཙམ་', + m: 'སྐར་མ་གཅིག་', + mm: 'སྐར་མ་ %d', + h: 'ཆུ་ཚོད་གཅིག་', + hh: 'ཆུ་ཚོད་ %d', + d: 'ཉིན་གཅིག་', + dd: 'ཉིན་ %d', + M: 'ཟླ་བ་གཅིག་', + MM: 'ཟླ་བ་ %d', + y: 'ལོ་གཅིག་', + yy: 'ལོ་ %d' } } From a597d0b1b8dd28e626f8c59d326622088f7b51e7 Mon Sep 17 00:00:00 2001 From: Akam Foad <41629832+akamfoad@users.noreply.github.com> Date: Fri, 15 Apr 2022 06:12:23 +0300 Subject: [PATCH 8/8] fix: update Kurdish [ku] locale strings and formatted output contains non-standard kurdish characters (#1848) --- src/locale/ku.js | 80 ++++++++++++++++++++++++++++++++++-------- test/locale/ku.test.js | 22 ++++++++++-- 2 files changed, 85 insertions(+), 17 deletions(-) diff --git a/src/locale/ku.js b/src/locale/ku.js index 07a6b2f16..1d7a449d8 100644 --- a/src/locale/ku.js +++ b/src/locale/ku.js @@ -1,14 +1,65 @@ // Kurdish [ku] import dayjs from 'dayjs' +export const englishToArabicNumbersMap = { + 1: '١', + 2: '٢', + 3: '٣', + 4: '٤', + 5: '٥', + 6: '٦', + 7: '٧', + 8: '٨', + 9: '٩', + 0: '٠' +} + +const arabicToEnglishNumbersMap = { + '١': '1', + '٢': '2', + '٣': '3', + '٤': '4', + '٥': '5', + '٦': '6', + '٧': '7', + '٨': '8', + '٩': '9', + '٠': '0' +} + +const months = [ + 'کانوونی دووەم', + 'شوبات', + 'ئادار', + 'نیسان', + 'ئایار', + 'حوزەیران', + 'تەممووز', + 'ئاب', + 'ئەیلوول', + 'تشرینی یەکەم', + 'تشرینی دووەم', + 'کانوونی یەکەم' +] + const locale = { name: 'ku', - weekdays: 'یه‌كشه‌ممه‌_دووشه‌ممه‌_سێشه‌ممه‌_چوارشه‌ممه‌_پێنجشه‌ممه‌_هه‌ینی_شه‌ممه‌'.split('_'), - months: 'کانونی دووەم_شوبات_ئازار_نیسان_ئایار_حوزەیران_تەمموز_ئاب_ئەیلوول_تشرینی یەكەم_تشرینی دووەم_كانونی یەکەم'.split('_'), + months, + monthsShort: months, + weekdays: 'یەکشەممە_دووشەممە_سێشەممە_چوارشەممە_پێنجشەممە_هەینی_شەممە'.split('_'), + weekdaysShort: 'یەکشەم_دووشەم_سێشەم_چوارشەم_پێنجشەم_هەینی_شەممە'.split('_'), weekStart: 6, - weekdaysShort: 'یه‌كشه‌م_دووشه‌م_سێشه‌م_چوارشه‌م_پێنجشه‌م_هه‌ینی_شه‌ممه‌'.split('_'), - monthsShort: 'کانونی دووەم_شوبات_ئازار_نیسان_ئایار_حوزەیران_تەمموز_ئاب_ئەیلوول_تشرینی یەكەم_تشرینی دووەم_كانونی یەکەم'.split('_'), - weekdaysMin: 'ی_د_س_چ_پ_ه_ش'.split('_'), + weekdaysMin: 'ی_د_س_چ_پ_هـ_ش'.split('_'), + preparse(string) { + return string + .replace(/[١٢٣٤٥٦٧٨٩٠]/g, match => arabicToEnglishNumbersMap[match]) + .replace(/،/g, ',') + }, + postformat(string) { + return string + .replace(/\d/g, match => englishToArabicNumbersMap[match]) + .replace(/,/g, '،') + }, ordinal: n => n, formats: { LT: 'HH:mm', @@ -20,18 +71,18 @@ const locale = { }, meridiem: hour => (hour < 12 ? 'پ.ن' : 'د.ن'), relativeTime: { - future: 'له‌ %s', + future: 'لە %s', past: '%s', - s: 'چه‌ند چركه‌یه‌ك', - m: 'یه‌ك خوله‌ك', - mm: '%d خوله‌ك', - h: 'یه‌ك كاتژمێر', - hh: '%d كاتژمێر', - d: 'یه‌ك ڕۆژ', + s: 'چەند چرکەیەک', + m: 'یەک خولەک', + mm: '%d خولەک', + h: 'یەک کاتژمێر', + hh: '%d کاتژمێر', + d: 'یەک ڕۆژ', dd: '%d ڕۆژ', - M: 'یه‌ك مانگ', + M: 'یەک مانگ', MM: '%d مانگ', - y: 'یه‌ك ساڵ', + y: 'یەک ساڵ', yy: '%d ساڵ' } } @@ -39,4 +90,3 @@ const locale = { dayjs.locale(locale, null, true) export default locale - diff --git a/test/locale/ku.test.js b/test/locale/ku.test.js index d3dec4c28..7ceb5424d 100644 --- a/test/locale/ku.test.js +++ b/test/locale/ku.test.js @@ -1,6 +1,10 @@ +import moment from 'moment' import MockDate from 'mockdate' import dayjs from '../../src' -import '../../src/locale/ku' +import locale, { englishToArabicNumbersMap } from '../../src/locale/ku' +import preParsePostFormat from '../../src/plugin/preParsePostFormat' + +dayjs.extend(preParsePostFormat) beforeEach(() => { MockDate.set(new Date()) @@ -15,6 +19,20 @@ it('Format meridiem correctly', () => { const dayjsKu = dayjs() .startOf('day') .add(i, 'hour') - expect(dayjsKu.locale('ku').format('h A')).toBe(`${i % 12 || 12} ${i < 12 ? 'پ.ن' : 'د.ن'}`) + const hour = (i % 12 || 12) + .toString() + .replace(/\d/g, match => englishToArabicNumbersMap[match]) + const m = i < 12 ? 'پ.ن' : 'د.ن' + expect(dayjsKu.locale('ku').format('h A')).toBe(`${hour} ${m}`) + } +}) + +it('Preparse with locale function', () => { + for (let i = 0; i <= 7; i += 1) { + dayjs.locale(locale) + const momentKu = moment() + .locale('ku') + .add(i, 'day') + expect(dayjs(momentKu.format()).format()).toEqual(momentKu.format()) } })