Skip to content

Commit

Permalink
Merge pull request #4825 from Manfre98:develop
Browse files Browse the repository at this point in the history
[locale] it: Improve relative time
  • Loading branch information
ichernev committed Apr 27, 2020
2 parents 144e394 + 3cdb879 commit b162aee
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 11 deletions.
53 changes: 47 additions & 6 deletions src/locale/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! locale : Italian [it]
//! author : Lorenzo : https://github.com/aliem
//! author: Mattia Larentis: https://github.com/nostalgiaz
//! author: Marco : https://github.com/Manfre98

import moment from '../moment';

Expand All @@ -24,16 +25,56 @@ export default moment.defineLocale('it', {
LLLL: 'dddd D MMMM YYYY HH:mm',
},
calendar: {
sameDay: '[Oggi alle] LT',
nextDay: '[Domani alle] LT',
nextWeek: 'dddd [alle] LT',
lastDay: '[Ieri alle] LT',
sameDay: function () {
return (
'[Oggi a' +
(this.hours() > 1 ? 'lle ' : this.hours() === 0 ? ' ' : "ll'") +
']LT'
);
},
nextDay: function () {
return (
'[Domani a' +
(this.hours() > 1 ? 'lle ' : this.hours() === 0 ? ' ' : "ll'") +
']LT'
);
},
nextWeek: function () {
return (
'dddd [a' +
(this.hours() > 1 ? 'lle ' : this.hours() === 0 ? ' ' : "ll'") +
']LT'
);
},
lastDay: function () {
return (
'[Ieri a' +
(this.hours() > 1 ? 'lle ' : this.hours() === 0 ? ' ' : "ll'") +
']LT'
);
},
lastWeek: function () {
switch (this.day()) {
case 0:
return '[la scorsa] dddd [alle] LT';
return (
'[La scorsa] dddd [a' +
(this.hours() > 1
? 'lle '
: this.hours() === 0
? ' '
: "ll'") +
']LT'
);
default:
return '[lo scorso] dddd [alle] LT';
return (
'[Lo scorso] dddd [a' +
(this.hours() > 1
? 'lle '
: this.hours() === 0
? ' '
: "ll'") +
']LT'
);
}
},
sameElse: 'L',
Expand Down
47 changes: 42 additions & 5 deletions src/test/locale/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ test('calendar day', function (assert) {
'Domani alle 12:00',
'tomorrow at the same time'
);
assert.equal(
moment(a).add({ d: 1, h: -1 }).calendar(),
'Domani alle 11:00',
'tomorrow minus 1 hour'
);
assert.equal(
moment(a).subtract({ h: 1 }).calendar(),
'Oggi alle 11:00',
Expand All @@ -343,19 +348,31 @@ test('calendar next week', function (assert) {
m = moment().add({ d: i });
assert.equal(
m.calendar(),
m.format('dddd [alle] LT'),
m.format(
'dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT'
),
'Today + ' + i + ' days current time'
);
m.hours(0).minutes(0).seconds(0).milliseconds(0);
assert.equal(
m.calendar(),
m.format('dddd [alle] LT'),
m.format(
'dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT'
),
'Today + ' + i + ' days beginning of day'
);
m.hours(23).minutes(59).seconds(59).milliseconds(999);
assert.equal(
m.calendar(),
m.format('dddd [alle] LT'),
m.format(
'dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT'
),
'Today + ' + i + ' days end of day'
);
}
Expand All @@ -369,20 +386,40 @@ test('calendar last week', function (assert) {
weekday = parseInt(m.format('d'), 10);
datestring =
weekday === 0
? '[la scorsa] dddd [alle] LT'
: '[lo scorso] dddd [alle] LT';
? '[La scorsa] dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT'
: '[Lo scorso] dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT';
assert.equal(
m.calendar(),
m.format(datestring),
'Today - ' + i + ' days current time'
);
m.hours(0).minutes(0).seconds(0).milliseconds(0);
datestring =
weekday === 0
? '[La scorsa] dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT'
: '[Lo scorso] dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT';
assert.equal(
m.calendar(),
m.format(datestring),
'Today - ' + i + ' days beginning of day'
);
m.hours(23).minutes(59).seconds(59).milliseconds(999);
datestring =
weekday === 0
? '[La scorsa] dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT'
: '[Lo scorso] dddd [a' +
(m.hours() > 1 ? 'lle ' : m.hours() === 0 ? ' ' : "ll'") +
']LT';
assert.equal(
m.calendar(),
m.format(datestring),
Expand Down

0 comments on commit b162aee

Please sign in to comment.