tempotime
A Rust port of Luxon.js with immutable, chainable DateTime operations and IANA timezone support.
Zero external dependencies by default – only std::time for UTC operations. Optionally enable chrono for full timezone support.
use ;
dt
.plus
.start_of
.to_format
Features
- Zero dependencies by default – UTC-only DateTime using
std::time - Immutable operations that return new
DateTimeinstances - Optional IANA timezone support via
chrono-tz - Object-based duration syntax
- Round to start/end of time units
- Luxon-compatible formatting tokens
- Built-in locale presets
- Small footprint (< 100KB binary in zero-deps mode)
Installation
Zero-Deps Mode (UTC only)
[]
= "0.1"
With Timezone Support
[]
= { = "0.1", = ["chrono", "tz"] }
Zero-Deps Mode
By default, tempotime uses only std::time::SystemTime for UTC timestamps, resulting in:
- Tiny binary – ~80KB vs ~2MB with chrono
- Fast compilation – No external dependencies
- Full API – All methods work identically
Limitations
- UTC only (
.set_zone()is a no-op) - Month/year arithmetic uses approximations (30 days/month, 365 days/year)
.local()returns UTC
When to Use
- Microservices that only need UTC timestamps
- CLI tools with strict binary size requirements
- Projects that want minimal dependencies
Feature Comparison
| Feature | Zero-Deps | chrono |
tz |
|---|---|---|---|
| Binary Size | ~80KB | ~2MB | ~2MB |
| Dependencies | 0 | 1 | 2 |
.now() |
✅ | ✅ | ✅ |
.from_iso() |
✅ | ✅ | ✅ |
.to_format() |
✅ | ✅ | ✅ |
.plus()/.minus() |
✅ | ✅ | ✅ |
| Month/year math | ~30d/365d | Accurate | Accurate |
.set_zone() |
No-op | No-op | ✅ |
| Timezones | UTC only | UTC only | IANA |
Usage
Basic Operations
use ;
let now = dt;
let future = now
.plus
.start_of;
println!;
Timezones
// Enable with --features tz
let ny_time = dt
.set_zone
.to_format;
Formatting
let now = dt;
now.to_format;
now.to_locale_string;
now.to_locale_string;
now.to_locale_string;
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 |
M |
10 | Month (no padding) |
dd |
29 | 2-digit day |
d |
29 | Day (no padding) |
do |
29th | Day with ordinal |
EEEE |
Wednesday | Full weekday |
EEE |
Wed | Short weekday |
HH |
14 | 24-hour (padded) |
H |
14 | 24-hour |
hh |
02 | 12-hour (padded) |
h |
2 | 12-hour |
mm |
05 | Minutes (padded) |
ss |
09 | Seconds (padded) |
SSS |
123 | Milliseconds |
a |
pm | AM/PM |
Durations
use Duration;
let dur = from_object;
dur.as_unit;
dur.as_unit;
Intervals
use ;
let start = dt;
let end = start.clone.plus;
let interval = from_date_times;
let check = dt.plus;
interval.contains;
interval.length.as_unit;
Differences
let now = dt;
let past = from_iso.unwrap;
now.diff;
now.diff;
Why tempotime?
vs. chrono
// chrono (verbose)
let dt = now
.checked_add_signed
.unwrap
.format
.to_string;
// tempotime (clean)
let dt = dt
.plus
.to_format;
vs. time
tempotime provides:
- Immutable by default
- Luxon-style formatting
- Object-based durations
- Chainable API
API Reference
DateTime
now .set_zone .plus .minus .start_of // "year", "month", "day", "hour", "minute"
dt.end_of .to_iso .to_format .to_locale_string .diff
Duration
from_object .to_object .as_unit
Interval
from_date_times .contains .length .start .end
Convenience
dt // Alias for DateTime::now()
Features
All features are optional:
[]
= []
= ["dep:chrono"]
= ["chrono", "chrono-tz"]
= ["dep:serde", "chrono?/serde"]
Enable features as needed:
# Zero-deps (default)
= "0.1"
# With chrono (accurate month/year math, still UTC-only)
= { = "0.1", = ["chrono"] }
# With timezones
= { = "0.1", = ["tz"] }
# With serialization
= { = "0.1", = ["serde"] }
Examples
Testing
Contributing
Contributions are welcome. This is a community-driven port of Luxon.js to Rust.
- Fork the repo
- Create a feature branch
- Add tests for new features
- Submit a PR
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Inspiration
This project is a Rust port of Luxon.js, the modern successor to Moment.js.