Skip to content

Commit

Permalink
Merge pull request #9799 from petetnt/petetnt-stats-fix
Browse files Browse the repository at this point in the history
fix: Deal with undetected timeZone in Stats.js
  • Loading branch information
sokra committed Oct 11, 2019
2 parents 8dc440e + 2260eca commit 16d2628
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/Stats.js
Expand Up @@ -974,16 +974,29 @@ class Stats {
}
if (typeof obj.builtAt === "number") {
const builtAtDate = new Date(obj.builtAt);
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";
}
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) {
Expand Down

0 comments on commit 16d2628

Please sign in to comment.