Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
50222d4d
Commit
50222d4d
authored
Oct 19, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add calculateRemainingMilliseconds() helper function
parent
048ec287
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
app/assets/javascripts/lib/utils/datetime_utility.js
app/assets/javascripts/lib/utils/datetime_utility.js
+12
-0
spec/javascripts/lib/utils/datetime_utility_spec.js
spec/javascripts/lib/utils/datetime_utility_spec.js
+18
-0
No files found.
app/assets/javascripts/lib/utils/datetime_utility.js
View file @
50222d4d
...
...
@@ -473,3 +473,15 @@ export const stringifyTime = timeObject => {
*/
export
const
abbreviateTime
=
timeStr
=>
timeStr
.
split
(
'
'
).
filter
(
unitStr
=>
unitStr
.
charAt
(
0
)
!==
'
0
'
)[
0
];
/**
* Calculates the milliseconds between now and a given date string.
* The result cannot become negative.
*
* @param endDate date string that the time difference is calculated for
* @return {number} number of milliseconds remaining until the given date
*/
export
const
calculateRemainingMilliseconds
=
endDate
=>
{
const
remainingMilliseconds
=
new
Date
(
endDate
).
getTime
()
-
Date
.
now
();
return
Math
.
max
(
remainingMilliseconds
,
0
);
};
spec/javascripts/lib/utils/datetime_utility_spec.js
View file @
50222d4d
...
...
@@ -352,3 +352,21 @@ describe('prettyTime methods', () => {
});
});
});
describe
(
'
calculateRemainingMilliseconds
'
,
()
=>
{
beforeEach
(()
=>
{
spyOn
(
Date
,
'
now
'
).
and
.
callFake
(()
=>
new
Date
(
'
2063-04-04T00:42:00Z
'
).
getTime
());
});
it
(
'
calculates the remaining time for a given end date
'
,
()
=>
{
const
milliseconds
=
datetimeUtility
.
calculateRemainingMilliseconds
(
'
2063-04-04T01:44:03Z
'
);
expect
(
milliseconds
).
toBe
(
3723000
);
});
it
(
'
returns 0 if the end date has passed
'
,
()
=>
{
const
milliseconds
=
datetimeUtility
.
calculateRemainingMilliseconds
(
'
2063-04-03T00:00:00Z
'
);
expect
(
milliseconds
).
toBe
(
0
);
});
});
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