Skip to content

replace jiff by chrono. add support for localization of date and time#130

Open
daxcore wants to merge 1 commit intorharish101:mainfrom
daxcore:feature/add-localization-support
Open

replace jiff by chrono. add support for localization of date and time#130
daxcore wants to merge 1 commit intorharish101:mainfrom
daxcore:feature/add-localization-support

Conversation

@daxcore
Copy link
Copy Markdown

@daxcore daxcore commented Sep 27, 2025

Summary

Hey. This pull request replaces the jiff crate with chrono, chrono-tz, and localzone for handling time formatting, time zones, and locale customization in the clock widget. It introduces support for user-specified locales, improving i18n by allowing time display in different languages and regional formats.

Motivation

  • The jiff crate is still limited for localized time formatting.
  • chrono offers a stable API with broad support for date/time formatting using strftime.
  • chrono-tz supports IANA time zones directly.
  • The localzone crate enables automatic detection of the system's time zone.
  • Added locale customization so the clock widget can adapt to the user’s preferred language/region.

This improves internationalization and configurability of the clock component.

Changes

Dependencies

  • Added chrono with unstable-locales feature for localized formatting.
  • Added chrono-tz for IANA timezone parsing.
  • Added localzone for detecting the system’s local timezone.
  • Removed jiff.

Configuration (regreet.sample.toml)

  • Updated the documentation link to chrono’s strftime reference.
  • Added new locale option, allowing users to specify the locale for formatting:
        [widget.clock]
        format = "%a %H:%M"
        timezone = "America/Chicago"
        label_width = 150
        locale = "en_US"
  • This controls language-specific elements (e.g., month, weekday, AM/PM).

Code (widget/clock.rs)

  • Replaced jiff::TimeZone and formatting logic with chrono::Utc, chrono_tz::Tz, and localized formatting (format_localized).
  • Implemented timezone parsing:
    • User-specified timezone (Tz) is preferred.
    • Falls back to system local timezone via localzone.
    • Defaults to UTC if none found.
  • Implemented deserializer for Locale, with validation and fallback behavior.
  • Updated ClockConfig to include locale field.
  • Updated Clock implementation:
    • Current time is updated using Utc::now().with_timezone(...).
    • Formatted using the configured Locale.

Benefits

  • Improved configurability through locales.
  • Consistent formatting with chrono’s ecosystem.
  • Reliable timezone handling with system fallback via localzone.
  • Enhanced internationalization support for multilingual deployments.

@BurntSushi
Copy link
Copy Markdown

The jiff crate is still limited for localized time formatting.

You can use jiff-icu to tie into the icu crate for modern Unicode localized datetime formatting.

Jiff does everything else in your list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants