Skip to content

Commit 8e6d11d

Browse files
authored
fix: update Italian (Switzerland) [it-ch] locale relativeTime (#1829)
1 parent 4e2802c commit 8e6d11d

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

src/locale/it-ch.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ const locale = {
1717
LL: 'D MMMM YYYY',
1818
LLL: 'D MMMM YYYY HH:mm',
1919
LLLL: 'dddd D MMMM YYYY HH:mm'
20+
},
21+
relativeTime: {
22+
future: 'tra %s',
23+
past: '%s fa',
24+
s: 'alcuni secondi',
25+
m: 'un minuto',
26+
mm: '%d minuti',
27+
h: 'un\'ora',
28+
hh: '%d ore',
29+
d: 'un giorno',
30+
dd: '%d giorni',
31+
M: 'un mese',
32+
MM: '%d mesi',
33+
y: 'un anno',
34+
yy: '%d anni'
2035
}
2136
}
2237

test/locale/it-ch.test.js

Lines changed: 71 additions & 0 deletions
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 '../../src/locale/it-ch'
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 in Switzerland', () => {
12+
beforeEach(() => {
13+
dayjs.locale('it-ch')
14+
moment.locale('it-ch')
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+
[44.4, 'second'], // a few seconds
44+
[89.5, 'second'], // a minute
45+
[2, 'minute'], // 2 minutes
46+
[5, 'minute'], // 5 minutes
47+
[43, 'minute'], // 44 minutes
48+
[45, 'minute'], // an hour
49+
[3, 'hour'], // 3 hours
50+
[21, 'hour'], // 21 hours
51+
[1, 'day'], // a day
52+
[3, 'day'], // 3 day
53+
[25, 'day'], // 25 days
54+
[1, 'month'], // a month
55+
[2, 'month'], // 2 month
56+
[10, 'month'], // 10 month
57+
[1, 'year'], // a year
58+
[2, 'year'], // 2 year
59+
[5, 'year'], // 5 year
60+
[18, 'month'] // 2 years
61+
]
62+
63+
64+
T.forEach((t) => {
65+
expect(dayjs().from(dayjs().add(t[0], t[1])))
66+
.toBe(moment().from(moment().add(t[0], t[1])))
67+
expect(dayjs().from(dayjs().add(t[0], t[1]), true))
68+
.toBe(moment().from(moment().add(t[0], t[1]), true))
69+
})
70+
})
71+
})

0 commit comments

Comments
 (0)