@@ -301,7 +301,8 @@ def run_clock(
301301 date_system : str = "GREGORIAN" ,
302302 date_format : str = "FULL" ,
303303 offset_local : float = 0 ,
304- offset_timezone : float = 0 ) -> None :
304+ offset_timezone : float = 0 ,
305+ once : bool = False ) -> None :
305306 """
306307 Run clock.
307308
@@ -319,6 +320,7 @@ def run_clock(
319320 :param date_format: date format
320321 :param offset_local: manual offset for the local time
321322 :param offset_timezone: manual offset for the timezone
323+ :param once: once flag
322324 """
323325 try :
324326 detected_environment = detect_environment ()
@@ -349,7 +351,8 @@ def run_clock(
349351 h_shift = max (0 , h_shift )
350352 face = get_face (face )
351353 while True :
352- clear_screen (detected_environment )
354+ if not once :
355+ clear_screen (detected_environment )
353356 print ('\n ' * v_shift , end = '' )
354357 print (" " * h_shift , end = '' )
355358 datetime_timezone = datetime_lib .datetime .now (tz = tz ) + offset_main_timedelta
@@ -373,6 +376,8 @@ def run_clock(
373376 if offset_local != 0 :
374377 print (" " * h_shift , end = '' )
375378 print (OFFSET_FORMAT .format (offset_type = "Local" , offset_value = offset_local ))
379+ if once :
380+ break
376381 time .sleep (1 )
377382 if not no_blink :
378383 format_index = int (not format_index )
@@ -400,6 +405,7 @@ def main() -> None:
400405 parser .add_argument ('--hide-date' , help = 'hide date' , nargs = "?" , const = 1 )
401406 parser .add_argument ('--hide-timezone' , help = 'hide timezone' , nargs = "?" , const = 1 )
402407 parser .add_argument ('--am-pm' , help = 'AM/PM mode' , nargs = "?" , const = 1 )
408+ parser .add_argument ('--once' , help = 'print current time once and exit immediately' , nargs = '?' , const = 1 )
403409 parser .add_argument ('--calendar' , help = 'calendar mode' , type = str .upper , choices = CALENDARS_LIST )
404410 parser .add_argument ('--first-weekday' , help = 'first weekday' , type = str .upper , default = "MONDAY" ,
405411 choices = WEEKDAYS_LIST + [x [:2 ] for x in WEEKDAYS_LIST ])
@@ -458,4 +464,5 @@ def main() -> None:
458464 date_system = args .date_system ,
459465 date_format = args .date_format ,
460466 offset_local = args .offset_local ,
461- offset_timezone = args .offset_timezone )
467+ offset_timezone = args .offset_timezone ,
468+ once = args .once )
0 commit comments