From 1d7b454529fa47ccec6cb6abb83a6a0ae16e7b3e Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Mon, 26 Aug 2019 14:45:21 +0200
Subject: [PATCH] Add functions dateToInputDateString and dateToInputTimeString

---
 packages/common/utils.js | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/packages/common/utils.js b/packages/common/utils.js
index c26afe76..f3fe8c0c 100644
--- a/packages/common/utils.js
+++ b/packages/common/utils.js
@@ -136,7 +136,7 @@ export const makeId = (length) => {
 export const pad10 = (n) => { return n < 10 ? '0' + n : n };
 
 /**
- * Converts a date string to a local iso datetime with stripped seconds and timezone for the datetime-local input
+ * Converts a date object or string to a local iso datetime with stripped seconds and timezone for the datetime-local input
  *
  * @param date
  * @returns {string}
@@ -148,3 +148,31 @@ export const dateToStrippedIsoDT = (date) => {
 
     return `${date.getFullYear()}-${pad10(date.getMonth()+1)}-${pad10(date.getDate())}T${pad10(date.getHours())}:${pad10(date.getMinutes())}`;
 };
+
+/**
+ * Converts a date object or string to a local date string the date input
+ *
+ * @param date
+ * @returns {string}
+ */
+export const dateToInputDateString = (date) => {
+    if (!(date instanceof Date)) {
+        date = new Date(date);
+    }
+
+    return `${date.getFullYear()}-${pad10(date.getMonth()+1)}-${pad10(date.getDate())}`;
+};
+
+/**
+ * Converts a date object or string to a local time string the time input
+ *
+ * @param date
+ * @returns {string}
+ */
+export const dateToInputTimeString = (date) => {
+    if (!(date instanceof Date)) {
+        date = new Date(date);
+    }
+
+    return `${pad10(date.getHours())}:${pad10(date.getMinutes())}`;
+};
-- 
GitLab