Crates.io | ext-time |
lib.rs | ext-time |
version | |
source | src |
created_at | 2025-02-01 10:24:21.44248+00 |
updated_at | 2025-02-05 08:55:49.406649+00 |
description | A Rust library that extends the time crate with additional useful methods for time manipulation and formatting |
homepage | |
repository | https://github.com/rain2307/ext-time |
max_upload_size | |
id | 1538336 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A Rust library that extends the time crate with additional useful methods for time manipulation and formatting.
Extension methods for Time
type:
to_shorten
)from_str
)sub_ext
)is_between
)reset_minute
, is_same_minute
, add_minutes
)Extension methods for OffsetDateTime
:
Serde support for OffsetDateTime
:
Add this to your Cargo.toml
:
[dependencies]
ext-time = "0.1.0"
use ext_time::prelude::*;
use time::macros::time;
// Time operations
let t = time!(23:30);
assert_eq!(t.to_shorten(), "23:30");
assert!(t.is_between(time!(23:00), time!(0:00)));
let next = t.add_minutes(40); // Handles midnight wraparound
// OffsetDateTime with timezone
let dt = OffsetDateTime::now_with_offset(8); // UTC+8
println!("{}", dt.to_display_string(8)); // "2024-03-20 15:30:45.123+08:00"
println!("{}", dt.to_chinese_string()); // "2024年03月20日 15时30分45秒 +8"
// Parse from various formats
let dt = OffsetDateTime::from_milliseconds(1694696340500, 8)?;
let dt = OffsetDateTime::from_date_time("20240320", "15:30:45", 123, 8)?;
let dt = OffsetDateTime::from_simple("20240320_1530", 8)?;
// Serde support
#[derive(Serialize, Deserialize)]
struct Event {
#[serde(serialize_with = "serde_t2ts", deserialize_with = "serde_parse_ts")]
timestamp: OffsetDateTime,
}
For detailed documentation and examples, please check the API documentation.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.