Commit 343245b3 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

For #2923: Don't crash if Intl.RelativeTimeFormat not supported

parent ffd0d3ac
......@@ -194,17 +194,21 @@ class ReaderView {
// Construct a localized and "humanized" reading time in minutes.
// If we have both a fast and slow reading time we'll show both e.g.
// "2 - 4 minutes", otherwise we'll just show "4 minutes".
var parts = new Intl.RelativeTimeFormat(lang).formatToParts(readingTimeMinsSlow, 'minute');
if (parts.length == 3) {
// No need to use part[0] which represents the literal "in".
var readingTime = parts[1].value; // reading time in minutes
var minutesLiteral = parts[2].value; // localized singular or plural literal of 'minute'
var readingTimeString = `${readingTime} ${minutesLiteral}`;
if (readingTimeMinsSlow != readingTimeMinsFast) {
readingTimeString = `${readingTimeMinsFast} - ${readingTimeString}`;
try {
var parts = new Intl.RelativeTimeFormat(lang).formatToParts(readingTimeMinsSlow, 'minute');
if (parts.length == 3) {
// No need to use part[0] which represents the literal "in".
var readingTime = parts[1].value; // reading time in minutes
var minutesLiteral = parts[2].value; // localized singular or plural literal of 'minute'
var readingTimeString = `${readingTime} ${minutesLiteral}`;
if (readingTimeMinsSlow != readingTimeMinsFast) {
readingTimeString = `${readingTimeMinsFast} - ${readingTimeString}`;
}
return readingTimeString;
}
return readingTimeString;
}
catch(error) {
console.error(`Failed to format reading time: ${error}`);
}
return "";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment