|
17 | 17 |
|
18 | 18 | from calendar import timegm |
19 | 19 | from datetime import datetime, timedelta, timezone |
| 20 | +from typing import Dict, Optional |
20 | 21 |
|
21 | 22 | from metomi.isodatetime.timezone import ( |
22 | 23 | get_local_time_zone_format, get_local_time_zone, TimeZoneFormatMode) |
@@ -108,31 +109,45 @@ def get_current_time_string(display_sub_seconds=False, override_use_utc=None, |
108 | 109 | use_basic_format=use_basic_format) |
109 | 110 |
|
110 | 111 |
|
111 | | -def get_time_string(date_time, display_sub_seconds=False, |
112 | | - override_use_utc=None, use_basic_format=False, |
113 | | - date_time_is_local=False, custom_time_zone_info=None): |
| 112 | +def get_time_string( |
| 113 | + date_time: datetime, |
| 114 | + display_sub_seconds: bool = False, |
| 115 | + override_use_utc: Optional[bool] = None, |
| 116 | + use_basic_format: bool = False, |
| 117 | + date_time_is_local: bool = False, |
| 118 | + custom_time_zone_info: Optional[Dict] = None, |
| 119 | +): |
114 | 120 | """Return a string representing the current system time. |
115 | 121 |
|
116 | | - Arguments: |
117 | | - date_time - a datetime.datetime object. |
118 | | -
|
119 | | - Keyword arguments: |
120 | | - display_sub_seconds (default False) - a boolean that, if True, |
121 | | - switches on microsecond reporting |
122 | | - override_use_utc (default None) - a boolean (or None) that, if |
123 | | - True, switches on utc time zone reporting. If False, it switches |
124 | | - off utc time zone reporting (even if _FLAGS['utc_mode'] is True). If None, |
125 | | - the _FLAGS['utc_mode'] boolean is used. |
126 | | - use_basic_format (default False) - a boolean that, if True, |
127 | | - represents the date/time without "-" or ":" delimiters. This is |
128 | | - most useful for filenames where ":" may cause problems. |
129 | | - date_time_is_local - a boolean that, if True, indicates that |
130 | | - the date_time argument object is in the local time zone, not UTC. |
131 | | - custom_time_zone_info (default None) - a dictionary that enforces |
132 | | - a particular time zone. It looks like {"hours": _hours, |
133 | | - "minutes": _minutes, "string": _string} where _hours and _minutes |
134 | | - are the hours and minutes offset from UTC and _string is the string |
135 | | - to use as the time zone designator. |
| 122 | + Args: |
| 123 | + date_time: Datetime to operate on. |
| 124 | + display_sub_seconds: |
| 125 | + Switch on microsecond reporting. |
| 126 | + override_use_utc: |
| 127 | + Switch on utc time zone reporting. |
| 128 | + If False, it switches off utc time zone reporting even |
| 129 | + if ``_FLAGS['utc_mode']`` is True). |
| 130 | + If None, the ``_FLAGS['utc_mode']`` boolean is used. |
| 131 | + use_basic_format: |
| 132 | + Represent the date/time without "-" or ":" |
| 133 | + delimiters. This is useful for filenames, where ":" may |
| 134 | + cause problems. |
| 135 | + date_time_is_local: |
| 136 | + Indicates that the date_time argument |
| 137 | + object is in the local time zone, not UTC. |
| 138 | + custom_time_zone_info: |
| 139 | + A dictionary that enforces a particular time zone: |
| 140 | +
|
| 141 | + .. code-block:: python |
| 142 | + { |
| 143 | + "hours": _hours, # offset from UTC |
| 144 | + "minutes": _minutes, # offset from utc |
| 145 | + "string_basic": _string, # timezone designators |
| 146 | + "string_extened": _string |
| 147 | + } |
| 148 | +
|
| 149 | + Usage of ``string_basic`` or ``string_extended`` is |
| 150 | + switched by ``use_basic_format``. |
136 | 151 |
|
137 | 152 | """ |
138 | 153 | time_zone_string = None |
|
0 commit comments