ext-time
A Rust library that extends the time crate with additional useful methods for time manipulation and formatting.
Features
-
Extension methods for
Timetype:- Format time as HH:MM (
to_shorten) - Parse time from HH:MM string (
from_str) - Duration calculation with cross-day handling (
sub_ext) - Time range checks (
is_between) - Minute-based operations (
reset_minute,is_same_minute,add_minutes)
- Format time as HH:MM (
-
Extension methods for
OffsetDateTime:- Timestamp conversions (milliseconds/seconds)
- Timezone-aware formatting (display/Chinese format)
- Parse from various formats (milliseconds, date-time string, simple format)
- Minute-based operations
-
Serde support for
OffsetDateTime:- Serialize to Unix timestamp
- Deserialize from Unix timestamp
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
use *;
use time;
// Time operations
let t = time!;
assert_eq!;
assert!;
let next = t.add_minutes; // Handles midnight wraparound
// OffsetDateTime with timezone
let dt = now_with_offset; // UTC+8
println!; // "2024-03-20 15:30:45.123 +8"
println!; // "2024年03月20日 15时30分45秒 +8"
// Parse from various formats
let dt = from_milliseconds?;
let dt = from_date_time?;
let dt = from_simple?;
// Serde support
Documentation
For detailed documentation and examples, please check the API documentation.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.