[gnome-shell] telepathyClient: Do a better job with old chat timestamps



commit b470736246301f6f576de59631883661b3d3424d
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Mon Mar 28 16:37:53 2011 -0400

    telepathyClient: Do a better job with old chat timestamps
    
    If we have a date that's not within the last week, it's really
    confusing to display it as "Sent at 9:23 on Tuesday". Steal
    some strings from calendar.js for displaying older dates to
    avoid a string-freeze break.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=645609

 js/ui/telepathyClient.js |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js
index 675181a..cc653e7 100644
--- a/js/ui/telepathyClient.js
+++ b/js/ui/telepathyClient.js
@@ -11,6 +11,7 @@ const Tpl = imports.gi.TelepathyLogger;
 const Tp = imports.gi.TelepathyGLib;
 const Gettext = imports.gettext.domain('gnome-shell');
 const _ = Gettext.gettext;
+const C_ = Gettext.pgettext;
 
 const History = imports.misc.history;
 const Main = imports.ui.main;
@@ -465,15 +466,39 @@ Notification.prototype = {
         }
     },
 
+    _formatTimestamp: function(date) {
+        let now = new Date();
+
+        var daysAgo = (now.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
+
+        // Show a week day and time if date is in the last week
+        if (daysAgo < 1 || (daysAgo < 7 && now.getDay() != date.getDay())) {
+            /* Translators: this is a time format string followed by a date.
+             If applicable, replace %X with a strftime format valid for your
+             locale, without seconds. */
+            // xgettext:no-c-format
+            format = _("Sent at %X on %A");
+
+        // FIXME: The next two are stolen from calendar.js with the comment to avoid
+        // a string-freeze break. They should be replaced with better strings
+        // with 'Sent at', appropriate context and appropriate translator comment.
+
+        } else if (date.getYear() == now.getYear()) {
+            /* Translators: Shown on calendar heading when selected day occurs on current year */
+            format = C_("calendar heading", "%A, %B %d");
+        } else {
+            /* Translators: Shown on calendar heading when selected day occurs on different year */
+            format = C_("calendar heading", "%A, %B %d, %Y");
+        }
+
+        return date.toLocaleFormat(format);
+    },
+
     appendTimestamp: function() {
         let lastMessageTime = this._history[0].time;
         let lastMessageDate = new Date(lastMessageTime * 1000);
 
-        /* Translators: this is a time format string followed by a date.
-           If applicable, replace %X with a strftime format valid for your
-           locale, without seconds. */
-        // xgettext:no-c-format
-        let timeLabel = this.addBody(lastMessageDate.toLocaleFormat(_("Sent at %X on %A")), false, { expand: true, x_fill: false, x_align: St.Align.END });
+        let timeLabel = this.addBody(this._formatTimestamp(lastMessageDate), false, { expand: true, x_fill: false, x_align: St.Align.END });
         timeLabel.add_style_class_name('chat-meta-message');
         this._history.unshift({ actor: timeLabel, time: lastMessageTime, realMessage: false });
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]