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.ts

20 lines
457 B
TypeScript

/**
* 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 function createDateFromString(dateString: Date | string) : Date {
if (dateString instanceof Date) {
return dateString
}
if (dateString.includes('-')) {
dateString = dateString.replace(/-/g, '/')
}
return new Date(dateString)
}