Bug 1301655 - pt 2 - Replace use of nsIScriptableDateFormat with Intl.DateTimeFormat in FeedWriter.js. r=gandalf
authorJonathan Kew <jkew@mozilla.com>
Fri, 28 Oct 2016 12:04:06 +0100
changeset 319990 625ba7fc4b96abe8474f5f478b39692e72dd1233
parent 319989 cd3bd7aa413d765587d94db7a6fc8b10c4008af6
child 319991 68543a46ef49fb7309c345179c87912b8d75e41b
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgandalf
bugs1301655
milestone52.0a1
Bug 1301655 - pt 2 - Replace use of nsIScriptableDateFormat with Intl.DateTimeFormat in FeedWriter.js. r=gandalf
browser/components/feeds/FeedWriter.js
--- a/browser/components/feeds/FeedWriter.js
+++ b/browser/components/feeds/FeedWriter.js
@@ -257,21 +257,30 @@ FeedWriter.prototype = {
   _parseDate(dateString) {
     // Convert the date into the user's local time zone
     let dateObj = new Date(dateString);
 
     // Make sure the date we're given is valid.
     if (!dateObj.getTime())
       return false;
 
-    let dateService = Cc["@mozilla.org/intl/scriptabledateformat;1"].
-                      getService(Ci.nsIScriptableDateFormat);
-    return dateService.FormatDateTime("", dateService.dateFormatLong, dateService.timeFormatNoSeconds,
-                                      dateObj.getFullYear(), dateObj.getMonth()+1, dateObj.getDate(),
-                                      dateObj.getHours(), dateObj.getMinutes(), dateObj.getSeconds());
+    return this._dateFormatter.format(dateObj);
+  },
+
+  __dateFormatter: null,
+  get _dateFormatter() {
+    if (!this.__dateFormatter) {
+      const locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
+                     .getService(Ci.nsIXULChromeRegistry)
+                     .getSelectedLocale("global", true);
+      const dtOptions = { year: 'numeric', month: 'long', day: 'numeric',
+                          hour: 'numeric', minute: 'numeric' };
+      this.__dateFormatter = new Intl.DateTimeFormat(locale, dtOptions);
+    }
+    return this.__dateFormatter;
   },
 
   /**
    * Returns the feed type.
    */
   __feedType: null,
   _getFeedType() {
     if (this.__feedType != null)