Skip to content
Snippets Groups Projects
Commit 1d7b4545 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Add functions dateToInputDateString and dateToInputTimeString

parent 41dbe8aa
No related branches found
No related tags found
No related merge requests found
...@@ -136,7 +136,7 @@ export const makeId = (length) => { ...@@ -136,7 +136,7 @@ export const makeId = (length) => {
export const pad10 = (n) => { return n < 10 ? '0' + n : n }; 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 * @param date
* @returns {string} * @returns {string}
...@@ -148,3 +148,31 @@ export const dateToStrippedIsoDT = (date) => { ...@@ -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())}`; 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())}`;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment