Skip to content

Fix locale ISO datetime parsing - #1471

Open
nkgotcode wants to merge 3 commits into
pimutils:masterfrom
nkgotcode:fix/khal-iso8601-locale-datetime
Open

nkgotcode wants to merge 3 commits into
pimutils:masterfrom
nkgotcode:fix/khal-iso8601-locale-datetime

Conversation

@nkgotcode

@nkgotcode nkgotcode commented Jun 18, 2026 •

Copy link
Copy Markdown

Fixes #1469.

This updates locale datetime parsing so composite locale directives are expanded through locale.nl_langinfo() before parsing. It also accepts the ISO-like %c form produced by locales such as en_DK.utf8 when the formatted value has an empty %Z timezone field.

The regression test covers a locale-provided datetime format of %Y-%m-%dT%T %Z with an input value that omits the timezone name.

Validation:

. .venv-oss1856/bin/activate && py.test tests/parse_datetime_test.py -q
# 54 passed, 14 warnings
. .venv-oss1856/bin/activate
TMPDIR=$(mktemp -d)
mkdir -p "$TMPDIR/calendar" "$TMPDIR/cache"
CONFIG="$TMPDIR/config"
printf '%s\n' '[calendars]' '  [[default]]' "    path = $TMPDIR/calendar" '    color = dark magenta' '' '[locale]' 'local_timezone = Europe/Paris' 'default_timezone = Europe/Paris' '' '[sqlite]' "path = $TMPDIR/cache/khal.db" > "$CONFIG"
env -u LC_ALL LANG=en_US.utf8 LC_TIME=en_DK.utf8 khal -c "$CONFIG" printformats
env -u LC_ALL LANG=en_US.utf8 LC_TIME=en_DK.utf8 khal -c "$CONFIG" at '2026-05-14T12:00:00'
# exit 0; no critical parse error

Review update

Rebased onto current master; empty %z and %Z fields are both supported. Expanded POSIX %T formats now parse portably, and event-description tokens are preserved.

Validation: 55 parser tests and changed-file Ruff checks pass. Full suite: 338 passed, 4 failed; the same four locale/UI tests fail on unmodified upstream in this macOS environment.

Comment thread khal/parse_datetime.py Outdated
Comment on lines +58 to +61
if "%Z" in expanded_format:
without_timezone = expanded_format.replace(" %Z", "").replace("%Z", "").strip()
if without_timezone not in candidates:
candidates.append(without_timezone)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also handle %z?

@nkgotcode
nkgotcode force-pushed the fix/khal-iso8601-locale-datetime branch from bb119c7 to 60ff82d Compare October 13, 2026 02:52
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.

Khal cannot parse ISO8601 from system default

2 participants