Framework for embedding localizations into Rust types
//! Example showing how to localize Jiff timestamps

use icu_locale::{Locale, locale};
use jiff::{Timestamp, ToSpan};
use l10n_embed::Localize;

const DEFAULT_LOCALE: Locale = locale!("en-US");

fn main() -> 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
    println!(
        "Current time: {}",
        current_timestamp.localize_for(&DEFAULT_LOCALE)
    );
    println!("Unix epoch: {}", unix_epoch.localize_for(&DEFAULT_LOCALE));
    println!(
        "Two hours from now: {}",
        in_two_hours.localize_for(&DEFAULT_LOCALE)
    );
    println!(
        "Since start of year (UTC): {}",
        start_of_year.localize_for(&DEFAULT_LOCALE)
    );

    Ok(())
}