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
38a6ddb7
Commit
38a6ddb7
authored
Sep 27, 2019
by
Martin Wortschack
Committed by
Mike Greiling
Sep 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getDateInPast method
- Avoid mutating the original date reference
parent
17fc6231
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
app/assets/javascripts/lib/utils/datetime_utility.js
app/assets/javascripts/lib/utils/datetime_utility.js
+6
-2
spec/frontend/lib/utils/datetime_utility_spec.js
spec/frontend/lib/utils/datetime_utility_spec.js
+8
-3
No files found.
app/assets/javascripts/lib/utils/datetime_utility.js
View file @
38a6ddb7
...
...
@@ -555,5 +555,9 @@ export const calculateRemainingMilliseconds = endDate => {
* @param {number} daysInPast number of days that are subtracted from a given date
* @returns {String} Date string in ISO format
*/
export
const
getDateInPast
=
(
date
,
daysInPast
)
=>
new
Date
(
date
.
setTime
(
date
.
getTime
()
-
daysInPast
*
24
*
60
*
60
*
1000
)).
toISOString
();
export
const
getDateInPast
=
(
date
,
daysInPast
)
=>
{
const
dateClone
=
newDate
(
date
);
return
new
Date
(
dateClone
.
setTime
(
dateClone
.
getTime
()
-
daysInPast
*
24
*
60
*
60
*
1000
),
).
toISOString
();
};
spec/frontend/lib/utils/datetime_utility_spec.js
View file @
38a6ddb7
...
...
@@ -428,11 +428,16 @@ describe('newDate', () => {
});
describe
(
'
getDateInPast
'
,
()
=>
{
const
date
=
new
Date
(
1563235200000
);
// 2019-07-16T00:00:00.000Z;
const
daysInPast
=
90
;
it
(
'
returns the correct date in the past
'
,
()
=>
{
const
date
=
new
Date
(
1563235200000
);
// 2019-07-16T00:00:00.00Z
const
daysInPast
=
90
;
const
dateInPast
=
datetimeUtility
.
getDateInPast
(
date
,
daysInPast
);
expect
(
dateInPast
).
toBe
(
'
2019-04-17T00:00:00.000Z
'
);
});
it
(
'
does not modifiy the original date
'
,
()
=>
{
datetimeUtility
.
getDateInPast
(
date
,
daysInPast
);
expect
(
date
).
toStrictEqual
(
new
Date
(
1563235200000
));
});
});
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