Bug 1444480 - Omit timezone in some timestamps. r=florian
authorMartin Giger <martin@humanoids.be>
Fri, 09 Mar 2018 19:54:02 +0100
changeset 31274 3cc1812a10b418c8aac85feb001e332cb56892c9
parent 31273 56248d8b301e719523527385d279bd860b5432ed
child 31275 044240bd35e00b5c202b97d37ba532ef5f23d309
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersflorian
bugs1444480
Bug 1444480 - Omit timezone in some timestamps. r=florian
chat/content/imtooltip.xml
chat/modules/ToLocaleFormat.jsm
chat/modules/imThemes.jsm
--- a/chat/content/imtooltip.xml
+++ b/chat/content/imtooltip.xml
@@ -483,23 +483,23 @@
          for (let node = elt; node; node = node.parentNode) {
            if (!node._originalMsg)
              continue;
            // It's a message, so add a date/time tooltip.
            let date = new Date(node._originalMsg.time * 1000);
            let text;
            if ((new Date()).toDateString() == date.toDateString()) {
              const dateTimeFormatter = new Services.intl.DateTimeFormat(undefined, {
-               timeStyle: "long"
+               timeStyle: "medium"
              });
              text = dateTimeFormatter.format(date);
            }
            else {
              const dateTimeFormatter = new Services.intl.DateTimeFormat(undefined, {
-               dateStyle: "short", timeStyle: "long"
+               dateStyle: "short", timeStyle: "medium"
              });
              text = dateTimeFormatter.format(date);
            }
            // Setting the attribute on this node means that if the element
            // we are pointing at carries a title set by the prpl,
            // that title won't be overridden.
            node.setAttribute("title", text);
            break;
--- a/chat/modules/ToLocaleFormat.jsm
+++ b/chat/modules/ToLocaleFormat.jsm
@@ -18,28 +18,28 @@ function ToLocaleFormat(aFormat, aDate) 
            Math.floor((y - 1969) / 4) -
            Math.floor((y - 1901) / 100) +
            Math.floor((y - 1601) / 400);
   }
   function DayWithinYear(t) {
     return Day(t) - DayFromYear(t.getFullYear());
   }
   function weekday(option) {
-    return aDate.toLocaleString(locale, {weekday: option});
+    return aDate.toLocaleString(undefined, {weekday: option});
   }
   function month(option) {
-    return aDate.toLocaleString(locale, {month: option});
+    return aDate.toLocaleString(undefined, {month: option});
   }
   function hourMinSecTwoDigits() {
-    return aDate.toLocaleString(locale, {
+    return aDate.toLocaleString(undefined, {
       hour: "2-digit", minute: "2-digit", second: "2-digit"
     });
   }
   function dayPeriod() {
-    let dtf = Intl.Dateformat(locale, {hour: "2-digit"});
+    let dtf = Intl.DateTimeFormat(undefined, {hour: "2-digit"});
     let dayPeriodPart =
       dtf.resolvedOptions().hour12 &&
       dtf.formatToParts(aDate).find(part => part.type === "dayPeriod");
     return dayPeriodPart ? dayPeriodPart.value : "";
   }
   function weekNumber(weekStart, t = aDate) {
     let day = t.getDay();
     if (weekStart) {
@@ -71,17 +71,17 @@ function ToLocaleFormat(aFormat, aDate) 
   }
   function timeZoneOffset() {
     let offset = aDate.getTimezoneOffset();
     let tzoff =
       Math.floor(Math.abs(offset) / 60) * 100 + Math.abs(offset) % 60;
     return (offset < 0 ? "+" : "-") + String(tzoff).padStart(4, "0");
   }
   function timeZone() {
-    let dtf = Intl.DateTimeFormat("en-US", {timeZoneName: "short"});
+    let dtf = Intl.DateTimeFormat(undefined, {timeZoneName: "short"});
     let timeZoneNamePart = dtf.formatToParts(aDate)
                               .find(part => part.type === "timeZoneName");
     return timeZoneNamePart ? timeZoneNamePart.value : "";
   }
 
   let dateTimeFormatter = new Services.intl.DateTimeFormat(undefined, {
     dateStyle: "full", timeStyle: "long"
   });
--- a/chat/modules/imThemes.jsm
+++ b/chat/modules/imThemes.jsm
@@ -34,16 +34,24 @@ XPCOMUtils.defineLazyGetter(this, "gPref
   Services.prefs.getBranch(kMessagesStylePrefBranch)
 );
 
 XPCOMUtils.defineLazyGetter(this, "TXTToHTML", function() {
   let cs = Cc["@mozilla.org/txttohtmlconv;1"].getService(Ci.mozITXTToHTMLConv);
   return aTXT => cs.scanTXT(aTXT, cs.kEntities);
 });
 
+XPCOMUtils.defineLazyGetter(this, "gTimeFormatter", () => {
+  return new Services.intl.DateTimeFormat(undefined, {
+    hour: "2-digit",
+    minute: "2-digit",
+    second: "2-digit"
+  });
+});
+
 ChromeUtils.defineModuleGetter(this,
   "ToLocaleFormat", "resource:///modules/ToLocaleFormat.jsm");
 
 var gCurrentTheme = null;
 
 function getChromeFile(aURI)
 {
   try {
@@ -335,20 +343,17 @@ var headerFooterReplacements = {
     return (!aConv.isChat && (buddy = aConv.buddy) &&
             buddy.buddyIconFilename) || "incoming_icon.png";
   },
   outgoingIconPath: aConv => "outgoing_icon.png",
   timeOpened: function(aConv, aFormat) {
     let date = new Date(aConv.startDate / 1000);
     if (aFormat)
       return ToLocaleFormat(aFormat, date);
-    const timeFormatter = new Services.intl.DateTimeFormat(undefined, {
-      timeStyle: "long"
-    });
-    return timeFormatter.format(date);
+    return gTimeFormatter.format(date);
   }
 };
 
 function formatAutoResponce(aTxt) {
   return Services.strings
                  .createBundle("chrome://chat/locale/conversations.properties")
                  .formatStringFromName("autoReply", [aTxt], 1);
 }
@@ -356,27 +361,21 @@ function formatAutoResponce(aTxt) {
 var statusMessageReplacements = {
   message: aMsg => "<span class=\"ib-msg-txt\">" +
                    (aMsg.autoResponse ? formatAutoResponce(aMsg.message) : aMsg.message) +
                    "</span>",
   time: function(aMsg, aFormat) {
     let date = new Date(aMsg.time * 1000);
     if (aFormat)
       return ToLocaleFormat(aFormat, date);
-    const timeFormatter = new Services.intl.DateTimeFormat(undefined, {
-      timeStyle: "long"
-    });
-    return timeFormatter.format(date);
+    return gTimeFormatter.format(date);
   },
   timestamp: aMsg => aMsg.time,
   shortTime: function(aMsg) {
-    const timeFormatter = new Services.intl.DateTimeFormat(undefined, {
-      timeStyle: "long"
-    });
-    return timeFormatter.format(new Date(aMsg.time * 1000));
+    return gTimeFormatter.format(new Date(aMsg.time * 1000));
   },
   messageClasses: function(aMsg) {
     let msgClass = [];
 
     if (aMsg.system)
       msgClass.push("event");
     else {
       msgClass.push("message");