Universal Date Parser
A comprehensive, high-performance date parsing library that can intelligently parse dates from virtually any format into standardized output. Features automatic format detection, timezone awareness, robust error handling, and multi-language bindings.
โจ Features
- Universal Format Support: Parse dates from ISO 8601, RFC 2822, Unix timestamps, US/European formats, and more
- Intelligent Detection: Automatic format recognition with confidence scoring
- Timezone Awareness: Flexible timezone handling strategies
- Ambiguity Resolution: Detect and handle ambiguous date formats (MM/DD vs DD/MM)
- High Performance: Optimized for speed with comprehensive benchmarks
- Multi-Language Bindings: C FFI and WebAssembly exports
- Fuzzy Parsing: Handle malformed or non-standard date inputs
- Extensive Configuration: Customizable parsing behavior
- Robust Error Handling: Detailed error messages and recovery strategies
๐ Quick Start
Add to your Cargo.toml
:
[]
= "1.0"
Basic Usage
use ;
Advanced Configuration
use ;
use FixedOffset;
๐ Supported Formats
Standard Formats
- ISO 8601:
2023-12-25T15:30:45Z
,2023-12-25T15:30:45+02:00
- RFC 2822:
Mon, 25 Dec 2023 15:30:45 +0000
- Unix Timestamps:
1703520645
,1703520645000
(with milliseconds)
Regional Formats
- US Format:
MM/DD/YYYY
โ12/25/2023
- European Format:
DD/MM/YYYY
โ25/12/2023
- Flexible Separators:
MM-DD-YYYY
,DD.MM.YYYY
Natural Language
- Long Format:
December 25, 2023
,25 December 2023
- Relative Dates:
today
,yesterday
,tomorrow
Custom Formats
- Configurable Patterns: Add your own regex patterns
- Format Priority: Control parsing order and preferences
๐ง Configuration Options
Timezone Strategies
๐ Multi-Language Support
C/C++ Integration
int
WebAssembly/JavaScript
import init from './pkg/universal_date_parser.js';
๐ Performance
Based on comprehensive benchmarks:
Date Parsing Performance:
โโโ ISO 8601 DateTime: ~245 ns (4.08M parses/sec)
โโโ US Format: ~189 ns (5.29M parses/sec)
โโโ Unix Timestamp: ~156 ns (6.41M parses/sec)
โโโ European Format: ~198 ns (5.05M parses/sec)
โโโ Bulk Parsing (10): ~1.85 ฮผs (540K batches/sec)
Configuration Impact:
โโโ Default Mode: ~189 ns
โโโ Strict Mode: ~167 ns (12% faster)
โโโ Fuzzy Mode: ~234 ns (24% slower)
Run benchmarks yourself:
๐ ๏ธ Error Handling
The parser provides detailed error information:
use ParseError;
match parser.parse
๐งช Testing
Run the comprehensive test suite:
# Run all tests
# Run with output
# Run specific test
๐ Examples
Handling Multiple Possibilities
let parser = new;
let possibilities = parser.parse_all_possibilities;
for in possibilities.iter.enumerate
Custom Format Patterns
let config = ParserConfig ;
let parser = with_config;
let result = parser.parse.unwrap;
Batch Processing
let parser = new;
let dates = vec!;
let results: = dates
.iter
.map
.collect;
for in dates.iter.zip
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
This project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.