#!/usr/bin/env python3 """ This module describes time intervals in a human-readable format. """ import sys from typing import TextIO from datetime import timedelta from argh import arg import humanize from ally import main __version__ = "0.2.1" logger = main.get_logger() @arg('seconds', type=int, help="Interval in seconds") @arg('-s', '--short', help="Use short format") def describe_interval(seconds: int, short: bool = False) -> str: """ Convert a number of seconds into a human-readable time interval description. Args: seconds (int): The number of seconds to describe. short (bool): Whether to use a shorter format. Returns: str: A human-readable description of the time interval. """ delta = timedelta(seconds=seconds) if short: return humanize.naturaldelta(delta, minimum_unit="seconds") else: return humanize.precisedelta(delta, minimum_unit="seconds") if __name__ == "__main__": main.run(describe_interval)