@@ -155,7 +155,7 @@ def show_date_formats_list(date_system: str = "GREGORIAN") -> None:
155155 """
156156 datetime_lib = datetime
157157 example_year = 1990
158- if date_system == "JALALI" :
158+ if date_system . upper () == "JALALI" :
159159 datetime_lib = jdatetime
160160 example_year = 1368
161161 print ("Date formats list:\n " )
@@ -176,7 +176,7 @@ def get_weekday_id(first_weekday: str, date_system: str = "GREGORIAN") -> int:
176176 if len (first_weekday ) > 2 :
177177 first_weekday_normalized = first_weekday_normalized [:2 ]
178178 weekdays = [x [:2 ] for x in WEEKDAYS_LIST ]
179- if date_system == "JALALI" :
179+ if date_system . upper () == "JALALI" :
180180 weekdays = weekdays [- 2 :] + weekdays [:- 2 ]
181181 return weekdays .index (first_weekday_normalized )
182182
@@ -281,61 +281,64 @@ def run_clock(
281281 :param offset_local: manual offset for the local time
282282 :param offset_timezone: manual offset for the timezone
283283 """
284- detected_environment = detect_environment ()
285- datetime_lib = datetime
286- if date_system .upper () == "JALALI" :
287- datetime_lib = jdatetime
288- format_index = 0
289- time_formats = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
290- time_formats_local = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
291- if vertical :
292- time_formats = VERTICAL_TIME_12H_FORMATS if am_pm else VERTICAL_TIME_24H_FORMATS
293- tz = None
294- timezone_str = "Local"
295- offset_main_timedelta = datetime_lib .timedelta (hours = offset_local )
296- offset_local_timedelta = datetime .timedelta (hours = offset_local )
297- if country is not None :
298- timezone = pytz .country_timezones (country )[0 ].upper ()
299- if timezone is not None :
300- timezone_str = timezone
301- timezone_diff = get_timezone_difference (
302- timezone = timezone ,
303- offset_local = offset_local ,
304- offset_timezone = offset_timezone )
305- timezone_str += " ({timezone_diff})" .format (timezone_diff = timezone_diff )
306- tz = pytz .timezone (timezone )
307- offset_main_timedelta = datetime_lib .timedelta (hours = offset_timezone )
308- v_shift = max (0 , v_shift )
309- h_shift = max (0 , h_shift )
310- face = get_face (face )
311- while True :
312- clear_screen (detected_environment )
313- print ('\n ' * v_shift , end = '' )
314- print (" " * h_shift , end = '' )
315- datetime_timezone = datetime_lib .datetime .now (tz = tz ) + offset_main_timedelta
316- time_timezone_str = datetime_timezone .strftime (time_formats [format_index ])
317- date_timezone_str = datetime_timezone .strftime (DATE_FORMATS_MAP [date_format .upper ()])
318- tprint (time_timezone_str , font = face , sep = "\n " + " " * h_shift )
319- if not hide_date :
320- print (" " * h_shift , end = '' )
321- print (date_timezone_str )
322- if not hide_timezone :
284+ try :
285+ detected_environment = detect_environment ()
286+ datetime_lib = datetime
287+ if date_system .upper () == "JALALI" :
288+ datetime_lib = jdatetime
289+ format_index = 0
290+ time_formats = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
291+ time_formats_local = HORIZONTAL_TIME_12H_FORMATS if am_pm else HORIZONTAL_TIME_24H_FORMATS
292+ if vertical :
293+ time_formats = VERTICAL_TIME_12H_FORMATS if am_pm else VERTICAL_TIME_24H_FORMATS
294+ tz = None
295+ timezone_str = "Local"
296+ offset_main_timedelta = datetime_lib .timedelta (hours = offset_local )
297+ offset_local_timedelta = datetime .timedelta (hours = offset_local )
298+ if country is not None :
299+ timezone = pytz .country_timezones (country )[0 ].upper ()
300+ if timezone is not None :
301+ timezone_str = timezone
302+ timezone_diff = get_timezone_difference (
303+ timezone = timezone ,
304+ offset_local = offset_local ,
305+ offset_timezone = offset_timezone )
306+ timezone_str += " ({timezone_diff})" .format (timezone_diff = timezone_diff )
307+ tz = pytz .timezone (timezone )
308+ offset_main_timedelta = datetime_lib .timedelta (hours = offset_timezone )
309+ v_shift = max (0 , v_shift )
310+ h_shift = max (0 , h_shift )
311+ face = get_face (face )
312+ while True :
313+ clear_screen (detected_environment )
314+ print ('\n ' * v_shift , end = '' )
323315 print (" " * h_shift , end = '' )
324- print ("Timezone: {timezone}" .format (timezone = timezone_str ))
325- if offset_timezone != 0 :
316+ datetime_timezone = datetime_lib .datetime .now (tz = tz ) + offset_main_timedelta
317+ time_timezone_str = datetime_timezone .strftime (time_formats [format_index ])
318+ date_timezone_str = datetime_timezone .strftime (DATE_FORMATS_MAP [date_format .upper ()])
319+ tprint (time_timezone_str , font = face , sep = "\n " + " " * h_shift )
320+ if not hide_date :
326321 print (" " * h_shift , end = '' )
327- print (OFFSET_FORMAT .format (offset_type = "Timezone" , offset_value = offset_timezone ))
328- if timezone is not None :
329- datetime_local = datetime .datetime .now () + offset_local_timedelta
330- time_local_str = datetime_local .strftime (time_formats_local [format_index ])
322+ print (date_timezone_str )
323+ if not hide_timezone :
331324 print (" " * h_shift , end = '' )
332- print ("Local Time: {local_time}" .format (local_time = time_local_str ))
333- if offset_local != 0 :
334- print (" " * h_shift , end = '' )
335- print (OFFSET_FORMAT .format (offset_type = "Local" , offset_value = offset_local ))
336- time .sleep (1 )
337- if not no_blink :
338- format_index = int (not format_index )
325+ print ("Timezone: {timezone}" .format (timezone = timezone_str ))
326+ if offset_timezone != 0 :
327+ print (" " * h_shift , end = '' )
328+ print (OFFSET_FORMAT .format (offset_type = "Timezone" , offset_value = offset_timezone ))
329+ if timezone is not None :
330+ datetime_local = datetime .datetime .now () + offset_local_timedelta
331+ time_local_str = datetime_local .strftime (time_formats_local [format_index ])
332+ print (" " * h_shift , end = '' )
333+ print ("Local Time: {local_time}" .format (local_time = time_local_str ))
334+ if offset_local != 0 :
335+ print (" " * h_shift , end = '' )
336+ print (OFFSET_FORMAT .format (offset_type = "Local" , offset_value = offset_local ))
337+ time .sleep (1 )
338+ if not no_blink :
339+ format_index = int (not format_index )
340+ except (KeyboardInterrupt , EOFError ):
341+ print (EXIT_MESSAGE )
339342
340343
341344def main () -> None :
@@ -396,21 +399,18 @@ def main() -> None:
396399 offset_local = args .offset_local ,
397400 offset_timezone = args .offset_timezone )
398401 else :
399- try :
400- run_clock (
401- timezone = args .timezone ,
402- country = args .country ,
403- h_shift = args .h_shift ,
404- v_shift = args .v_shift ,
405- face = args .face ,
406- no_blink = args .no_blink ,
407- vertical = args .vertical ,
408- hide_date = args .hide_date ,
409- hide_timezone = args .hide_timezone ,
410- am_pm = args .am_pm ,
411- date_system = args .date_system ,
412- date_format = args .date_format ,
413- offset_local = args .offset_local ,
414- offset_timezone = args .offset_timezone )
415- except (KeyboardInterrupt , EOFError ):
416- print (EXIT_MESSAGE )
402+ run_clock (
403+ timezone = args .timezone ,
404+ country = args .country ,
405+ h_shift = args .h_shift ,
406+ v_shift = args .v_shift ,
407+ face = args .face ,
408+ no_blink = args .no_blink ,
409+ vertical = args .vertical ,
410+ hide_date = args .hide_date ,
411+ hide_timezone = args .hide_timezone ,
412+ am_pm = args .am_pm ,
413+ date_system = args .date_system ,
414+ date_format = args .date_format ,
415+ offset_local = args .offset_local ,
416+ offset_timezone = args .offset_timezone )
0 commit comments