Skip to content

Instantly share code, notes, and snippets.

@marcelmokos
Last active November 8, 2018 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelmokos/7694e174bcfb0b4bacdf8cf8db6e8971 to your computer and use it in GitHub Desktop.
Save marcelmokos/7694e174bcfb0b4bacdf8cf8db6e8971 to your computer and use it in GitHub Desktop.
function addDays(date = new Date(), days = 0) {
const dateClone = new Date(date); // date is an object provided by reference, we need to clone it
dateClone.setDate(date.getDate() + days);
return dateClone;
}
const tomorrowDate = (date, days = 1) => addDays(date, days);
it("Test tomorrowDate function", () => {
cosnt testDateString = "2018-01-01T00:00:00.000Z"
const testDate = new Date(testString);
const testTomorrowDate = new Date("2018-01-02T00:00:00.000Z");
expect(yesterdayDate(testDateString).toIsoString()).toBe(testTomorrowDate.toIsoString());
expect(yesterdayDate(testDate).toIsoString()).toBe(testTomorrowDate.toIsoString());
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment