frontend/src/helpers/time/createDateFromString.js
sytone 306a926c66 Add default list setting & creating tasks from home (#520)
Co-authored-by: sytone <github@sytone.com>
Co-authored-by: Sytone <github@sytone.com>
Co-authored-by: kolaente <k@knt.li>
Reviewed-on: vikunja/frontend#520
Reviewed-by: konrad <konrad@kola-entertainments.de>
Co-authored-by: sytone <kolaente@sytone.com>
Co-committed-by: sytone <kolaente@sytone.com>
2021-07-17 21:21:46 +00:00

20 lines
436 B
JavaScript

/**
* Returns a new date from any format in a way that all browsers, especially safari, can understand.
*
* @see https://kolaente.dev/vikunja/frontend/issues/207
*
* @param dateString
* @returns {Date}
*/
export const createDateFromString = dateString => {
if (dateString instanceof Date) {
return dateString
}
if (dateString.includes('-')) {
dateString = dateString.replace(/-/g, '/')
}
return new Date(dateString)
}