4343TIME_ZONE_STRING_LOCAL_EXTENDED = get_local_time_zone_format (
4444 TimeZoneFormatMode .extended )
4545TIME_ZONE_STRING_UTC = "Z"
46- TIME_ZONE_UTC_UTC_OFFSET = (0 , 0 )
4746TIME_ZONE_LOCAL_UTC_OFFSET = get_local_time_zone ()
4847
4948TIME_ZONE_LOCAL_INFO = {
5453}
5554
5655TIME_ZONE_UTC_INFO = {
57- "hours" : TIME_ZONE_UTC_UTC_OFFSET [ 0 ] ,
58- "minutes" : TIME_ZONE_UTC_UTC_OFFSET [ 1 ] ,
56+ "hours" : 0 ,
57+ "minutes" : 0 ,
5958 "string_basic" : TIME_ZONE_STRING_UTC ,
6059 "string_extended" : TIME_ZONE_STRING_UTC
6160}
@@ -113,9 +112,13 @@ def get_current_time_string(display_sub_seconds=False, override_use_utc=None,
113112 use_basic_format = use_basic_format )
114113
115114
116- def get_time_string (date_time , display_sub_seconds = False ,
117- override_use_utc = None , use_basic_format = False ,
118- date_time_is_local = False , custom_time_zone_info = None ):
115+ def get_time_string (
116+ date_time : datetime ,
117+ display_sub_seconds : bool = False ,
118+ override_use_utc : Optional [bool ] = None ,
119+ use_basic_format : bool = False ,
120+ date_time_is_local : bool = False ,
121+ ):
119122 """Return a string representing the current system time.
120123
121124 Arguments:
@@ -133,31 +136,10 @@ def get_time_string(date_time, display_sub_seconds=False,
133136 most useful for filenames where ":" may cause problems.
134137 date_time_is_local - a boolean that, if True, indicates that
135138 the date_time argument object is in the local time zone, not UTC.
136- custom_time_zone_info (default None) - a dictionary that enforces
137- a particular time zone. It looks like {"hours": _hours,
138- "minutes": _minutes, "string": _string} where _hours and _minutes
139- are the hours and minutes offset from UTC and _string is the string
140- to use as the time zone designator.
141139
142140 """
143141 time_zone_string = None
144- if custom_time_zone_info is not None :
145- custom_hours = custom_time_zone_info ["hours" ]
146- custom_minutes = custom_time_zone_info ["minutes" ]
147- if use_basic_format :
148- custom_string = custom_time_zone_info ["string_basic" ]
149- else :
150- custom_string = custom_time_zone_info ["string_extended" ]
151- if date_time_is_local :
152- date_time_hours , date_time_minutes = TIME_ZONE_LOCAL_UTC_OFFSET
153- else :
154- date_time_hours , date_time_minutes = (0 , 0 )
155- diff_hours = custom_hours - date_time_hours
156- diff_minutes = custom_minutes - date_time_minutes
157- date_time = date_time + timedelta (
158- hours = diff_hours , minutes = diff_minutes )
159- time_zone_string = custom_string
160- elif override_use_utc or (override_use_utc is None and _FLAGS ['utc_mode' ]):
142+ if override_use_utc or (override_use_utc is None and _FLAGS ['utc_mode' ]):
161143 time_zone_string = TIME_ZONE_STRING_UTC
162144 if date_time_is_local :
163145 h , m = TIME_ZONE_LOCAL_UTC_OFFSET
@@ -183,9 +165,11 @@ def get_time_string(date_time, display_sub_seconds=False,
183165 return date_time_string + time_zone_string
184166
185167
186- def get_time_string_from_unix_time (unix_time , display_sub_seconds = False ,
187- use_basic_format = False ,
188- custom_time_zone_info = None ):
168+ def get_time_string_from_unix_time (
169+ unix_time : float ,
170+ display_sub_seconds : bool = False ,
171+ use_basic_format : bool = False ,
172+ ) -> str :
189173 """Convert a unix timestamp into a local time zone datetime.datetime.
190174
191175 Arguments:
@@ -198,20 +182,15 @@ def get_time_string_from_unix_time(unix_time, display_sub_seconds=False,
198182 use_basic_format (default False) - a boolean that, if True,
199183 represents the date/time without "-" or ":" delimiters. This is
200184 most useful for filenames where ":" may cause problems.
201- custom_time_zone_info (default None) - a dictionary that enforces
202- a particular time zone. It looks like {"hours": _hours,
203- "minutes": _minutes, "string": _string} where _hours and _minutes
204- are the hours and minutes offset from UTC and _string is the string
205- to use as the time zone designator.
206185
207186 """
208- date_time = datetime . fromtimestamp ( unix_time , timezone . utc )
209- return get_time_string ( date_time ,
210- display_sub_seconds = display_sub_seconds ,
211- use_basic_format = use_basic_format ,
212- override_use_utc = None ,
213- date_time_is_local = False ,
214- custom_time_zone_info = custom_time_zone_info )
187+ return get_time_string (
188+ datetime . fromtimestamp ( unix_time , timezone . utc ) ,
189+ display_sub_seconds = display_sub_seconds ,
190+ use_basic_format = use_basic_format ,
191+ override_use_utc = None ,
192+ date_time_is_local = False ,
193+ )
215194
216195
217196def get_unix_time_from_time_string (datetime_string ):
0 commit comments