Skip to content

Commit 02d96ec

Browse files
fix: Update Bengali [bn] locale (#1329)
1 parent 8e995e9 commit 02d96ec

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

src/locale/bn.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
// Bengali [bn]
22
import dayjs from 'dayjs'
33

4+
const symbolMap = {
5+
1: '১',
6+
2: '২',
7+
3: '৩',
8+
4: '৪',
9+
5: '৫',
10+
6: '৬',
11+
7: '৭',
12+
8: '৮',
13+
9: '৯',
14+
0: '০'
15+
}
16+
17+
const numberMap = {
18+
'১': '1',
19+
'২': '2',
20+
'৩': '3',
21+
'৪': '4',
22+
'৫': '5',
23+
'৬': '6',
24+
'৭': '7',
25+
'৮': '8',
26+
'৯': '9',
27+
'০': '0'
28+
}
29+
430
const locale = {
531
name: 'bn',
632
weekdays: 'রবিবার_সোমবার_মঙ্গলবার_বুধবার_বৃহস্পতিবার_শুক্রবার_শনিবার'.split('_'),
7-
months: 'জানুয়ারী_ফেব্রুয়ারি_মার্চ_এপ্রিল_মে_জুন_জুলাই_আগস্ট_সেপ্টেম্বর_অক্টোবর_নভেম্বর_ডিসেম্বর'.split('_'),
33+
months: 'জানুয়ারি_ফেব্রুয়ারি_মার্চ_এপ্রিল_মে_জুন_জুলাই_আগস্ট_সেপ্টেম্বর_অক্টোবর_নভেম্বর_ডিসেম্বর'.split('_'),
834
weekdaysShort: 'রবি_সোম_মঙ্গল_বুধ_বৃহস্পতি_শুক্র_শনি'.split('_'),
935
monthsShort: 'জানু_ফেব_মার্চ_এপ্র_মে_জুন_জুল_আগ_সেপ্ট_অক্টো_নভে_ডিসে'.split('_'),
1036
weekdaysMin: 'রবি_সোম_মঙ্গ_বুধ_বৃহঃ_শুক্র_শনি'.split('_'),
37+
preparse(string) {
38+
return string.replace(/[]/g, match => numberMap[match])
39+
},
40+
postformat(string) {
41+
return string.replace(/\d/g, match => symbolMap[match])
42+
},
1143
ordinal: n => n,
1244
formats: {
1345
LT: 'A h:mm সময়',
@@ -37,4 +69,3 @@ const locale = {
3769
dayjs.locale(locale, null, true)
3870

3971
export default locale
40-

test/locale/bn.test.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import moment from 'moment'
2+
import MockDate from 'mockdate'
3+
import dayjs from '../../src'
4+
import relativeTime from '../../src/plugin/relativeTime'
5+
import localeData from '../../src/plugin/localeData'
6+
import preParsePostFormat from '../../src/plugin/preParsePostFormat'
7+
import '../../src/locale/bn'
8+
9+
dayjs.extend(localeData)
10+
dayjs.extend(relativeTime)
11+
dayjs.extend(preParsePostFormat)
12+
13+
beforeEach(() => {
14+
MockDate.set(new Date())
15+
})
16+
17+
afterEach(() => {
18+
MockDate.reset()
19+
})
20+
21+
it('Format Month with locale function', () => {
22+
for (let i = 0; i <= 7; i += 1) {
23+
const dayjsBN = dayjs()
24+
.locale('bn')
25+
.add(i, 'day')
26+
const momentBN = moment()
27+
.locale('bn')
28+
.add(i, 'day')
29+
const testFormat1 = 'DD MMMM YYYY MMM'
30+
const testFormat2 = 'MMMM'
31+
const testFormat3 = 'MMM'
32+
expect(dayjsBN.format(testFormat1)).toEqual(momentBN.format(testFormat1))
33+
expect(dayjsBN.format(testFormat2)).toEqual(momentBN.format(testFormat2))
34+
expect(dayjsBN.format(testFormat3)).toEqual(momentBN.format(testFormat3))
35+
}
36+
})
37+
38+
it('Preparse with locale function', () => {
39+
for (let i = 0; i <= 7; i += 1) {
40+
dayjs.locale('bn')
41+
const momentBN = moment()
42+
.locale('bn')
43+
.add(i, 'day')
44+
expect(dayjs(momentBN.format()).format()).toEqual(momentBN.format())
45+
}
46+
})
47+
48+
it('RelativeTime: Time from X', () => {
49+
const T = [
50+
[44.4, 'second'], // a few seconds
51+
[89.5, 'second'], // a minute
52+
[130, 'second'], // two minutes
53+
[43, 'minute'], // 44 minutes
54+
[1, 'hour'], // 1 hour
55+
[21, 'hour'], // 21 hours
56+
[2, 'day'], // 2 days
57+
[25, 'day'], // 25 days
58+
[2, 'month'], // 2 months
59+
[10, 'month'], // 10 months
60+
[18, 'month'], // 2 years
61+
[15, 'year'] // 15 years
62+
]
63+
64+
T.forEach((t) => {
65+
dayjs.locale('bn')
66+
moment.locale('bn')
67+
expect(dayjs().from(dayjs().add(t[0], t[1]))).toBe(moment().from(moment().add(t[0], t[1])))
68+
expect(dayjs().from(dayjs().add(t[0], t[1]), true))
69+
.toBe(moment().from(moment().add(t[0], t[1]), true))
70+
})
71+
})

0 commit comments

Comments
 (0)