-
Notifications
You must be signed in to change notification settings - Fork 95
Address some warnings #6640
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
base: master
Are you sure you want to change the base?
Address some warnings #6640
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from calendar import timegm | ||||||||||||||||||||||||||||||
| from datetime import datetime, timedelta, timezone | ||||||||||||||||||||||||||||||
| from typing import Optional, Tuple | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| from metomi.isodatetime.timezone import ( | ||||||||||||||||||||||||||||||
| get_local_time_zone_format, get_local_time_zone, TimeZoneFormatMode) | ||||||||||||||||||||||||||||||
|
|
@@ -42,10 +43,7 @@ | |||||||||||||||||||||||||||||
| TIME_ZONE_STRING_LOCAL_EXTENDED = get_local_time_zone_format( | ||||||||||||||||||||||||||||||
| TimeZoneFormatMode.extended) | ||||||||||||||||||||||||||||||
| TIME_ZONE_STRING_UTC = "Z" | ||||||||||||||||||||||||||||||
| TIME_ZONE_UTC_UTC_OFFSET = (0, 0) | ||||||||||||||||||||||||||||||
| TIME_ZONE_LOCAL_UTC_OFFSET = get_local_time_zone() | ||||||||||||||||||||||||||||||
| TIME_ZONE_LOCAL_UTC_OFFSET_HOURS = TIME_ZONE_LOCAL_UTC_OFFSET[0] | ||||||||||||||||||||||||||||||
| TIME_ZONE_LOCAL_UTC_OFFSET_MINUTES = TIME_ZONE_LOCAL_UTC_OFFSET[1] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| TIME_ZONE_LOCAL_INFO = { | ||||||||||||||||||||||||||||||
| "hours": TIME_ZONE_LOCAL_UTC_OFFSET[0], | ||||||||||||||||||||||||||||||
|
|
@@ -55,8 +53,8 @@ | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| TIME_ZONE_UTC_INFO = { | ||||||||||||||||||||||||||||||
| "hours": TIME_ZONE_UTC_UTC_OFFSET[0], | ||||||||||||||||||||||||||||||
| "minutes": TIME_ZONE_UTC_UTC_OFFSET[1], | ||||||||||||||||||||||||||||||
| "hours": 0, | ||||||||||||||||||||||||||||||
| "minutes": 0, | ||||||||||||||||||||||||||||||
| "string_basic": TIME_ZONE_STRING_UTC, | ||||||||||||||||||||||||||||||
| "string_extended": TIME_ZONE_STRING_UTC | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
@@ -74,8 +72,9 @@ | |||||||||||||||||||||||||||||
| _FLAGS['utc_mode'] = bool(mode) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def now(override_use_utc=None): | ||||||||||||||||||||||||||||||
| """Return a current-time datetime.datetime and a UTC timezone flag. | ||||||||||||||||||||||||||||||
| def now(override_use_utc: Optional[bool] = None) -> Tuple[datetime, bool]: | ||||||||||||||||||||||||||||||
| """Return a current-time, timezone-aware datetime.datetime and a flag | ||||||||||||||||||||||||||||||
| indicating whether it is UTC or not. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Keyword arguments: | ||||||||||||||||||||||||||||||
| override_use_utc (default None) - a boolean (or None) that, if | ||||||||||||||||||||||||||||||
|
|
@@ -85,9 +84,9 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| if override_use_utc or (override_use_utc is None and _FLAGS['utc_mode']): | ||||||||||||||||||||||||||||||
| return datetime.utcnow(), False | ||||||||||||||||||||||||||||||
| return datetime.now(timezone.utc), False | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| return datetime.now(), True | ||||||||||||||||||||||||||||||
| return datetime.now().astimezone(), True | ||||||||||||||||||||||||||||||
oliver-sanders marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_current_time_string(display_sub_seconds=False, override_use_utc=None, | ||||||||||||||||||||||||||||||
|
|
@@ -113,9 +112,13 @@ | |||||||||||||||||||||||||||||
| use_basic_format=use_basic_format) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_time_string(date_time, display_sub_seconds=False, | ||||||||||||||||||||||||||||||
| override_use_utc=None, use_basic_format=False, | ||||||||||||||||||||||||||||||
| date_time_is_local=False, custom_time_zone_info=None): | ||||||||||||||||||||||||||||||
| def get_time_string( | ||||||||||||||||||||||||||||||
| date_time: datetime, | ||||||||||||||||||||||||||||||
| display_sub_seconds: bool = False, | ||||||||||||||||||||||||||||||
| override_use_utc: Optional[bool] = None, | ||||||||||||||||||||||||||||||
| use_basic_format: bool = False, | ||||||||||||||||||||||||||||||
| date_time_is_local: bool = False, | ||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||
| """Return a string representing the current system time. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Arguments: | ||||||||||||||||||||||||||||||
|
|
@@ -133,46 +136,20 @@ | |||||||||||||||||||||||||||||
| most useful for filenames where ":" may cause problems. | ||||||||||||||||||||||||||||||
| date_time_is_local - a boolean that, if True, indicates that | ||||||||||||||||||||||||||||||
| the date_time argument object is in the local time zone, not UTC. | ||||||||||||||||||||||||||||||
| custom_time_zone_info (default None) - a dictionary that enforces | ||||||||||||||||||||||||||||||
| a particular time zone. It looks like {"hours": _hours, | ||||||||||||||||||||||||||||||
| "minutes": _minutes, "string": _string} where _hours and _minutes | ||||||||||||||||||||||||||||||
| are the hours and minutes offset from UTC and _string is the string | ||||||||||||||||||||||||||||||
| to use as the time zone designator. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| time_zone_string = None | ||||||||||||||||||||||||||||||
| if custom_time_zone_info is not None: | ||||||||||||||||||||||||||||||
| custom_hours = custom_time_zone_info["hours"] | ||||||||||||||||||||||||||||||
| custom_minutes = custom_time_zone_info["minutes"] | ||||||||||||||||||||||||||||||
| if use_basic_format: | ||||||||||||||||||||||||||||||
| custom_string = custom_time_zone_info["string_basic"] | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| custom_string = custom_time_zone_info["string_extended"] | ||||||||||||||||||||||||||||||
| if date_time_is_local: | ||||||||||||||||||||||||||||||
| date_time_hours = TIME_ZONE_LOCAL_UTC_OFFSET_HOURS | ||||||||||||||||||||||||||||||
| date_time_minutes = TIME_ZONE_LOCAL_UTC_OFFSET_MINUTES | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| date_time_hours, date_time_minutes = (0, 0) | ||||||||||||||||||||||||||||||
| diff_hours = custom_hours - date_time_hours | ||||||||||||||||||||||||||||||
| diff_minutes = custom_minutes - date_time_minutes | ||||||||||||||||||||||||||||||
| date_time = date_time + timedelta( | ||||||||||||||||||||||||||||||
| hours=diff_hours, minutes=diff_minutes) | ||||||||||||||||||||||||||||||
| time_zone_string = custom_string | ||||||||||||||||||||||||||||||
oliver-sanders marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
-144
to
-160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This code block was previously only used by the Cylc 7 GUI (7.8.15): cylc-flow/lib/cylc/gui/updater_tree.py Lines 269 to 277 in e60e8f7
However, even then it looks like it was only used for the same purpose that is already provided by cylc-flow/lib/cylc/gui/updater_tree.py Line 190 in e60e8f7
cylc-flow/lib/cylc/state_summary_mgr.py Lines 125 to 128 in e60e8f7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hjoliver poke There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hjoliver poke |
||||||||||||||||||||||||||||||
| elif override_use_utc or (override_use_utc is None and _FLAGS['utc_mode']): | ||||||||||||||||||||||||||||||
| if override_use_utc or (override_use_utc is None and _FLAGS['utc_mode']): | ||||||||||||||||||||||||||||||
| time_zone_string = TIME_ZONE_STRING_UTC | ||||||||||||||||||||||||||||||
| if date_time_is_local: | ||||||||||||||||||||||||||||||
| date_time = date_time - timedelta( | ||||||||||||||||||||||||||||||
| hours=TIME_ZONE_LOCAL_UTC_OFFSET_HOURS, | ||||||||||||||||||||||||||||||
| minutes=TIME_ZONE_LOCAL_UTC_OFFSET_MINUTES | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| h, m = TIME_ZONE_LOCAL_UTC_OFFSET | ||||||||||||||||||||||||||||||
| date_time = date_time - timedelta(hours=h, minutes=m) | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| if use_basic_format: | ||||||||||||||||||||||||||||||
| time_zone_string = TIME_ZONE_STRING_LOCAL_BASIC | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| time_zone_string = TIME_ZONE_STRING_LOCAL_EXTENDED | ||||||||||||||||||||||||||||||
| if not date_time_is_local: | ||||||||||||||||||||||||||||||
| diff_hours = TIME_ZONE_LOCAL_UTC_OFFSET_HOURS | ||||||||||||||||||||||||||||||
| diff_minutes = TIME_ZONE_LOCAL_UTC_OFFSET_MINUTES | ||||||||||||||||||||||||||||||
| diff_hours, diff_minutes = TIME_ZONE_LOCAL_UTC_OFFSET | ||||||||||||||||||||||||||||||
| date_time = date_time + timedelta( | ||||||||||||||||||||||||||||||
| hours=diff_hours, minutes=diff_minutes) | ||||||||||||||||||||||||||||||
| if use_basic_format: | ||||||||||||||||||||||||||||||
|
|
@@ -187,9 +164,11 @@ | |||||||||||||||||||||||||||||
| return date_time_string + time_zone_string | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_time_string_from_unix_time(unix_time, display_sub_seconds=False, | ||||||||||||||||||||||||||||||
| use_basic_format=False, | ||||||||||||||||||||||||||||||
| custom_time_zone_info=None): | ||||||||||||||||||||||||||||||
| def get_time_string_from_unix_time( | ||||||||||||||||||||||||||||||
| unix_time: float, | ||||||||||||||||||||||||||||||
| display_sub_seconds: bool = False, | ||||||||||||||||||||||||||||||
| use_basic_format: bool = False, | ||||||||||||||||||||||||||||||
| ) -> str: | ||||||||||||||||||||||||||||||
| """Convert a unix timestamp into a local time zone datetime.datetime. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Arguments: | ||||||||||||||||||||||||||||||
|
|
@@ -202,20 +181,15 @@ | |||||||||||||||||||||||||||||
| use_basic_format (default False) - a boolean that, if True, | ||||||||||||||||||||||||||||||
| represents the date/time without "-" or ":" delimiters. This is | ||||||||||||||||||||||||||||||
| most useful for filenames where ":" may cause problems. | ||||||||||||||||||||||||||||||
| custom_time_zone_info (default None) - a dictionary that enforces | ||||||||||||||||||||||||||||||
| a particular time zone. It looks like {"hours": _hours, | ||||||||||||||||||||||||||||||
| "minutes": _minutes, "string": _string} where _hours and _minutes | ||||||||||||||||||||||||||||||
| are the hours and minutes offset from UTC and _string is the string | ||||||||||||||||||||||||||||||
| to use as the time zone designator. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| date_time = datetime.fromtimestamp(unix_time, timezone.utc) | ||||||||||||||||||||||||||||||
| return get_time_string(date_time, | ||||||||||||||||||||||||||||||
| display_sub_seconds=display_sub_seconds, | ||||||||||||||||||||||||||||||
| use_basic_format=use_basic_format, | ||||||||||||||||||||||||||||||
| override_use_utc=None, | ||||||||||||||||||||||||||||||
| date_time_is_local=False, | ||||||||||||||||||||||||||||||
| custom_time_zone_info=custom_time_zone_info) | ||||||||||||||||||||||||||||||
| return get_time_string( | ||||||||||||||||||||||||||||||
| datetime.fromtimestamp(unix_time, timezone.utc), | ||||||||||||||||||||||||||||||
| display_sub_seconds=display_sub_seconds, | ||||||||||||||||||||||||||||||
| use_basic_format=use_basic_format, | ||||||||||||||||||||||||||||||
| override_use_utc=None, | ||||||||||||||||||||||||||||||
| date_time_is_local=False, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_unix_time_from_time_string(datetime_string): | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.