From 85311d5f6ecb6e2f970ff83ede664a243dfd0dce Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Sat, 19 Nov 2016 12:48:46 +0000 Subject: [PATCH] Bug 1318204 - Provide fallback date/time formatting in about:crashes for Android, where Intl API is not available. r=gandalf --- toolkit/crashreporter/content/crashes.js | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/toolkit/crashreporter/content/crashes.js b/toolkit/crashreporter/content/crashes.js index f1d3f39d9b75..74d3018df0c0 100644 --- a/toolkit/crashreporter/content/crashes.js +++ b/toolkit/crashreporter/content/crashes.js @@ -78,14 +78,31 @@ function populateReportList() { return; } - const locale = Cc["@mozilla.org/chrome/chrome-registry;1"] - .getService(Ci.nsIXULChromeRegistry) - .getSelectedLocale("global", true); - var dateFormatter = new Intl.DateTimeFormat(locale, { year: '2-digit', - month: 'numeric', - day: 'numeric' }); - var timeFormatter = new Intl.DateTimeFormat(locale, { hour: 'numeric', - minute: 'numeric' }); + var dateFormatter; + var timeFormatter; + try { + const locale = Cc["@mozilla.org/chrome/chrome-registry;1"] + .getService(Ci.nsIXULChromeRegistry) + .getSelectedLocale("global", true); + dateFormatter = new Intl.DateTimeFormat(locale, { year: '2-digit', + month: 'numeric', + day: 'numeric' }); + timeFormatter = new Intl.DateTimeFormat(locale, { hour: 'numeric', + minute: 'numeric' }); + } catch (e) { + // XXX Fallback to be removed once bug 1215247 is complete + // and the Intl API is available on all platforms. + dateFormatter = { + format: function(date) { + return date.toLocaleDateString(); + } + } + timeFormatter = { + format: function(date) { + return date.toLocaleTimeString(); + } + } + } var ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); var reportURI = ios.newURI(reportURL, null, null);