From 3d43f1e85f0e38edc62b85754b68ecfc53699ee7 Mon Sep 17 00:00:00 2001 From: petetnt Date: Fri, 11 Oct 2019 09:04:29 +0300 Subject: [PATCH 1/2] fix: Deal with undetected timeZone in Stats.js Signed-off-by: petetnt --- lib/Stats.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Stats.js b/lib/Stats.js index 153e6f0e8af..0de02f3af22 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -974,16 +974,22 @@ class Stats { } if (typeof obj.builtAt === "number") { const builtAtDate = new Date(obj.builtAt); + let timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; + // Force UTC if runtime timezone could not be detected. + if (!timeZone || timeZone.toLowerCase() === "etc/unknown") { + timeZone = "UTC"; + } colors.normal("Built at: "); colors.normal( builtAtDate.toLocaleDateString(undefined, { day: "2-digit", month: "2-digit", - year: "numeric" + year: "numeric", + timeZone }) ); colors.normal(" "); - colors.bold(builtAtDate.toLocaleTimeString()); + colors.bold(builtAtDate.toLocaleTimeString(undefined, { timeZone })); newline(); } if (obj.env) { From 2260ecae3745fe9b0a029b3a66f93c08804124ff Mon Sep 17 00:00:00 2001 From: petetnt Date: Fri, 11 Oct 2019 09:30:54 +0300 Subject: [PATCH 2/2] fix: Intl.DateTimeFormat can throw too Signed-off-by: petetnt --- lib/Stats.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Stats.js b/lib/Stats.js index 0de02f3af22..fcdcc0a2fc8 100644 --- a/lib/Stats.js +++ b/lib/Stats.js @@ -974,7 +974,14 @@ class Stats { } if (typeof obj.builtAt === "number") { const builtAtDate = new Date(obj.builtAt); - let timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; + let timeZone = null; + + try { + timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; + } catch (err) { + // disregard the RangeError + } + // Force UTC if runtime timezone could not be detected. if (!timeZone || timeZone.toLowerCase() === "etc/unknown") { timeZone = "UTC";