3 releases
| 0.1.2 | Oct 1, 2025 |
|---|---|
| 0.1.1 | Oct 1, 2025 |
| 0.1.0 | Oct 1, 2025 |
#843 in Development tools
35 downloads per month
26KB
342 lines
smart_date_time
A smart date-time parsing and formatting Rust library that supports multiple date-time formats and languages, including Chinese, English, and other popular world languages.
Features
- 🚀 Smart Parsing: Automatically recognizes and parses multiple date-time formats
- 🌍 Multilingual Support: Native support for Chinese, English, and 8 other popular world languages
- 📅 Flexible Formatting: Supports custom formatting templates
- 🔄 Fault Tolerance: Returns current date-time when parsing fails
- ⚡ Lightweight: Minimal dependencies, excellent performance
Supported Languages
Fully Supported ✅
- 🇨🇳 Chinese (中文) - 今天, 现在
- 🇺🇸 English - today, doday, now
- 🇪🇸 Spanish (Español) - hoy, ahora
- 🇫🇷 French (Français) - aujourd'hui, maintenant
- 🇩🇪 German (Deutsch) - heute, jetzt
- 🇯🇵 Japanese (日本語) - 今日, 今
- 🇰🇷 Korean (한국어) - 오늘, 지금
- 🇮🇹 Italian (Italiano) - oggi, ora
- 🇵🇹 Portuguese (Português) - hoje, agora
- 🇷🇺 Russian (Русский) - сегодня, сейчас
Supported Formats
Date Formats
2025-01-20- Standard date format2025/1/20- Slash-separated format2025.1.20- Dot-separated format2025年1月20- Chinese year-month format2025年1月20日- Chinese complete date format01-01- Month-day format (uses current year)1.2- Dot-separated month-day format11.20- Dot-separated month-day format20号- Chinese date format
Time Formats
13:42:52- Complete time format13:42- Hour-minute format13点- Chinese hour format13点半- Chinese half-hour format
Special Keywords
今天- Current date (Chinese)doday- Current date (English)now- Current date-time (English)
Installation
Add dependency to your Cargo.toml:
[dependencies]
smart_date_time = "0.1.0"
Usage
Basic Usage
use smart_date_time;
// Parse and format date
let result = smart_date_time::format("2025-01-20", "YYYY-MM-DD");
println!("{}", result); // Output: 2025-01-20
// Parse Chinese format
let result = smart_date_time::format("今天", "YYYY年MM月DD日");
println!("{}", result); // Output: 2025年10月01日 (based on current date)
// Parse time format
let result = smart_date_time::format("13点半", "YYYY-MM-DD HH:mm");
println!("{}", result); // Output: 2025-10-01 13:30 (uses current date)
Formatting Templates
Supported formatting placeholders:
YYYY- Four-digit year (e.g., 2025)MM- Two-digit month (e.g., 01, 12)DD- Two-digit day (e.g., 01, 31)HH- Two-digit hour (24-hour format, e.g., 00, 23)mm- Two-digit minute (e.g., 00, 59)ss- Two-digit second (e.g., 00, 59)
Examples
use smart_date_time;
// Various format examples
let examples = vec![
("2025-01-20", "YYYY-MM-DD"),
("2025/1/20", "YYYY/MM/DD"),
("2025.1.20", "YYYY.MM.DD"),
("2025年1月20日", "YYYY年MM月DD日"),
("01-01", "MM-DD"),
("20号", "DD号"),
("13:42:52", "HH:mm:ss"),
("13点半", "HH:mm"),
("今天", "今天是YYYY年MM月DD日"),
("now", "Current time: YYYY-MM-DD HH:mm:ss"),
];
for (input, format_str) in examples {
let result = smart_date_time::format(input, format_str);
println!("Input: {}, Format: {}, Result: {}", input, format_str, result);
}
Roadmap
Completed Features ✅
- v0.1.0: Full multilingual support for 10 languages (Chinese, English, Spanish, French, German, Japanese, Korean, Italian, Portuguese, Russian)
Future Plans 🚀
- v0.2.0: Add language-specific date-time formats (e.g., Spanish date formats, Japanese era names)
- v0.3.0: Add timezone support
- v0.4.0: Add relative date parsing (e.g., "3 days ago", "next week")
- v1.0.0: Advanced localization features and cultural date-time formatting
Dependencies
chrono- Date-time handlingregex- Regular expression matching
Development and Testing
Run tests:
cargo test
Run examples:
cargo run
Contributing
We welcome contributions! If you'd like to help implement support for additional languages or improve existing functionality, please:
- Check our roadmap for planned features
- Open an issue to discuss your proposed changes
- Submit a pull request with your implementation
Issues and Pull Requests are welcome!
License
This project is licensed under the MIT License. See the LICENSE file for details.
Changelog
v0.1.0
- Initial release
- Basic date-time parsing and formatting support
- Full multilingual support for 10 languages:
- 🇨🇳 Chinese (中文): 今天, 现在
- 🇺🇸 English: today, doday, now
- 🇪🇸 Spanish (Español): hoy, ahora
- 🇫🇷 French (Français): aujourd'hui, maintenant
- 🇩🇪 German (Deutsch): heute, jetzt
- 🇯🇵 Japanese (日本語): 今日, 今
- 🇰🇷 Korean (한국어): 오늘, 지금
- 🇮🇹 Italian (Italiano): oggi, ora
- 🇵🇹 Portuguese (Português): hoje, agora
- 🇷🇺 Russian (Русский): сегодня, сейчас
- Fault tolerance mechanism implementation
- Comprehensive test coverage for all supported languages
- Smart keyword recognition and parsing
Dependencies
~2.8–4MB
~69K SLoC