⏰ Tempotime
A Luxon.js-inspired datetime library for Rust with zero dependencies by default.
Tempotime brings the elegant, immutable, and chainable API of Luxon.js to Rust, while offering unique advantages like optional zero-dependency operation for UTC-only use cases.
use ;
let result = dt
.plus
.start_of
.to_format;
println!;
// Output: "November 16th, 2025 at 12:00 am"
✨ Features
🚀 Zero Dependencies by Default
Use only std::time for UTC operations – no external crates required. Perfect for microservices, CLI tools, and fast compilation.
🔒 Immutable by Design
All operations return new instances, preventing common date manipulation bugs.
⛓️ Fluent & Chainable
Write clean, readable date manipulation code with method chaining.
🌍 Optional Timezone Support
Enable IANA timezone database when you need it with the tz feature.
📝 Luxon-Compatible Formatting
Familiar, intuitive token-based formatting inspired by Luxon.js.
📦 Tiny Binary Footprint
- Zero-deps mode: ~175 KB
- With timezone support: ~2 MB
📥 Installation
Add to your Cargo.toml:
# Zero-deps mode (UTC only, minimal binary size)
[]
= "0.1"
Feature Flags
# Accurate month/year arithmetic
= { = "0.1", = ["chrono"] }
# Full IANA timezone support
= { = "0.1", = ["tz"] }
# JSON serialization
= { = "0.1", = ["serde"] }
# All features
= { = "0.1", = ["tz", "serde"] }
🚀 Quick Start
use ;
// Get current time
let now = dt;
// Parse from ISO 8601
let date = from_iso.unwrap;
// Add/subtract durations
let tomorrow = now.plus;
let last_week = now.minus;
// Format output
println!;
Chainable Operations
use ;
let result = dt
.plus
.start_of
.to_format;
println!; // "Saturday, November 2nd"
📖 Core API
DateTime
// Creation
now // Current UTC time
from_iso // Parse ISO 8601
from_format // Parse custom format
// Manipulation
dt.plus // Add duration
dt.minus // Subtract duration
dt.start_of // Round down
dt.end_of // Round up
dt.set_zone // Convert timezone
// Formatting
dt.to_iso // ISO 8601 string
dt.to_format // Custom format
dt.to_locale_string // Locale preset
// Comparison
dt.diff // Difference in days
dt > other_dt // Compare dates
Duration
let dur = from_object;
dur.as_unit // Convert to days
dur.to_object // Export as HashMap
Interval
use ;
let start = dt;
let end = start.clone.plus;
let interval = from_date_times;
interval.contains // Check if in range
interval.length.as_unit // Get length
🎨 Format Tokens
| Token | Output | Description |
|---|---|---|
yyyy |
2025 | 4-digit year |
yy |
25 | 2-digit year |
MMMM |
October | Full month name |
MMM |
Oct | Short month name |
MM |
10 | 2-digit month |
dd |
30 | 2-digit day |
do |
30th | Day with ordinal |
EEEE |
Wednesday | Full weekday |
EEE |
Wed | Short weekday |
HH |
14 | 24-hour (padded) |
hh |
02 | 12-hour (padded) |
mm |
30 | Minutes |
ss |
05 | Seconds |
SSS |
123 | Milliseconds |
a |
pm | AM/PM |
'text' |
text | Literal text |
Examples
let dt = dt;
dt.to_format; // "2025-10-30"
dt.to_format; // "October 30th, 2025"
dt.to_format; // "Wednesday at 2:30 pm"
🎯 Zero-Deps Mode
By default, Tempotime uses only std::time::SystemTime for UTC timestamps.
✅ Advantages
- Zero external dependencies
- Fast compilation (~2-3 seconds)
- Tiny binary (~175 KB)
- Full API compatibility
⚠️ Limitations
- UTC only
- Approximate month/year math
- No DST support
.local()returns UTC
When to Upgrade
Enable features when you need:
- ✓ Accurate month/year arithmetic (
chrono) - ✓ Timezone conversions (
tz) - ✓ DST handling (
tz)
🆚 Comparison with Other Libraries
vs. chrono
chrono:
use ;
let dt = now
.checked_add_signed
.unwrap
.format
.to_string;
tempotime:
use ;
let dt = dt
.plus
.to_format;
vs. time
Tempotime provides:
- ✓ Immutable-by-default design
- ✓ Luxon-style formatting
- ✓ Object-based durations
- ✓ More chainable API
- ✓ Optional zero-dependency mode
📊 Feature Comparison
| Feature | Zero-Deps | chrono |
tz |
|---|---|---|---|
| Binary Size | ~175 KB | ~2 MB | ~2 MB |
| Dependencies | 0 | 1 | 2 |
| Compilation | ~2-3s | ~15-20s | ~25-30s |
| UTC Operations | ✅ | ✅ | ✅ |
| Month/Year Math | ~30d/365d | Accurate | Accurate |
| Timezones | UTC only | UTC only | IANA (600+) |
| DST Support | ❌ | ❌ | ✅ |
📚 Examples
Run the included examples:
# Basic demo
# Timezone example
# Zero-deps demonstration
🧪 Testing
# Run tests (zero-deps mode)
# Run tests with all features
# Run benchmarks
🤝 Contributing
Contributions are welcome! This is a community-driven port of Luxon.js to Rust.
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
📜 License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
🙏 Acknowledgments
This project is inspired by Luxon.js, the modern successor to Moment.js.
🔗 Links
- 📦 Crates.io: https://crates.io/crates/tempotime
- 📖 Documentation: https://docs.rs/tempotime
- 🐙 GitHub: https://github.com/hyoussef07/tempotime
- 🌟 Luxon.js: https://moment.github.io/luxon/
⭐ If you find Tempotime useful, please consider giving it a star on GitHub! ⭐
Made with ❤️ for the Rust community