Crates.io | simple-datetime-rs |
lib.rs | simple-datetime-rs |
version | 0.2.3 |
created_at | 2025-09-11 13:43:07.49347+00 |
updated_at | 2025-09-17 09:30:38.736023+00 |
description | A high-performance, lightweight date and time library for Rust with dramatically faster parsing, memory-efficient operations, and chrono-compatible formatting |
homepage | https://gitlab.com/Efimster/date |
repository | https://gitlab.com/Efimster/date |
max_upload_size | |
id | 1833874 |
size | 151,930 |
A high-performance, lightweight date and time library for Rust that provides dramatically faster parsing and memory-efficient operations for common date/time tasks.
wasm-bindgen
for WASM)Operation | simple-datetime-rs | chrono | Performance Gain |
---|---|---|---|
Date Parsing | 6.13 ns | 105.41 ns | ð simple-datetime-rs 17.2x faster |
Time Parsing | 7.19 ns | 89.11 ns | ð simple-datetime-rs 12.4x faster |
DateTime Parsing | 43.67 ns | 58.70 ns | ð simple-datetime-rs 1.3x faster |
Operation | simple-datetime-rs | chrono | Memory Advantage |
---|---|---|---|
1000 Date Objects | 1.29 Ξs | N/A | simple-datetime-rs only |
1000 Time Objects | 1.53 Ξs | N/A | simple-datetime-rs only |
1000 DateTime Objects | 3.30 Ξs | 42.43 Ξs | simple-datetime-rs 12.9x more efficient |
Workflow | simple-datetime-rs | chrono | Performance Gain |
---|---|---|---|
Complete Workflow | 610.91 ns | 763.94 ns | simple-datetime-rs 1.25x faster |
use simple_datetime_rs::{DateTime, Format};
let now = DateTime::now();
println!("{}", now.format("%Y-%m-%d %H:%M:%S")?); // "2025-09-17 07:53:14"
println!("{}", now.format("%A, %B %d, %Y at %I:%M %p")?); // "Wednesday, September 17, 2025 at 07:53 AM"
println!("{}", now.format("%+")?); // "2025-09-17T07:53:14Z" (ISO 8601)
%Y
(year), %m
(month), %d
(day), %B
(month name), %A
(weekday)%H
(24-hour), %I
(12-hour), %M
(minute), %S
(second), %f
(microsecond), %p
(AM/PM)%z
(offset), %:z
(offset with colon)%D
(MM/DD/YY), %T
(HH:MM:SS), %F
(YYYY-MM-DD), %+
(ISO 8601)let date = Date::new(2023, 6, 15);
let time = Time::new(14, 30, 45);
let datetime = DateTime::new(date, time, 0);
println!("{}", date.format("%A, %B %d, %Y")?); // "Thursday, June 15, 2023"
println!("{}", time.format("%I:%M %p")?); // "02:30 PM"
println!("{}", datetime.format("%Y-%m-%d %H:%M:%S")?); // "2023-06-15 14:30:45"
wasm-bindgen
for WASM)let date = Date::new(2023, 6, 15);
let day_of_year = date.year_day(); // 166 (June 15th is the 166th day)
let days_remaining = date.days_to_next_year(); // 199 days left in 2023
Why it's unique: Most libraries don't provide direct year day calculation or days remaining functionality.
let q1 = Date::new(2023, 2, 15).quarter(); // 1
let q2 = Date::new(2023, 5, 15).quarter(); // 2
let q3 = Date::new(2023, 8, 15).quarter(); // 3
let q4 = Date::new(2023, 11, 15).quarter(); // 4
Why it's unique: Built-in quarter calculation for business applications.
let date = Date::new(2023, 2, 28);
let is_last_day = date.is_month_last_day(); // true
let last_day = date.month_last_day(); // 2023-02-28
let leap_date = Date::new(2024, 2, 28);
let is_last_day_leap = leap_date.is_month_last_day(); // false
let last_day_leap = leap_date.month_last_day(); // 2024-02-29
Why it's unique: Direct month boundary detection and last day calculation.
// Invalid dates are automatically normalized
let invalid_date = Date::new(2020, 49, 32); // Month 49, Day 32
let normalized = invalid_date.normalize(); // 2024-02-01
let invalid_time = Time::new(25, 70, 80); // Hour 25, Minute 70, Second 80
let normalized_time = invalid_time.normalize(); // 02:10:20
let invalid_dt = DateTime::new(invalid_date, invalid_time, 0);
let normalized_dt = invalid_dt.normalize(); // Properly normalized
Why it's unique: Most libraries throw errors for invalid dates. simple-datetime-rs normalizes them intelligently.
// Convert from MS-DOS 16-bit date format
let date = Date::from_ms_dos_date(0x354b); // 2006-10-11
let time = Time::from_ms_dos_time(0x7d1c); // 15:40:56
// Convert back to MS-DOS format
let ms_dos_date = date.to_ms_dos_date(); // 0x354b
let ms_dos_time = time.to_ms_dos_time(); // 0x7d1c
Why it's unique: No other major date/time library provides MS-DOS format support for legacy system compatibility.
let time = Time::new_with_microseconds(14, 30, 45, 123456);
let microseconds = time.to_microseconds(); // 52545123456
let milliseconds = time.to_milliseconds(); // 52545123
// Automatic normalization with microseconds
let overflow_time = Time::new_with_microseconds(14, 30, 45, 2000000);
let normalized = overflow_time.normalize(); // 14:30:47.000000
Why it's unique: Native microsecond support without external dependencies.
// Works identically on native and WASM
let now = DateTime::now();
let today = Date::today();
// Cross-platform current time
let current_seconds = DateTime::now();
let current_milliseconds = DateTime::now_milliseconds();
Why it's unique: Seamless cross-platform time access without platform-specific code.
let date = Date::new(2023, 6, 15); // Thursday
let is_weekend = date.is_weekend(); // false
let is_weekday = date.is_week_day(); // true
let is_monday = date.is_monday(); // false
let is_thursday = date.is_thursday(); // true
let date = Date::new(2024, 6, 15);
let is_leap = date.leap_year(); // true
let next_leap = date.next_leap_year(); // 2028
let recent_leap = date.recent_leap_year(); // 2024
Why it's unique: Comprehensive weekday and leap year utilities in one place.
let mut dt = DateTime::new(date, time, 0); // UTC
dt.set_shift(120); // UTC+2 (2 hours ahead)
let gmt_time = dt.to_seconds_from_unix_epoch_gmt();
// Timezone-aware comparison
let utc_dt = DateTime::new(date, time, 0);
let est_dt = DateTime::new(date, time, -300); // UTC-5
assert_eq!(utc_dt, est_dt); // Same moment in time
Why it's unique: Simple timezone offset management without complex timezone databases.
let time = Time::new_with_microseconds(14, 30, 45, 123456);
// Various time formats
let full_time = time.to_string(); // "14:30:45.123456"
let short_time = time.to_hh_mm_string(); // "14:30"
let iso_time = time.to_iso_string(); // "14:30:45.123456"
// DateTime formatting
let dt = DateTime::new(date, time, 0);
let iso_dt = dt.to_iso_8061(); // "2023-06-15T14:30:45.123456Z"
let shift_dt = dt.shift_string(); // "Z" or "+02:00"
Why it's unique: Multiple built-in formatting options without external dependencies.
// Many operations avoid allocations
let days = date.to_days(); // Direct calculation
let is_leap = date.leap_year(); // Inline computation
let is_weekend = date.is_weekend(); // Simple modulo operation
// Efficient arithmetic
let future_date = date.add_days(30); // Optimized algorithm
let future_month = date.add_months(6); // Smart month handling
// Creating 1000 dates is extremely memory efficient
let mut dates = Vec::with_capacity(1000);
for i in 0..1000 {
dates.push(Date::new(2023, 6, 15 + (i % 30)));
}
// Only 24KB for 1000 Date objects
// Built-in validation
let valid_date = Date::new(2023, 6, 15);
let is_valid = valid_date.valid(); // true
let invalid_date = Date::new(2023, 2, 30);
let is_invalid = invalid_date.valid(); // false
// Time validation
let valid_time = Time::new(14, 30, 45);
let is_time_valid = valid_time.valid(); // true
let invalid_time = Time::new(25, 0, 0);
let is_time_invalid = invalid_time.valid(); // false
// Clean, readable API
let date = Date::new(2023, 6, 15);
let time = Time::new(14, 30, 45);
let datetime = DateTime::new(date, time, 0);
// Natural arithmetic operations
let future_date = date.add_days(30);
let future_time = time + Time::new(1, 0, 0);
// Many operations avoid unnecessary allocations
let days = date.to_days(); // Direct calculation
let is_leap = date.leap_year(); // Inline computation
let is_weekend = date.is_weekend(); // Simple modulo operation
// Parse from various formats
let date: Date = "2023-06-15".parse()?;
let time: Time = "14:30:45.123456".parse()?;
let datetime: DateTime = "2023-06-15T14:30:45Z".parse()?;
The library includes comprehensive benchmarks comparing performance against chrono and std::time:
# Run performance comparisons
cargo bench --bench performance_comparison
# Generate HTML reports
cargo bench --bench performance_comparison -- --html
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.
simple-datetime-rs provides a compelling alternative to chrono for applications where:
While chrono excels in creation speed and feature completeness, simple-datetime-rs offers dramatic advantages in parsing performance, days arithmetic, and memory usage, making it an excellent choice for high-performance applications and memory-constrained environments.
simple-datetime-rs provides unique functionality that combines:
These features make simple-datetime-rs particularly well-suited for: