hightime ======== .. py:module:: hightime .. autoapi-nested-parse:: This package extends the built-in datetime types to support sub-microsecond values. The classes defined in this package are: * :any:`hightime.datetime`: A subclass of :any:`datetime.datetime` with sub-microsecond capabilities. * :any:`hightime.timedelta`: A subclass of :any:`datetime.timedelta` with sub-microsecond capabilities. .. note:: Due to floating point arithmetic inaccuracies, the ability to specify sub-microsecond values in terms of much larger units (weeks, days, seconds) has been limited. For the exact limitations, please consult the source code. Classes ------- .. autoapisummary:: hightime.datetime hightime.timedelta Package Contents ---------------- .. py:class:: datetime Bases: :py:obj:`datetime.datetime` A datetime represents a point in time. This class extends :any:`datetime.datetime` to support up to yoctosecond precision. The constructor takes the same arguments as :any:`datetime.datetime`, with the addition of ``femtosecond`` and ``yoctosecond``. >>> new_years = datetime(year=1999, month=12, day=31, hour=23, minute=59, second=59, ... microsecond=999999, femtosecond=999999999, yoctosecond=999999999) >>> new_years hightime.datetime(1999, 12, 31, 23, 59, 59, 999999, 999999999, 999999999) >>> new_years + timedelta(yoctoseconds=1) hightime.datetime(2000, 1, 1, 0, 0) .. py:attribute:: __slots__ :value: ('_femtosecond', '_yoctosecond') .. py:attribute:: year year (1-9999) .. py:attribute:: month month (1-12) .. py:attribute:: day day (1-31) .. py:attribute:: hour hour (0-23) .. py:attribute:: minute minute (0-59) .. py:attribute:: second second (0-59) .. py:attribute:: microsecond microsecond (0-999999) .. py:attribute:: tzinfo timezone info object .. py:attribute:: fold .. py:property:: femtosecond femtosecond (0-999999999) .. py:property:: yoctosecond yoctosecond (0-999999999) .. py:method:: fromtimestamp(t, tz=None) :classmethod: Return a datetime corresponding to a POSIX timestamp with the provided time zone. .. warning:: This method does not support sub-microsecond values. .. py:method:: utcfromtimestamp(t) :classmethod: Return a datetime corresponding to a POSIX timestamp in UTC. .. warning:: This method does not support sub-microsecond values. .. py:method:: astimezone(tz=None) Return a copy of self converted to the specified time zone. .. py:method:: isoformat(sep='T', timespec='auto') Return a string representing the time in ISO 8601 format. .. py:method:: replace(year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, femtosecond=None, yoctosecond=None, tzinfo=True, *, fold=None) Return a copy of self with the specified fields replaced with the provided values. .. py:method:: __repr__() Return repr(self). .. py:attribute:: __str__ Convert to string, for str(). .. py:method:: __eq__(other) Return self==other. .. py:method:: __ne__(other) Return self!=other. .. py:method:: __lt__(other) Return selfother. .. py:method:: __ge__(other) Return self>=other. .. py:method:: __add__(other) Return self+other. .. py:attribute:: __radd__ .. py:method:: __sub__(other) Return self-other. .. py:method:: __hash__() Return hash(self). .. py:method:: __reduce_ex__(protocol) Return object state for pickling. .. py:method:: __reduce__() Return object state for pickling. .. py:class:: timedelta Bases: :py:obj:`datetime.timedelta` A timedelta represents a duration. This class extends :any:`datetime.timedelta` to support up to yoctosecond precision. The constructor takes the same arguments as :any:`datetime.timedelta`, with the addition of ``nanoseconds``, ``picoseconds``, ``femtoseconds``, ``attoseconds``, ``zeptoseconds``, and ``yoctoseconds``. >>> timedelta(days=1, seconds=2, microseconds=3, # doctest: +NORMALIZE_WHITESPACE ... milliseconds=4, minutes=5, hours=6, weeks=7, nanoseconds=8, picoseconds=9, femtoseconds=10, ... attoseconds=11, zeptoseconds=12, yoctoseconds=13) hightime.timedelta(days=50, seconds=21902, microseconds=4003, femtoseconds=8009010, yoctoseconds=11012013) >>> timedelta(picoseconds=1e12) hightime.timedelta(seconds=1) .. note:: Performing math operations with floating point may reduce the precision of the result. For example, multiplying or dividing by the number of yoctoseconds in a second has the correct result when it is expressed as an integer, and the wrong result when it is expressed as a float: >>> timedelta(yoctoseconds=1) * 10**24 hightime.timedelta(seconds=1) >>> timedelta(yoctoseconds=1) * 1e24 hightime.timedelta(microseconds=999999, femtoseconds=999999999, yoctoseconds=983222784) >>> timedelta(seconds=1) // 10**24 hightime.timedelta(yoctoseconds=1) >>> timedelta(seconds=1) / 1e24 hightime.timedelta() Likewise, you can specify larger units as a float with a sub-microsecond value, but this may reduce the precision of the result: >>> timedelta(seconds=1e-15) hightime.timedelta(femtoseconds=1) >>> timedelta(seconds=1e-24) # expected hightime.timedelta(yoctoseconds=1) hightime.timedelta() .. py:attribute:: __slots__ :value: ('_femtoseconds', '_yoctoseconds') .. py:attribute:: days days .. py:attribute:: seconds seconds .. py:attribute:: microseconds microseconds .. py:property:: femtoseconds femtoseconds .. py:property:: yoctoseconds yoctoseconds .. py:method:: total_seconds() Total seconds in the duration. .. py:method:: precision_total_seconds() Precise total seconds in the duration. .. note:: Up to 64 significant digits are used in computation. .. py:method:: __repr__() Return repr(self). .. py:method:: __str__() Return str(self). .. py:method:: __eq__(other) Return self==other. .. py:method:: __ne__(other) Return self!=other. .. py:method:: __lt__(other) Return selfother. .. py:method:: __ge__(other) Return self>=other. .. py:method:: __bool__() Return bool(self). .. py:method:: __pos__() Return +self. .. py:method:: __abs__() Return abs(self). .. py:method:: __add__(other) Return self+other. .. py:attribute:: __radd__ .. py:method:: __sub__(other) Return self-other. .. py:method:: __neg__() Return -self. .. py:method:: __mul__(other) Return self*other. .. py:attribute:: __rmul__ .. py:method:: __floordiv__(other) Return self//other. .. py:method:: __truediv__(other) Return self/other. .. py:method:: __mod__(other) Return self%other. .. py:method:: __divmod__(other) Return divmod(self, other). .. py:method:: __hash__() Return hash(self). .. py:method:: __reduce__() Return object state for pickling.