datification(date: string | Date): Result<Date, Error>
Converts a string or a Date object into a Date object.
If the input is a string, it assumes the string is a valid date string (ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ // ie: 2024-03-06T16:09:03Z). If the input is already a Date object, it returns the input as is.
Example 1
Example 1
import { assertEquals } from '@std/assert' // Valid ISO 8601 string const result = datification('2022-01-01T12:00') assertEquals(result.error, undefined) assertEquals(result.data?.toISOString(), new Date('2022-01-01T12:00').toISOString())