Bug 1360915 - Restore datetime formatting to be sensitive to OS regional setting by using mozIntl. r=MakeMyDay
authorJavi Rueda <foss@franjaru.com>
Sun, 21 May 2017 22:59:11 +0200
changeset 28419 f0f85441cb740327b5dac5ac74a63330a90d3234
parent 28418 8635ff1796b88bfdfaa9c72a576bd6778f239125
child 28420 9aad32d14d945e0e89c43cff9fef9d67b11f9dd0
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMakeMyDay
bugs1360915
Bug 1360915 - Restore datetime formatting to be sensitive to OS regional setting by using mozIntl. r=MakeMyDay
calendar/base/src/calDateTimeFormatter.js
--- a/calendar/base/src/calDateTimeFormatter.js
+++ b/calendar/base/src/calDateTimeFormatter.js
@@ -25,37 +25,34 @@ calDateTimeFormatter.prototype = {
 
     formatDate: function(aDate) {
         // Format the date using user's format preference (long or short)
         let format = Preferences.get("calendar.date.format", 0);
         return (format == 0 ? this.formatDateLong(aDate) : this.formatDateShort(aDate));
     },
 
     formatDateShort: function(aDate) {
-        let dtOptions = { year: 'numeric', month: '2-digit', day: '2-digit' };
-        return this._inTimezone(aDate, dtOptions);
+        return this._inTimezone(aDate, { dateStyle: "short" });
     },
 
     formatDateLong: function(aDate) {
-        let dtOptions = { weekday: 'long', year: 'numeric', month: 'long', day: '2-digit' };
-        return this._inTimezone(aDate, dtOptions);
+        return this._inTimezone(aDate, { dateStyle: "full" });
     },
 
     formatDateWithoutYear: function(aDate) {
         let dtOptions = { month: 'short', day: 'numeric' };
         return this._inTimezone(aDate, dtOptions);
     },
 
     formatTime: function(aDate) {
         if (aDate.isDate) {
             return this.mDateStringBundle.GetStringFromName("AllDay");
         }
 
-        let timeOptions = { hour: 'numeric', minute: '2-digit' };
-        return this._inTimezone(aDate, timeOptions);
+        return this._inTimezone(aDate, { timeStyle: "short" });
     },
 
     formatDateTime: function(aDate) {
         let formattedDate = this.formatDate(aDate);
         let formattedTime = this.formatTime(aDate);
 
         let timeBeforeDate = Preferences.get("calendar.date.formatTimeBeforeDate", false);
         if (timeBeforeDate) {
@@ -74,17 +71,18 @@ calDateTimeFormatter.prototype = {
      */
     _inTimezone: function(aDate, aOptions) {
         let timezone = aDate.timezone;
         // we set the tz only if we have a valid tz - otherwise localtime will be used on formatting.
         if (timezone && (timezone.isUTC || timezone.icalComponent)) {
             aOptions.timeZone = timezone.tzid;
         }
 
-        return cal.dateTimeToJsDate(aDate).toLocaleString(undefined, aOptions);
+        let formatter = Services.intl.createDateTimeFormat(undefined, aOptions);
+        return formatter.format(cal.dateTimeToJsDate(aDate));
     },
 
     formatTimeInterval: function(aStartDate, aEndDate) {
         if (!aStartDate && aEndDate) {
             return this.formatTime(aEndDate);
         }
         if (!aEndDate && aStartDate) {
             return this.formatTime(aStartDate);