Skip to content

Commit 9e9f76c

Browse files
authored
fix: replace italian locale "un' ora fa" with "un'ora fa", add tests for it (#2930)
1 parent 1b0989a commit 9e9f76c

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/locale/it.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const locale = {
2323
s: 'qualche secondo',
2424
m: 'un minuto',
2525
mm: '%d minuti',
26-
h: 'un\' ora',
26+
h: 'un\'ora',
2727
hh: '%d ore',
2828
d: 'un giorno',
2929
dd: '%d giorni',

test/locale/it.test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import moment from 'moment'
2+
import MockDate from 'mockdate'
3+
import dayjs from '../../src'
4+
import '../../src/locale/it'
5+
import relativeTime from '../../src/plugin/relativeTime'
6+
import localizedFormat from '../../src/plugin/localizedFormat'
7+
8+
dayjs.extend(relativeTime)
9+
dayjs.extend(localizedFormat)
10+
11+
describe('Italian formats', () => {
12+
beforeEach(() => {
13+
dayjs.locale('it')
14+
moment.locale('it')
15+
16+
MockDate.set(new Date())
17+
})
18+
19+
afterEach(() => {
20+
MockDate.reset()
21+
})
22+
23+
24+
it('Format month with locale function', () => {
25+
for (let i = 0; i <= 7; i += 1) {
26+
const dayjsWithLocale = dayjs().add(i, 'day')
27+
const momentWithLocale = moment().add(i, 'day')
28+
const testFormat1 = 'DD MMMM YYYY MMM'
29+
const testFormat2 = 'dddd, MMMM D YYYY'
30+
const testFormat3 = 'MMMM'
31+
const testFormat4 = 'MMM'
32+
const testFormat5 = 'L'
33+
expect(dayjsWithLocale.format(testFormat1)).toEqual(momentWithLocale.format(testFormat1))
34+
expect(dayjsWithLocale.format(testFormat2)).toEqual(momentWithLocale.format(testFormat2))
35+
expect(dayjsWithLocale.format(testFormat3)).toEqual(momentWithLocale.format(testFormat3))
36+
expect(dayjsWithLocale.format(testFormat4)).toEqual(momentWithLocale.format(testFormat4))
37+
expect(dayjsWithLocale.format(testFormat5)).toEqual(momentWithLocale.format(testFormat5))
38+
}
39+
})
40+
41+
it('RelativeTime: Time from X', () => {
42+
const T = [
43+
[89.5, 'second'], // a minute
44+
[2, 'minute'], // 2 minutes
45+
[5, 'minute'], // 5 minutes
46+
[43, 'minute'], // 44 minutes
47+
[45, 'minute'], // an hour
48+
[3, 'hour'], // 3 hours
49+
[21, 'hour'], // 21 hours
50+
[1, 'day'], // a day
51+
[3, 'day'], // 3 day
52+
[25, 'day'], // 25 days
53+
[1, 'month'], // a month
54+
[2, 'month'], // 2 month
55+
[10, 'month'], // 10 month
56+
[1, 'year'], // a year
57+
[2, 'year'], // 2 year
58+
[5, 'year'], // 5 year
59+
[18, 'month'] // 2 years
60+
]
61+
62+
63+
T.forEach((t) => {
64+
expect(dayjs().from(dayjs().add(t[0], t[1])))
65+
.toBe(moment().from(moment().add(t[0], t[1])))
66+
expect(dayjs().from(dayjs().add(t[0], t[1]), true))
67+
.toBe(moment().from(moment().add(t[0], t[1]), true))
68+
})
69+
})
70+
71+
// moment.js uses `alcuni secondi` while dayjs uses `qualche secondo`.
72+
it('RelativeTime: A few seconds', () => {
73+
const T = [
74+
[44.4, 'second'] // a few seconds
75+
]
76+
77+
T.forEach((t) => {
78+
expect(dayjs().from(dayjs().add(t[0], t[1])))
79+
.toBe('qualche secondo fa')
80+
expect(dayjs().from(dayjs().add(t[0], t[1]), true))
81+
.toBe('qualche secondo')
82+
})
83+
})
84+
})

0 commit comments

Comments
 (0)