Commit bf55e497 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'mw-get-date-in-past-fix' into 'master'

Fix getDateInPast method

See merge request gitlab-org/gitlab!17821
parents 17fc6231 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();
};
......@@ -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));
});
});
Markdown is supported
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