spacecell
A lightweight, zero-dependency datetime library for Rust. Provides ISO8601/RFC3339 parsing and formatting, proleptic Gregorian calendar calculations, and business day operations.
Features
- Zero dependencies - No external crates required
- Proleptic Gregorian calendar - Correct handling of dates before 1582
- ISO 8601 / RFC 3339 - Parse and format standard datetime strings
- Precision support - Seconds, milliseconds, microseconds, and nanoseconds
- Calendar arithmetic - Add/subtract days, weeks, months, years
- Business day calculations - Weekend and holiday-aware date arithmetic
- ISO week numbering - Week-based year calculations
- Fiscal calendar support - Quarters, half-years, fiscal years
Installation
Add to your Cargo.toml:
[]
= "0.1"
Usage
Parsing and Formatting
use ;
// Parse ISO8601 datetime
let = parse_iso8601.unwrap;
// Format back to string
let formatted = format_iso8601;
assert_eq!;
Calendar Operations
use ;
// Convert date to days since Unix epoch
let days = ymd_to_days;
// Convert back to year/month/day
let = days_to_ymd;
assert_eq!;
// Leap year detection
assert!;
assert!;
// Days in a month
assert_eq!; // Leap year
assert_eq!;
Business Day Calculations
use ;
// Create a calendar with holidays
let config = new
.add_holiday // Christmas
.add_holiday; // Boxing Day
// Add business days (skips weekends and holidays)
let = add_business_days;
// Skips Sat 24, Sun 25 (also holiday), Thu 26 (holiday)
// Count business days in a range
let count = count_business_days;
// Find next business day
let = next_business_day;
Time Deltas
use TimeDelta;
let delta = hours;
assert_eq!;
let d1 = days;
let d2 = hours;
let sum = d1 + d2;
Algorithms
Date calculations use Howard Hinnant's public domain algorithms for efficient, loop-free conversions between calendar dates and day counts.
Licence
Licensed under either of:
- Apache Licence, Version 2.0 (LICENCE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT licence (LICENCE-MIT or http://opensource.org/licenses/MIT)
at your option.