frontend/src/helpers/time/createDateFromString.js

20 lines
436 B
JavaScript
Raw Normal View History

2021-02-03 22:06:06 +00:00
/**
* 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 => {
2021-04-22 12:26:48 +00:00
if (dateString instanceof Date) {
return dateString
}
2021-02-03 22:06:06 +00:00
if (dateString.includes('-')) {
dateString = dateString.replace(/-/g, '/')
2021-02-03 22:06:06 +00:00
}
return new Date(dateString)
}