Skip to content

fix: format Notes/Agenda/Reminders dates using OS locale#8

Open
adutton wants to merge 1 commit into
benmaster82:mainfrom
adutton:use-os-locale-for-datetime-formats
Open

fix: format Notes/Agenda/Reminders dates using OS locale#8
adutton wants to merge 1 commit into
benmaster82:mainfrom
adutton:use-os-locale-for-datetime-formats

Conversation

@adutton
Copy link
Copy Markdown

@adutton adutton commented May 14, 2026

Summary

  • Dates in the Notes/Agenda/Reminders window were hardcoded to dd/MM/yyyy HH:mm, which doesn't match users whose OS region uses a different short-date format (e.g. yyyy-MM-dd).
  • main.py now calls locale.setlocale(LC_TIME, "") once at startup so strftime("%x") / strftime("%X") follow the OS region settings.
  • Notes/Agenda/Reminders cards now render dates via a small _format_dt_os helper that uses %x %X and strips seconds (the original UI didn't show them).

Test plan

  • Launch the app, open the Notes window
  • Verify each tab (Notes, Agenda, Reminders) renders dates in your OS short-date format
  • Verify times render without seconds
  • Change OS region settings (e.g. to a different short-date pattern), restart, confirm formatting follows
image

@benmaster82
Copy link
Copy Markdown
Owner

Thanks for the PR! Locale-aware date formatting is a nice improvement, definitely better than hardcoded %d/%m/%Y for everyone.

I have a couple of concerns before merging though:

1. locale.setlocale() is not thread-safe

WritHer runs multiple threads (dictation worker, assistant worker, hotkey listener, reminder scheduler). Python's docs explicitly warn that setlocale() affects the entire process and is not safe to call in multi-threaded applications. This could cause intermittent crashes or garbled output that's very hard to reproduce.

2. Conflicts with the existing i18n system

WritHer already has config.LANGUAGE + locales.py to control the user-facing language. Using the OS locale introduces a second, independent source of truth. A user with Windows set to English but WritHer set to Italian would see dates formatted in English inside the Notes window, that's inconsistent.

3. setlocale() in main.py is a side-effect in the wrong place

main.py doesn't do any date formatting itself. The locale call there is a global side-effect that affects the whole process just to serve notes_window.py. That's fragile.

What I'd suggest instead

  • Remove locale.setlocale() entirely, don't touch the global locale
  • Keep the formatting logic local to notes_window.py (where it's actually used)
  • Base the date format on config.LANGUAGE instead of the OS locale

Something simple like:

def _format_dt(dt: datetime) -> str:
    if config.LANGUAGE == "it":
        return dt.strftime("%d/%m/%Y  %H:%M")
    return dt.strftime("%Y-%m-%d  %H:%M")  # ISO-ish for EN and others

This stays consistent with the rest of the app, is thread-safe, and easy to extend when new languages are added.

The seconds-stripping logic is fine to keep, I agree that seconds are noise in this UI.

Would you be okay reworking it along these lines? Happy to help if you have questions. Thanks again for the contribution!

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