-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add global --timezone option #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||
| import signal | ||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||
| from argparse import ArgumentTypeError | ||||||||||||||||||||||||||||||||
| from collections import namedtuple | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -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
|
||||||||||||||||||||||||||||||||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
--timezonehelp text is quite generic, and users may not know what format is expected (e.g., IANA tzdb name likeAmerica/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.