# 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 format
- `2025/1/20` - Slash-separated format
- `2025.1.20` - Dot-separated format
- `2025年1月20` - Chinese year-month format
- `2025年1月20日` - Chinese complete date format
- `01-01` - Month-day format (uses current year)
- `1.2` - Dot-separated month-day format
- `11.20` - Dot-separated month-day format
- `20号` - Chinese date format
### Time Formats
- `13:42:52` - Complete time format
- `13:42` - Hour-minute format
- `13点` - Chinese hour format
- `13点半` - 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`:
```toml
[dependencies]
smart_date_time = "0.1.0"
```
## Usage
### Basic Usage
```rust
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
```rust
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 handling
- `regex` - Regular expression matching
## Development and Testing
Run tests:
```bash
cargo test
```
Run examples:
```bash
cargo run
```
## Contributing
We welcome contributions! If you'd like to help implement support for additional languages or improve existing functionality, please:
1. Check our [roadmap](#roadmap) for planned features
2. Open an issue to discuss your proposed changes
3. 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](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