From: Manfre98 <18686229+Manfre98@users.noreply.github.com> Date: Sat, 20 Oct 2018 17:49:31 +0000 (+0200) Subject: [locale] it: Improve relative time X-Git-Tag: 2.25.0~23^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3cdb879e645c45be2713240f503d6b37789525dc;p=thirdparty%2Fmoment.git [locale] it: Improve relative time --- diff --git a/src/locale/it.js b/src/locale/it.js index fccce151c..dc1e7580f 100644 --- a/src/locale/it.js +++ b/src/locale/it.js @@ -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'; @@ -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', diff --git a/src/test/locale/it.js b/src/test/locale/it.js index cefa073d0..aa45ce08d 100644 --- a/src/test/locale/it.js +++ b/src/test/locale/it.js @@ -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', @@ -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' ); } @@ -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),