Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: timestamp literal support (#28)
# RFC 3339-compliant Timestamp Parsing To ensure our timestamp parsing aligns closely with RFC 3339 standards, the following tests have been proposed to verify each aspect of the timestamp formatting and parsing process: ## Current Capabilities - Date and Time with Timezone: - [x] `2009-01-03T18:15:05Z` (UTC timezone) - [x] `2009-01-03T18:15:05+02:30` (Positive timezone offset) - [x] `2009-01-03T18:15:05-07:00` (Negative timezone offset) - Date and Time with Fractional Seconds: - [x] `2009-01-03T18:15:05.123Z` (Milliseconds) - [x] `2009-01-03T18:15:05.123456Z` (Microseconds) - [x] `2009-01-03T18:15:05.123456789Z` (Nanoseconds) ## Unix Epoch Time Parsing Capability This module includes functionality for parsing timestamps represented as time units (e.g., seconds) since the Unix epoch (January 1, 1970, at 00:00:00 UTC). This allows for direct integration and manipulation of time data sourced from systems that utilize Unix time (POSIX time). ### Features: - **Unix Timestamp Parsing**: Capable of interpreting strings or numeric values representing seconds since the Unix epoch and converting them into a standard datetime format. - **UTC Alignment**: All parsed Unix timestamps are automatically aligned to UTC, ensuring consistency across different time-related operations. ### Example Usage: ```rust // Parsing an RFC 3339 timestamp without a timezone: let timestamp_str = "2009-01-03T18:15:05Z"; let intermediate_timestamp = IntermediateTimestamp::try_from(timestamp_str).unwrap(); assert_eq!(intermediate_timestamp.timezone, IntermediateTimeZone::Utc); // Parsing an RFC 3339 timestamp with a positive timezone offset: let timestamp_str_with_tz = "2009-01-03T18:15:05+03:00"; let intermediate_timestamp = IntermediateTimestamp::try_from(timestamp_str_with_tz).unwrap(); assert_eq!(intermediate_timestamp.timezone, IntermediateTimeZone::FixedOffset(10800)); // 3 hours in seconds // Parsing a Unix epoch timestamp (assumed to be seconds and UTC): let unix_time_str = "1231006505"; let intermediate_timestamp = IntermediateTimestamp::to_timestamp(unix_time_str).unwrap(); assert_eq!(intermediate_timestamp.timezone, IntermediateTimeZone::Utc); ``` # Tests for RFC 3339 Compliance - [x] **Test UTC Timezone Parsing** Ensure proper parsing of timestamps with the UTC timezone designator (`Z`). - [x] **Test Positive Timezone Offset** Ensure timestamps with positive timezone offsets are parsed correctly. - [x] **Test Negative Timezone Offset** Ensure timestamps with negative timezone offsets are parsed correctly. - [x] **Test Zero Timezone Offset** Validate parsing of timestamps where timezone is explicitly set to UTC with `+00:00`. - [x] **Test Unix Epoch Time Timezone** Verify that Unix epoch timestamps are assumed to be in UTC. - [x] **Test Unix Epoch Timestamp Parsing** Check parsing of Unix epoch timestamps from string representations. - [x] **Test Basic RFC 3339 Timestamp** Confirm basic parsing of RFC 3339 compliant timestamps with no timezone offset specified. - [x] **Test RFC 3339 Timestamp with Positive Offset** Test parsing of timestamps with positive timezone offsets. - [x] **Test RFC 3339 Timestamp with Negative Offset** Test parsing of timestamps with negative timezone offsets. - [x] **Test RFC 3339 Timestamp with UTC Designator** Confirm parsing of timestamps with the UTC designator (`Z`). - [x] **Test Invalid RFC 3339 Timestamp** Ensure that non-compliant strings are not parsed as valid timestamps. - [x] **Test Timestamp with Seconds Precision** Confirm that timestamps with seconds precision are parsed correctly. - [x] **Test RFC 3339 Timestamp with Milliseconds** Validate parsing of timestamps that include millisecond precision. - [x] **Test RFC 3339 Timestamp with Microseconds** Validate parsing of timestamps that include microsecond precision. - [x] **Test RFC 3339 Timestamp with Nanoseconds** Validate parsing of timestamps that include nanosecond precision. - [x] **Test General Parsing Error** Check handling of malformed timestamp inputs. - [x] **Test Basic Date-Time Support** Ensure basic RFC 3339 formatted date-times are parsed correctly. - [x] **Test Leap Seconds Handling** Verify that leap seconds are handled correctly in timestamps. - [x] **Test Rejection of Incorrect Formats** Ensure that incorrect timestamp formats are properly rejected.
- Loading branch information