Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
343245b3
Commit
343245b3
authored
Oct 17, 2019
by
Christian Sadilek
Browse files
For #2923: Don't crash if Intl.RelativeTimeFormat not supported
parent
ffd0d3ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
components/feature/readerview/src/main/assets/extensions/readerview/readerview.js
View file @
343245b3
...
...
@@ -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
""
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment