rstime/lib.rs
1//! # rstime
2//!
3//! A zero-dependency enhanced time library for Rust, built using the standard library.
4//!
5//! Provides date, time, datetime types with formatting, parsing, arithmetic,
6//! Unix timestamp conversion, and clock functionality.
7//!
8//! ## Features
9//!
10//! - **Zero Dependencies**: Pure standard library implementation
11//! - **Date & Time Types**: `Date`, `Time`, `DateTime` with validation
12//! - **Duration & TimeDelta**: Positive and signed duration types with arithmetic
13//! - **Custom Formatting**: `{YYYY}`, `{MM}`, `{DD}`, `{HH}`, `{mm}`, `{ss}` token system
14//! - **Parsing**: Parse dates/times from strings with format patterns
15//! - **ISO 8601**: Built-in ISO 8601 parsing and formatting
16//! - **Weekday Calculation**: Zeller's formula for accurate weekday computation
17//! - **Unix Timestamps**: Convert between `DateTime` and Unix timestamps
18//! - **Clock**: System clock and monotonic clock for timing
19//! - **12/24 Hour**: 12-hour clock conversion with AM/PM
20//!
21//! ## Quick Start
22//!
23//! ```rust
24//! use rstime::{Date, Time, DateTime, Duration, TimeFormat};
25//!
26//! // Date handling
27//! let date = Date::new(2026, 5, 10);
28//! println!("{}", date); // 2026-05-10
29//! println!("{}", date.weekday()); // Sunday
30//!
31//! // Time handling
32//! let time = Time::new(14, 5, 9, 0);
33//! println!("{}", time); // 14:05:09
34//!
35//! // Formatting
36//! let dt = DateTime::new(date, time);
37//! println!("{}", dt.format("{YYYY}年{MM}月{DD}日 {HH}:{mm}")); // 2026年05月10日 14:05
38//!
39//! // Clock
40//! let now = DateTime::now();
41//! println!("Now: {}", now);
42//! ```
43//!
44//! ## Custom Format Tokens
45//!
46//! | Token | Description | Example |
47//! |-------|-------------|---------|
48//! | `{YYYY}` | 4-digit year | `2026` |
49//! | `{MM}` | 2-digit month | `05` |
50//! | `{DD}` | 2-digit day | `10` |
51//! | `{HH}` | 24-hour | `14` |
52//! | `{hh}` | 12-hour | `02` |
53//! | `{mm}` | Minutes | `05` |
54//! | `{ss}` | Seconds | `09` |
55//! | `{SSS}` | Milliseconds | `037` |
56//! | `{W}` | Short weekday | `Sun` |
57//! | `{WW}` | Full weekday | `Sunday` |
58//! | `{AMPM}` | Uppercase AM/PM | `PM` |
59//! | `{ampm}` | Lowercase am/pm | `pm` |
60
61pub mod clock;
62pub mod date;
63pub mod datetime;
64pub mod duration;
65pub mod error;
66pub mod format;
67pub mod parse;
68pub mod time;
69
70pub use clock::{Clock, MonotonicClock, SystemClock};
71pub use date::{Date, Weekday};
72pub use datetime::DateTime;
73pub use duration::{Duration, TimeDelta};
74pub use error::{RstimeError, RstimeResult};
75pub use format::TimeFormat;
76pub use parse::{parse_date, parse_datetime, parse_iso8601, parse_time};
77pub use time::Time;