Expand description
HL7 v2 date/time parsing and validation.
This crate provides comprehensive date/time handling for HL7 v2 messages, supporting various HL7 timestamp formats and precision levels.
§Supported Formats
DT(Date): YYYYMMDDTM(Time): HHMM[SS[.S[S[S[S]]]]]TS(Timestamp): YYYYMMDD[HHMM[SS[.S[S[S[S]]]]]]
§Example
use hl7v2_datetime::{parse_hl7_ts, parse_hl7_dt, parse_hl7_tm, parse_hl7_ts_with_precision, TimestampPrecision};
use chrono::Datelike;
// Parse date (DT)
let date = parse_hl7_dt("20250128").unwrap();
assert_eq!(date.year(), 2025);
assert_eq!(date.month(), 1);
assert_eq!(date.day(), 28);
// Parse timestamp (TS) with precision
let ts = parse_hl7_ts_with_precision("20250128152312").unwrap();
assert_eq!(ts.precision, TimestampPrecision::Second);
// Compare timestamps with different precisions
let ts1 = parse_hl7_ts_with_precision("20250128").unwrap();
let ts2 = parse_hl7_ts_with_precision("20250128120000").unwrap();
assert!(ts1.is_same_day(&ts2));Structs§
- Parsed
Timestamp - Parsed HL7 timestamp with precision information
Enums§
- Date
Time Error - Error type for date/time parsing
- Timestamp
Precision - Precision levels for HL7 timestamps
Functions§
- is_
valid_ hl7_ date - Check if a string is a valid HL7 date (DT)
- is_
valid_ hl7_ time - Check if a string is a valid HL7 time (TM)
- is_
valid_ hl7_ timestamp - Check if a string is a valid HL7 timestamp (TS)
- now_hl7
- Get current timestamp in HL7 format
- parse_
hl7_ dt - Parse HL7 date (DT format: YYYYMMDD)
- parse_
hl7_ tm - Parse HL7 time (TM format: HHMM[SS[.S…]])
- parse_
hl7_ ts - Parse HL7 timestamp (TS format: YYYYMMDD[HHMM[SS[.S…]]])
- parse_
hl7_ ts_ with_ precision - Parse HL7 timestamp with precision information
- today_
hl7 - Get current date in HL7 format