//! Example showing how to localize Jiff timestamps
useicu_locale::locale;usejiff::{Timestamp, ToSpan};usel10n_embed::{Context, Localize};fnmain()->Result<(), jiff::Error>{// Create some timestamps
let current_timestamp =Timestamp::now();let current_datetime = current_timestamp.in_tz("UTC")?;let unix_epoch =Timestamp::UNIX_EPOCH;let in_two_hours = current_timestamp.checked_add(2.hours())?;let start_of_year = current_datetime.first_of_year()?.timestamp();// Localize those timestamps into a relative time
let timestamps:[(&str, Timestamp);4]=[("Current time", current_timestamp),("Unix epoch", unix_epoch),("Two hours from now", in_two_hours),("Since start of year (UTC)", start_of_year),];let context =Context::new(locale!("en-US"),true);letmut buffer =String::new();for(name, timestamp)in timestamps {
buffer.clear();
timestamp.localize(&context,&mut buffer);println!("{name}: {buffer}");}Ok(())}