Refactor `getDateInPast` to return date object
Problem
getDateInPast currently returns an ISO string and not a date object. This results in requiring to initialise a date object after receiving the response from getDateInPast if you require another format / or need to further manipulate the date.
Suggestion
Change the response of getDateInPast to a date object.
- Advantage
- Applying the above suggestion would mean that the date can easily be formatted / manipulated as required after being returned from
getDateInPast
- Applying the above suggestion would mean that the date can easily be formatted / manipulated as required after being returned from
- Disadvantage
- Minor refactor across the analytics suite, the earlier we catch this the better.
app/assets/javascripts/lib/utils/datetime_utility.js
FROM
export const getDateInPast = (date, daysInPast) => {
const dateClone = newDate(date);
return new Date(
dateClone.setTime(dateClone.getTime() - daysInPast * 24 * 60 * 60 * 1000),
).toISOString();
};
TO
export const getDateInPast = (date, daysInPast) => {
const dateClone = newDate(date);
return new Date(
dateClone.setTime(dateClone.getTime() - daysInPast * 24 * 60 * 60 * 1000),
);
};