File size: 597 Bytes
3a67739
 
 
1a1e2eb
29b5c59
 
1a1e2eb
3a67739
 
 
 
d3ac0b2
 
3a67739
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Thunder/utils/time_format.py

from Thunder.utils.logger import logger

_TIME_PERIODS = (('d', 86400), ('h', 3600), ('m', 60), ('s', 1))

def get_readable_time(seconds: int) -> str:
    try:
        result = []
        for suffix, period in _TIME_PERIODS:
            if seconds >= period:
                value, seconds = divmod(int(seconds), period)
                result.append(f"{int(value)}{suffix}")
        return ' '.join(result) if result else '0s'
    except Exception as e:
        logger.error(f"Error in get_readable_time: {e}", exc_info=True)
        return "N/A"