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
  • 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),
  );
};

Originating discussion

!18395 (comment 233847503)

Assignee Loading
Time tracking Loading