Skip to content

Add timezone support to date extension (#2225) - #2526

Merged
AucaCoyan merged 4 commits into
espanso:devfrom
gcailly:feature/2225-add-timezone-support
Oct 11, 2025
Merged

AucaCoyan merged 4 commits into
espanso:devfrom
gcailly:feature/2225-add-timezone-support

Conversation

@gcailly

@gcailly gcailly commented Oct 11, 2025

Copy link
Copy Markdown
Contributor

Allow users to format dates in different timezones using the optional 'tz' parameter. Supports IANA timezone names (e.g., UTC, America/New_York, Europe/Paris) and falls back to local time for invalid timezones.

  • Added chrono-tz dependency to espanso-render/Cargo.toml.
  • Modified date.rs to support timezone conversion via new tz parameter.
  • Added helper function format_date_with_locale_and_tz() for timezone-aware formatting.
  • Added 3 new unit tests covering UTC, named timezones, and invalid timezone fallback.

Fixes #2225

@gcailly
gcailly requested a review from AucaCoyan as a code owner October 11, 2025 12:17
@gcailly
gcailly force-pushed the feature/2225-add-timezone-support branch from dd40f22 to 07c7a4c Compare October 11, 2025 12:21
Allow users to format dates in different timezones using the optional
'tz' parameter. Supports IANA timezone names (e.g., UTC, America/New_York,
Europe/Paris) and falls back to local time for invalid timezones.

- Add chrono-tz dependency for timezone support
- Implement timezone conversion in date extension
- Add error handling for invalid date formats (compatible with espanso#2516)
- Add tests for UTC, named timezones, and invalid timezone fallback
@gcailly
gcailly force-pushed the feature/2225-add-timezone-support branch from 07c7a4c to 7d0f404 Compare October 11, 2025 12:51
@AucaCoyan

Copy link
Copy Markdown
Collaborator

I like this! I think it need a tiny bit more before merging:

  • we are adding a key to the date extension, tz I would like to add that to the config parsed
  • and also the json schema

I test it and it worked a bit slowly, but it may well be because I'm having too many proceses in my PC.

I'm going to skip this merge with the upcoming release, and merge after 👌🏼 .
Thank you for your contribution!

@smeech

smeech commented Oct 11, 2025

Copy link
Copy Markdown
Collaborator

I'm pleased to see this. It'll render my time-zone Gist obsolete!

A suggestion for the future: Would it be possible to reconfigure espanso-render/src/extension/date.rs to accept Espanso {{variablel}} offsets, as well as integers?

@gcailly

gcailly commented Oct 11, 2025

Copy link
Copy Markdown
Contributor Author

@AucaCoyan I added modifications to adress this when I saw your comment.

@AucaCoyan

Copy link
Copy Markdown
Collaborator

Thank you!
Now that you added the TZs, got me thinking that we can do a BIG enum with all the TZs avaliable. I'll do that and push a commit here

@AucaCoyan

Copy link
Copy Markdown
Collaborator

Done! ~600 TZs added

@AucaCoyan

Copy link
Copy Markdown
Collaborator

It works! 🎉 🚀

image

(it's 11:30 on Argentina now)

Thank you so much @gcailly !

@AucaCoyan

Copy link
Copy Markdown
Collaborator

Note that format overrides locale. The latter only works when there is no format restricting the output

  - trigger: ":today"
    replace: "{{mytime}}"
    vars:
      - name: mytime
        type: date
        params:
          format: "%H:%M"
          locale: en-AG
          tz: America/Los_Angeles

07:33

        params:
          format: "%H:%M"
          locale: en-AG
          tz: America/Los_Angeles

Sat, 11 Oct 2025 07:33:49 -0700

...

Apparently there is some missbehaviour with locales and languages:

        params:
          tz: America/Argentina/Buenos_Aires

or

        params:
          locale: es-AR
          tz: America/Argentina/Buenos_Aires

both prints Sat, 11 Oct 2025 11:37:32 -0300 (in english)
I wonder if it tracks my system locale (en-US) before taking the locale key. But that's a different issue that this pr doesn't want to solve

@AucaCoyan
AucaCoyan merged commit 61f4ecd into espanso:dev Oct 11, 2025
@smeech smeech mentioned this pull request Oct 11, 2025
53 of 56 tasks
@gcailly

gcailly commented Oct 11, 2025

Copy link
Copy Markdown
Contributor Author

@smeech #2529 🙂

sboldt1978 pushed a commit to sboldt1978/espanso that referenced this pull request Feb 11, 2026
* Add timezone support to date extension (espanso#2225)

Allow users to format dates in different timezones using the optional
'tz' parameter. Supports IANA timezone names (e.g., UTC, America/New_York,
Europe/Paris) and falls back to local time for invalid timezones.

- Add chrono-tz dependency for timezone support
- Implement timezone conversion in date extension
- Add error handling for invalid date formats (compatible with espanso#2516)
- Add tests for UTC, named timezones, and invalid timezone fallback

* Add tz parameter to date extension JSON schema (espanso#2225)

* move deps into the workspace

* add enum of timezones

---------
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.

Add "time zone" parameter to date extension

3 participants