This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/time/createDateFromString.js
sytone 306a926c66
All checks were successful
continuous-integration/drone/push Build is passing
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: #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)
}