From 932424859b76c3e02bdf9676dd6740eb9941aa5f Mon Sep 17 00:00:00 2001 From: Niels Leenheer Date: Mon, 22 Jan 2018 22:38:11 +0100 Subject: [PATCH] Fix tomorrow() function For details see bug #564 --- snippets/tomorrow.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md index 3bd5a6412..49eb09332 100644 --- a/snippets/tomorrow.md +++ b/snippets/tomorrow.md @@ -1,10 +1,20 @@ ### tomorrow Results in a string representation of tomorrow's date. -Use `new Date()` to get today's date, adding `86400000` of seconds to it(24 hours), using `Date.toISOString()` to convert Date object to string. +Use `new Date()` to get today's date, adding one day using `Date.getDate()` and `Date.setDate()`, and converting the Date object to a string. ```js -const tomorrow = () => new Date(new Date().getTime() + 86400000).toISOString().split('T')[0]; +const tomorrow = () => { + let t = new Date(); + t.setDate(t.getDate() + 1); + return ( + t.getFullYear() + + '-' + + String(t.getMonth() + 1).padStart(2, '0') + + '-' + + String(t.getDay()).padStart(2, '0') + ); +}; ``` ```js