From 7b3068b35b21581d98b52de3a5dfaf61c3861768 Mon Sep 17 00:00:00 2001 From: Niels Leenheer Date: Mon, 22 Jan 2018 22:38:11 +0100 Subject: [PATCH 1/3] 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 From 5e6b867cf9233f26dd782729dad8aed764ed77ce Mon Sep 17 00:00:00 2001 From: Niels Leenheer Date: Mon, 22 Jan 2018 23:37:04 +0100 Subject: [PATCH 2/3] Use getDate() instead of the obviously wrong getDay() --- snippets/tomorrow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md index 49eb09332..3008f4d65 100644 --- a/snippets/tomorrow.md +++ b/snippets/tomorrow.md @@ -12,7 +12,7 @@ const tomorrow = () => { '-' + String(t.getMonth() + 1).padStart(2, '0') + '-' + - String(t.getDay()).padStart(2, '0') + String(t.getDate()).padStart(2, '0') ); }; ``` From d3df067dc967978e89f5f1dadadd32489288a5ba Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 23 Jan 2018 13:29:26 +0200 Subject: [PATCH 3/3] Update tomorrow.md --- snippets/tomorrow.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/snippets/tomorrow.md b/snippets/tomorrow.md index 3008f4d65..24bbb530c 100644 --- a/snippets/tomorrow.md +++ b/snippets/tomorrow.md @@ -7,13 +7,7 @@ Use `new Date()` to get today's date, adding one day using `Date.getDate()` and const tomorrow = () => { let t = new Date(); t.setDate(t.getDate() + 1); - return ( - t.getFullYear() + - '-' + - String(t.getMonth() + 1).padStart(2, '0') + - '-' + - String(t.getDate()).padStart(2, '0') - ); + return `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(t.getDate()).padStart(2, '0')}`; }; ```