| Crates.io | spacecell |
| lib.rs | spacecell |
| version | 0.1.0 |
| created_at | 2025-12-31 00:22:25.575508+00 |
| updated_at | 2025-12-31 00:22:25.575508+00 |
| description | Datetime library with ISO8601/RFC3339 parsing, calendar arithmetic, and business day calculations |
| homepage | |
| repository | |
| max_upload_size | |
| id | 2013668 |
| size | 91,418 |
A lightweight, zero-dependency datetime library for Rust. Provides ISO8601/RFC3339 parsing and formatting, proleptic Gregorian calendar calculations, and business day operations.
Add to your Cargo.toml:
[dependencies]
spacecell = "0.1"
use spacecell::{parse_iso8601, format_iso8601};
// Parse ISO8601 datetime
let (timestamp, unit) = parse_iso8601("2024-06-15T14:30:00.123Z").unwrap();
// Format back to string
let formatted = format_iso8601(timestamp, unit);
assert_eq!(formatted, "2024-06-15T14:30:00.123Z");
use spacecell::{ymd_to_days, days_to_ymd, is_leap_year, days_in_month};
// Convert date to days since Unix epoch
let days = ymd_to_days(2024, 6, 15);
// Convert back to year/month/day
let (year, month, day) = days_to_ymd(days);
assert_eq!((year, month, day), (2024, 6, 15));
// Leap year detection
assert!(is_leap_year(2024));
assert!(!is_leap_year(2023));
// Days in a month
assert_eq!(days_in_month(2024, 2), 29); // Leap year
assert_eq!(days_in_month(2023, 2), 28);
use spacecell::{
CalendarConfig, add_business_days, count_business_days,
next_business_day, is_business_day,
};
// Create a calendar with holidays
let config = CalendarConfig::new()
.add_holiday(2024, 12, 25) // Christmas
.add_holiday(2024, 12, 26); // Boxing Day
// Add business days (skips weekends and holidays)
let (y, m, d) = add_business_days(2024, 12, 23, 3, &config);
// Skips Sat 24, Sun 25 (also holiday), Thu 26 (holiday)
// Count business days in a range
let count = count_business_days(2024, 12, 1, 2024, 12, 31, &config);
// Find next business day
let (y, m, d) = next_business_day(2024, 12, 24, &config);
use spacecell::TimeDelta;
let delta = TimeDelta::hours(25);
assert_eq!(delta.total_seconds(), 90_000);
let d1 = TimeDelta::days(3);
let d2 = TimeDelta::hours(12);
let sum = d1 + d2;
Date calculations use Howard Hinnant's public domain algorithms for efficient, loop-free conversions between calendar dates and day counts.
Licensed under either of:
at your option.