Bug 1610400 - Fail gracefully when formatting a date with a timezone unknown to Services.intl. r=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 21 Jan 2020 16:38:44 +1300
changeset 37184 f2e3b944020b62496533aa1b9f211602f511c2eb
parent 37183 bfac6639d78670407f4afef6a7c1516024d7c33c
child 37185 66a355f9a99fbcb5f32df958150b18e6a965d5bd
push id2552
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:24:16 +0000
treeherdercomm-beta@f95a6f4408a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspmorris
bugs1610400
Bug 1610400 - Fail gracefully when formatting a date with a timezone unknown to Services.intl. r=pmorris
calendar/base/src/calDateTimeFormatter.js
--- a/calendar/base/src/calDateTimeFormatter.js
+++ b/calendar/base/src/calDateTimeFormatter.js
@@ -57,23 +57,30 @@ calDateTimeFormatter.prototype = {
   /**
    * _inTimezone returns a string with date formatted
    *
    * @param  {calIDateTime} aDate    The date object holding the tz information
    * @param  {JsObject}     aOptions The options object for formatting.
    * @return {String}                The date as a string.
    */
   _inTimezone: function(aDate, aOptions) {
+    let formatter = new Services.intl.DateTimeFormat(undefined, aOptions);
+
     let timezone = aDate.timezone;
-    // we set the tz only if we have a valid tz - otherwise localtime will be used on formatting.
+    // 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;
+      try {
+        formatter = new Services.intl.DateTimeFormat(undefined, aOptions);
+      } catch (ex) {
+        // Non-IANA timezones throw a RangeError.
+        cal.WARN(ex);
+      }
     }
 
-    let formatter = new Services.intl.DateTimeFormat(undefined, aOptions);
     return formatter.format(cal.dtz.dateTimeToJsDate(aDate));
   },
 
   formatTimeInterval: function(aStartDate, aEndDate) {
     if (!aStartDate && aEndDate) {
       return this.formatTime(aEndDate);
     }
     if (!aEndDate && aStartDate) {