(duration_in_seconds: float)
| 1990 | |
| 1991 | |
| 1992 | def duration_in_words(duration_in_seconds: float) -> str: |
| 1993 | if not duration_in_seconds: |
| 1994 | return "0 seconds" |
| 1995 | components = [] |
| 1996 | hours, remainder = divmod(duration_in_seconds, 3600) |
| 1997 | if hours > 1: |
| 1998 | components.append(f"{int(hours)} hours") |
| 1999 | elif hours == 1: |
| 2000 | components.append("1 hour") |
| 2001 | minutes, seconds = divmod(remainder, 60) |
| 2002 | if minutes > 1: |
| 2003 | components.append(f"{int(minutes)} minutes") |
| 2004 | elif minutes == 1: |
| 2005 | components.append("1 minute") |
| 2006 | if seconds >= 2: |
| 2007 | components.append(f"{int(seconds)} seconds") |
| 2008 | elif seconds >= 1: |
| 2009 | components.append("1 second") |
| 2010 | elif seconds: |
| 2011 | components.append(f"{round(seconds, 3)} second") |
| 2012 | return " ".join(components) |
| 2013 | |
| 2014 | |
| 2015 | if __name__ == "__main__": |
no outgoing calls