datetime.ts 592 B

12345678910111213141516171819
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. // export const validDateTime = (value: string) =>
  3. // !Number.isNaN(Date.parse(String(value)))
  4. export const validDateTime = (value: string) => {
  5. const dateTimeRegex =
  6. /^(?:\d{4}-\d{2}-\d{2}|(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)|(?:\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC))$/
  7. if (!dateTimeRegex.test(value)) return false
  8. return !Number.isNaN(Date.parse(String(value)))
  9. }
  10. export const isDateString = (value: string) => {
  11. const dateRegex = /^\d{4}-\d{2}-\d{2}$/
  12. return dateRegex.test(value)
  13. }