Module jiff
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 ;
// Current timestamp
let now = now;
println!;
// Create a specific date
let date = new.unwrap;
println!;
// Get Unix timestamp
let unix_seconds = now.as_second;
println!;
// Parse an RFC 3339 timestamp
let parsed: Timestamp = "2024-03-15T14:30:00Z".parse.unwrap;
println!;
Date arithmetic and spans:
use ;
// Create dates
let start = new.unwrap;
let end = new.unwrap;
// Calculate span between dates
let span = start.until.unwrap;
println!;
// Add one month using ToSpan
let next_month = start.checked_add.unwrap;
println!;
// Add days
let future = start.checked_add.unwrap;
println!;
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.