module DateUtils

Overview

Date parsing utilities

Provides a unified date parsing function that tries multiple formats including standard formats and common CMS-specific formats.

Defined in:

date_utils.cr

Class Method Summary

Class Method Detail

def self.parse(date_str : String | Nil) : Time | Nil #

Parse a date string from various formats

Tries the following formats in order:

  • Cronic (natural language dates like "tomorrow", "2 weeks ago")
  • RFC 2822 (e.g., "Wed, 02 Oct 2002 13:00:00 GMT")
  • ISO 8601 (e.g., "2022-01-01T00:00:00Z")
  • Pocketbase (e.g., "2026-01-29 11:57:28.164Z")
  • HTTP date (via HTTP.parse_time)

Returns nil if the date cannot be parsed.


[View source]