Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
b8cc0b2b
Commit
b8cc0b2b
authored
Feb 01, 2021
by
picklesrus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change time library to default to 1 minute when the time remaining is less than 30 seconds.
parent
63494a00
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
src/lib/format-time.js
src/lib/format-time.js
+4
-2
test/unit/lib/format-time.test.js
test/unit/lib/format-time.test.js
+7
-0
No files found.
src/lib/format-time.js
View file @
b8cc0b2b
...
...
@@ -18,8 +18,10 @@ const getTimeUnitAndDuration = timeStamp => {
unit
=
'
hour
'
;
duration
=
diff
/
oneHourInMs
;
}
// Round to nearest hour or minute.
duration
=
Math
.
round
(
duration
);
// Round to nearest hour or minute, but always have at least 1
// so we don't show something like "0 minutes". Hours isn't
// affected by the math.max because we choose minutes up to 2 hours.
duration
=
Math
.
max
(
1
,
Math
.
round
(
duration
));
return
{
unit
:
unit
,
duration
:
duration
...
...
test/unit/lib/format-time.test.js
View file @
b8cc0b2b
...
...
@@ -26,6 +26,13 @@ describe('unit test lib/format-time.js', () => {
expect
(
mockFormatExpression
.
format
).
toHaveBeenCalledWith
(
2
,
'
minute
'
);
});
test
(
'
test timestamp that is 15 seconds in the future displays 1
'
,
()
=>
{
const
fifteenSec
=
15
*
1000
;
mockFormatExpression
.
format
.
mockReturnValue
(
'
in 1 minute
'
);
format
.
formatRelativeTime
(
fifteenSec
,
'
en
'
);
expect
(
mockFormatExpression
.
format
).
toHaveBeenCalledWith
(
1
,
'
minute
'
);
});
test
(
'
test rounding timestamp that is 4.4 minutes rounds to 4
'
,
()
=>
{
const
fourPlusMin
=
4.4
*
60
*
1000
;
mockFormatExpression
.
format
.
mockReturnValue
(
'
in 4 minutes
'
);
...
...
Write
Preview
Markdown
is supported
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