Expand description
Modern date and time library.
jiff
is a modern date and time library for Rust that prioritizes correctness,
ergonomics, and performance. It provides timezone-aware date arithmetic,
high-precision timestamps, and comprehensive parsing and formatting capabilities.
The library offers several core types:
Timestamp
for nanosecond-precision instants in time,
Zoned
for timezone-aware date-times,
DateTime
for calendar date-times without timezone,
Date
for calendar dates,
and Time
for wall clock times.
Jiff excels at timezone-aware operations and automatically handles daylight saving time transitions correctly. It includes built-in support for the IANA Time Zone Database and provides powerful duration arithmetic that respects calendar rules.
The API design emphasizes preventing common datetime bugs through the type system, making operations like cross-timezone comparisons and DST-aware arithmetic safe by default.
§Examples
Working with timestamps and basic operations:
use jiff::{Timestamp, civil::Date};
// Current timestamp
let now = Timestamp::now();
println!("Now: {}", now);
// Create a specific date
let date = Date::new(2024, 3, 15).unwrap();
println!("Date: {}", date);
// Get Unix timestamp
let unix_seconds = now.as_second();
println!("Unix timestamp: {}", unix_seconds);
// Parse an RFC 3339 timestamp
let parsed: Timestamp = "2024-03-15T14:30:00Z".parse().unwrap();
println!("Parsed: {}", parsed);
Date arithmetic and spans:
use jiff::{civil::Date, ToSpan};
// Create dates
let start = Date::new(2024, 3, 15).unwrap();
let end = Date::new(2024, 12, 25).unwrap();
// Calculate span between dates
let span = start.until(end).unwrap();
println!("Span: {}", span);
// Add one month using ToSpan
let next_month = start.checked_add(1.month()).unwrap();
println!("Next month: {}", next_month);
// Add days
let future = start.checked_add(30.days()).unwrap();
println!("30 days later: {}", future);
Modules§
- _documentation
- Longer form documentation for Jiff.
- civil
- Facilities for dealing with inexact dates and times.
- fmt
- Configurable support for printing and parsing datetimes and durations.
- tz
- Routines for interacting with time zones and the zoneinfo database.
Structs§
- Error
- An error that can occur in this crate.
- Signed
Duration - A signed duration of time represented as a 96-bit integer of nanoseconds.
- Signed
Duration Round - Options for
SignedDuration::round
. - Span
- A span of time represented via a mixture of calendar and clock units.
- Span
Arithmetic - Options for
Span::checked_add
andSpan::checked_sub
. - Span
Compare - Options for
Span::compare
. - Span
Fieldwise - A wrapper for
Span
that implements theHash
,Eq
andPartialEq
traits. - Span
Relative To - A relative datetime for use with
Span
APIs. - Span
Round - Options for
Span::round
. - Span
Total - Options for
Span::total
. - Timestamp
- An instant in time represented as the number of nanoseconds since the Unix epoch.
- Timestamp
Arithmetic - Options for
Timestamp::checked_add
andTimestamp::checked_sub
. - Timestamp
Difference - Options for
Timestamp::since
andTimestamp::until
. - Timestamp
Display With Offset - A type for formatting a
Timestamp
with a specific offset. - Timestamp
Round - Options for
Timestamp::round
. - Timestamp
Series - An iterator over periodic timestamps, created by
Timestamp::series
. - Zoned
- A time zone aware instant in time.
- Zoned
Arithmetic - Options for
Timestamp::checked_add
andTimestamp::checked_sub
. - Zoned
Difference - Options for
Zoned::since
andZoned::until
. - Zoned
Round - Options for
Zoned::round
. - Zoned
With - A builder for setting the fields on a
Zoned
.
Enums§
- Round
Mode - The mode for dealing with the remainder when rounding datetimes or spans.
- Unit
- A way to refer to a single calendar or clock unit.