Skip to content

Commit d32b58d

Browse files
committed
temporal parser imlementation
1 parent 4707b93 commit d32b58d

File tree

3 files changed

+729
-14
lines changed

3 files changed

+729
-14
lines changed

src/iso.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ use crate::{
4444
use icu_calendar::{Date as IcuDate, Iso};
4545
use num_traits::{cast::FromPrimitive, Euclid};
4646

47+
// ISO/Temporal specification limits
48+
//
49+
// Year limits are defined by the ECMAScript Temporal specification:
50+
// https://tc39.es/proposal-temporal/#sec-temporal-date-objects
51+
// These limits ensure compatibility with ISO 8601 extended year format
52+
// and avoid issues with JavaScript's Date object limitations.
53+
//
54+
// Time component limits follow ISO 8601 standard:
55+
// https://www.iso.org/iso-8601-date-and-time-format.html
56+
// See also RFC 3339: https://tools.ietf.org/html/rfc3339
57+
58+
/// Minimum supported year (-271821-04-19T00:00:00Z corresponds to ECMAScript's minimum time value)
59+
pub(crate) const MIN_ISO_YEAR: i32 = -271821;
60+
/// Maximum supported year (275760-09-13T00:00:00Z corresponds to ECMAScript's maximum time value)
61+
pub(crate) const MAX_ISO_YEAR: i32 = 275760;
62+
/// Minimum month value per ISO 8601
63+
pub(crate) const MIN_ISO_MONTH: u8 = 1;
64+
/// Maximum month value per ISO 8601
65+
pub(crate) const MAX_ISO_MONTH: u8 = 12;
66+
/// Minimum day value per ISO 8601
67+
pub(crate) const MIN_ISO_DAY: u8 = 1;
68+
/// Maximum hour value per ISO 8601 (24-hour format, 0-23)
69+
pub(crate) const MAX_ISO_HOUR: u8 = 23;
70+
/// Maximum minute value per ISO 8601
71+
pub(crate) const MAX_ISO_MINUTE: u8 = 59;
72+
/// Maximum second value per ISO 8601
73+
pub(crate) const MAX_ISO_SECOND: u8 = 59;
74+
4775
/// `IsoDateTime` is the record of the `IsoDate` and `IsoTime` internal slots.
4876
#[non_exhaustive]
4977
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]

src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@
4848
//!
4949
//! ```
5050
//!
51+
//! ### Parse timestamps with the public `TemporalParser` API
52+
//!
53+
//! The `TemporalParser` provides a high-level, public API for parsing IXDTF strings
54+
//! with built-in validation and invariant checking.
55+
//!
56+
//! ```rust
57+
//! use temporal_rs::parsers::TemporalParser;
58+
//!
59+
//! let parser = TemporalParser::new();
60+
//!
61+
//! // Parse a PlainDateTime with validation
62+
//! let dt_result = parser.parse_date_time("2025-01-15T14:30:00[u-ca=gregory]");
63+
//! assert!(dt_result.is_ok());
64+
//! let parsed = dt_result.unwrap();
65+
//! assert_eq!(parsed.iso.date.year, 2025);
66+
//! assert_eq!(parsed.iso.time.hour, 14);
67+
//! assert!(parsed.calendar.is_some());
68+
//!
69+
//! // Parse an Instant
70+
//! let instant_result = parser.parse_instant("2025-01-15T14:30:00Z");
71+
//! assert!(instant_result.is_ok());
72+
//!
73+
//! // Parse a ZonedDateTime
74+
//! let zdt_result = parser.parse_zoned_date_time("2025-01-15T14:30:00Z[America/New_York]");
75+
//! assert!(zdt_result.is_ok());
76+
//! let zdt_parsed = zdt_result.unwrap();
77+
//! assert_eq!(zdt_parsed.timezone(), "America/New_York");
78+
//!
79+
//! // Invalid dates are properly rejected
80+
//! let invalid_result = parser.parse_date_time("2025-02-30T14:30:00"); // Feb 30th doesn't exist
81+
//! assert!(invalid_result.is_err());
82+
//! ```
83+
//!
5184
//! ### Create a `ZonedDateTime` for a RFC9557 IXDTF string.
5285
//!
5386
//! **Important Note:** The below API is enabled with the

0 commit comments

Comments
 (0)