Coverage for pyguymer3/convert_seconds_to_pretty_time.py: 62%
8 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 18:47 +0000
1#!/usr/bin/env python3
3# Define function ...
4def convert_seconds_to_pretty_time(
5 secFlt,
6 /,
7):
8 """Convert a value of seconds to a pretty value of time
10 This function reads in a value of seconds and returns the same value
11 expressed prettily for a human to read as hours, minutes and seconds.
13 Parameters
14 ----------
15 secFlt : float
16 the value of seconds
18 Returns
19 -------
20 secStr : float
21 the value of seconds as a string
23 Notes
24 -----
25 Copyright 2017 Thomas Guymer [1]_
27 References
28 ----------
29 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3
31 Examples
32 --------
33 >>> pyguymer3.convert_seconds_to_pretty_time(7326.311)
34 '2h 2m 6.3s'
35 """
37 # Calculate how many hours, minutes and seconds there are ...
38 h, rem = divmod(secFlt, 3600.0)
39 m, s = divmod(rem, 60.0)
41 # Check how big the number is ...
42 if h > 0.0:
43 # Return answer ...
44 return f"{h:,.0f}h {m:.0f}m {s:.1f}s"
46 # Check how big the number is ...
47 if m > 0.0:
48 # Return answer ...
49 return f"{m:.0f}m {s:.1f}s"
51 # Return answer ...
52 return f"{s:.1f}s"