From fb8fea472471582bc366074d84bd0d1b33e5d541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 2 Mar 2023 17:26:44 +0100 Subject: [PATCH] input datetime-local needs day to also be two digits --- games/static/js/utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/games/static/js/utils.js b/games/static/js/utils.js index 988e0a7..ddaaa3b 100644 --- a/games/static/js/utils.js +++ b/games/static/js/utils.js @@ -4,6 +4,13 @@ * @returns {string} */ export function toISOUTCString(date) { - let month = (date.getMonth() + 1).toString().padStart(2, 0); - return `${date.getFullYear()}-${month}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`; + function stringAndPad(number) { + return number.toString().padStart(2, 0); + } + const year = date.getFullYear(); + const month = stringAndPad(date.getMonth() + 1); + const day = stringAndPad(date.getDate()); + const hours = stringAndPad(date.getHours()); + const minutes = stringAndPad(date.getMinutes()); + return `${year}-${month}-${day}T${hours}:${minutes}`; }