Skip to content

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

Merged
rharish101 merged 2 commits into
rharish101:mainfrom
daxcore:feature/add-localization-support
Jun 13, 2026
Merged

replace jiff by chrono. add support for localization of date and time#130
rharish101 merged 2 commits into
rharish101:mainfrom
daxcore:feature/add-localization-support

Conversation

@daxcore

@daxcore daxcore commented Sep 27, 2025

Copy link
Copy Markdown
Contributor

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.

@rharish101
rharish101 force-pushed the feature/add-localization-support branch 2 times, most recently from 8f7924a to c6786de Compare May 10, 2026 17:13
@rharish101

Copy link
Copy Markdown
Owner

Thanks for the PR. I rebased it and added fallbacks to system tz/locale if they aren't specified in the config. @daxcore Could you review and test the new changes?

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

Unfortunately, I can't find any easy way to format in icu with a dynamic format string. If the format is fixed, it's pretty straightforward (as jiff-icu shows in its docs), but that's not the case here, as the format is specified by users in the config.

@daxcore

daxcore commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@rharish101 works pretty well for me. thx. built and tested successfully. 👍

@rharish101
rharish101 force-pushed the feature/add-localization-support branch from c6786de to 57cbbdd Compare June 13, 2026 13:37
@rharish101
rharish101 merged commit 17f96d3 into rharish101:main Jun 13, 2026
1 check passed
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.

3 participants