Parse Date Strings

screenshot of Parse Date Strings

Parsing content date strings in Eleventy core.

Overview

@11ty/parse-date-strings is a lightweight and efficient date parsing library designed specifically for compatibility with RFC 9557. It offers a zero-dependency solution, making it an ideal choice for developers looking to implement straightforward date parsing without the need for heavy libraries. The flexibility to utilize various formats, along with support for Temporal API integration, positions this library as a valuable asset for modern JavaScript applications.

This library not only simplifies the process of parsing date strings but also ensures consistency between development and production environments by defaulting to UTC when time zones are unknown. It's particularly useful for developers working on projects where date accuracy and flexibility are paramount.

Features

  • Zero Dependency: Minimalist library that doesn't require any additional packages, keeping your build lightweight.
  • Temporal API Compatibility: Date strings can be parsed using Temporal.PlainDate.from, Temporal.Instant.from, or Temporal.PlainDateTime.from for future-proofing against Temporal API enhancements.
  • Error Handling: Invalid date strings trigger errors, preventing subtle bugs and ensuring robust applications.
  • Time Zone Handling: Defaults to UTC when no time zone is specified, maintaining consistency across build and deployment servers.
  • Flexible Offset Support: Accepts various time zone offset formats including +00, +00:00, -00, and -00:00, with optional delimiters.
  • Date and Time Delimiters: Allows for flexibility in using delimiters; a T, t, or space is needed for DateTime strings, while date and time formats can opt for minimal delimiters.
  • Compatibility Considerations: Designed to exclude standalone time formats and ISO week date syntax, ensuring strict adherence to RFC 9557 while supporting fractional seconds.
  • Strict Parsing: Provides more stringent parsing rules compared to other popular libraries like Luxon, which ensures higher accuracy in date handling.