Skip to main content

Crate rstime

Crate rstime 

Source
Expand description

§rstime

A zero-dependency enhanced time library for Rust, built using the standard library.

Provides date, time, datetime types with formatting, parsing, arithmetic, Unix timestamp conversion, and clock functionality.

§Features

  • Zero Dependencies: Pure standard library implementation
  • Date & Time Types: Date, Time, DateTime with validation
  • Duration & TimeDelta: Positive and signed duration types with arithmetic
  • Custom Formatting: {YYYY}, {MM}, {DD}, {HH}, {mm}, {ss} token system
  • Parsing: Parse dates/times from strings with format patterns
  • ISO 8601: Built-in ISO 8601 parsing and formatting
  • Weekday Calculation: Zeller’s formula for accurate weekday computation
  • Unix Timestamps: Convert between DateTime and Unix timestamps
  • Clock: System clock and monotonic clock for timing
  • 12/24 Hour: 12-hour clock conversion with AM/PM

§Quick Start

use rstime::{Date, Time, DateTime, Duration, TimeFormat};

// Date handling
let date = Date::new(2026, 5, 10);
println!("{}", date);                    // 2026-05-10
println!("{}", date.weekday());          // Sunday

// Time handling
let time = Time::new(14, 5, 9, 0);
println!("{}", time);                    // 14:05:09

// Formatting
let dt = DateTime::new(date, time);
println!("{}", dt.format("{YYYY}年{MM}月{DD}日 {HH}:{mm}")); // 2026年05月10日 14:05

// Clock
let now = DateTime::now();
println!("Now: {}", now);

§Custom Format Tokens

TokenDescriptionExample
{YYYY}4-digit year2026
{MM}2-digit month05
{DD}2-digit day10
{HH}24-hour14
{hh}12-hour02
{mm}Minutes05
{ss}Seconds09
{SSS}Milliseconds037
{W}Short weekdaySun
{WW}Full weekdaySunday
{AMPM}Uppercase AM/PMPM
{ampm}Lowercase am/pmpm

Re-exports§

pub use clock::Clock;
pub use clock::MonotonicClock;
pub use clock::SystemClock;
pub use date::Date;
pub use date::Weekday;
pub use datetime::DateTime;
pub use duration::Duration;
pub use duration::TimeDelta;
pub use error::RstimeError;
pub use error::RstimeResult;
pub use format::TimeFormat;
pub use parse::parse_date;
pub use parse::parse_datetime;
pub use parse::parse_iso8601;
pub use parse::parse_time;
pub use time::Time;

Modules§

clock
Clock module
date
Date module
datetime
DateTime module
duration
Duration module
error
Error type module
format
Format module
parse
Parse module
time
Time module