Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gcalcli/argparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'given',
},
'--locale': {'default': '', 'type': str, 'help': 'System locale'},
'--timezone': {'default': '', 'type': str, 'help': 'Timezone to use'},
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The --timezone help text is quite generic, and users may not know what format is expected (e.g., IANA tzdb name like America/Los_Angeles). Clarifying the expected timezone identifier (and any platform caveats) in the option help would make the flag easier to use and reduce invalid-value failures.

Suggested change
'--timezone': {'default': '', 'type': str, 'help': 'Timezone to use'},
'--timezone': {
'default': '',
'type': str,
'help': "Timezone to use (IANA tzdb name, e.g. 'America/Los_Angeles')",
},

Copilot uses AI. Check for mistakes.
'--refresh': {
'action': 'store_true',
'dest': 'refresh_cache',
Expand Down
5 changes: 5 additions & 0 deletions gcalcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import re
import signal
import sys
import time
from argparse import ArgumentTypeError
from collections import namedtuple

Expand Down Expand Up @@ -226,6 +227,10 @@ def main():
except ValueError as exc:
printer.err_msg(str(exc))

if parsed_args.timezone:
os.environ['TZ'] = parsed_args.timezone
time.tzset()
Comment on lines +230 to +232
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

This new global timezone behavior isn’t covered by tests. Adding a test that passes --timezone and asserts the TZ override is applied (e.g., os.environ['TZ'] set and time.tzset invoked via monkeypatch, plus at least one time-parsing path producing the expected offset) would help prevent regressions.

Copilot uses AI. Check for mistakes.
Comment on lines +230 to +232
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

--timezone is applied after argparse has already converted date/time arguments (e.g., via utils.get_time_from_str() / tzlocal()), so values like start/end may be interpreted in the system timezone instead of the requested one. To make the flag effective, apply the TZ override (and any needed tzset) before any parsing/type conversion that depends on local time (e.g., by doing a minimal pre-parse for --timezone / config defaults, setting TZ, then running the full parser).

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

time.tzset() is not available on all platforms (notably Windows) and can also fail for invalid TZ values, which would currently crash the CLI. Consider guarding with hasattr(time, 'tzset') and handling AttributeError/OSError to emit a clear error message (and non-zero exit) when the timezone cannot be applied.

Suggested change
time.tzset()
if hasattr(time, 'tzset'):
try:
time.tzset()
except (AttributeError, OSError) as exc:
printer.err_msg(
f"Failed to apply timezone '{parsed_args.timezone}': {exc}"
)
sys.exit(1)
else:
printer.err_msg(
"Setting timezone via the TZ environment variable is not "
"supported on this platform."
)
sys.exit(1)

Copilot uses AI. Check for mistakes.

cal_names = set_resolved_calendars(parsed_args, printer=printer)

userless_mode = bool(os.environ.get('GCALCLI_USERLESS_MODE'))
Expand Down