polymerist.genutils.duration ============================ .. py:module:: polymerist.genutils.duration .. autoapi-nested-parse:: Utilities for representing, converting, and formatting amounts of time Attributes ---------- .. autoapisummary:: polymerist.genutils.duration.SECONDS_PER_INTERVAL polymerist.genutils.duration.SECONDS_PER_INTERVAL_ORDERED polymerist.genutils.duration.Timeable polymerist.genutils.duration.istimeable Classes ------- .. autoapisummary:: polymerist.genutils.duration.TimeTemplate polymerist.genutils.duration.Duration polymerist.genutils.duration.Timer Module Contents --------------- .. py:data:: SECONDS_PER_INTERVAL .. py:data:: SECONDS_PER_INTERVAL_ORDERED .. py:type:: Timeable :canonical: Union[int, float, timedelta] .. py:data:: istimeable .. py:class:: TimeTemplate(template) Bases: :py:obj:`string.Template` Like a string Template, but which uses a percent to indicate fields (much like a date formatter) .. py:attribute:: delimiter :type: str :value: '%' .. py:class:: Duration For representing, converting, and formatting a length of time .. py:attribute:: year :type: int :value: 0 .. py:attribute:: day :type: int :value: 0 .. py:attribute:: hour :type: int :value: 0 .. py:attribute:: minute :type: int :value: 0 .. py:attribute:: second :type: int :value: 0 .. py:attribute:: millisecond :type: int :value: 0 .. py:attribute:: microsecond :type: int :value: 0 .. py:method:: from_seconds(interval: Timeable) -> dict[str, int] :classmethod: Takes an object interpretable as a duration in seconds and returns the breakdown by years, hours, minutes, seconds, and milliseconds .. py:method:: to_seconds() -> float Convert the stored duration into a number of seconds .. py:property:: total_seconds :type: float conversion-to-seconds alias for convenience .. py:method:: format(fmt_str: str) -> str Format stored duration similar to datetime.strftime (https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime) .. py:attribute:: fmt .. py:class:: Timer Simple context manager for measuring how long something takes .. py:attribute:: start_time .. py:attribute:: time_taken :value: None