]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[locale] it: Improve relative time
authorManfre98 <18686229+Manfre98@users.noreply.github.com>
Sat, 20 Oct 2018 17:49:31 +0000 (19:49 +0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 27 Apr 2020 16:23:21 +0000 (19:23 +0300)
src/locale/it.js
src/test/locale/it.js

index fccce151c1c6cec8ac02af51f34d280fb87c6201..dc1e7580f993eb8886836fd7b92924e9409db29b 100644 (file)
@@ -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',
index cefa073d0bb52d59121ee1940ba614a994e22533..aa45ce08d25c0fd1044e6409e74d2c90f65c94c8 100644 (file)
@@ -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),