hightime

This package extends the built-in datetime types to support sub-microsecond values.

The classes defined in this package are:

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

datetime

A datetime represents a point in time.

timedelta

A timedelta represents a duration.

Package Contents

class hightime.datetime

Bases: datetime.datetime

A datetime represents a point in time.

This class extends datetime.datetime to support up to yoctosecond precision.

The constructor takes the same arguments as 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)
__slots__ = ('_femtosecond', '_yoctosecond')
year

year (1-9999)

month

month (1-12)

day

day (1-31)

hour

hour (0-23)

minute

minute (0-59)

second

second (0-59)

microsecond

microsecond (0-999999)

tzinfo

timezone info object

fold
property femtosecond

femtosecond (0-999999999)

property yoctosecond

yoctosecond (0-999999999)

classmethod fromtimestamp(t, tz=None)[source]

Return a datetime corresponding to a POSIX timestamp with the provided time zone.

Warning

This method does not support sub-microsecond values.

classmethod utcfromtimestamp(t)[source]

Return a datetime corresponding to a POSIX timestamp in UTC.

Warning

This method does not support sub-microsecond values.

astimezone(tz=None)[source]

Return a copy of self converted to the specified time zone.

isoformat(sep='T', timespec='auto')[source]

Return a string representing the time in ISO 8601 format.

replace(year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, femtosecond=None, yoctosecond=None, tzinfo=True, *, fold=None)[source]

Return a copy of self with the specified fields replaced with the provided values.

__repr__()[source]

Return repr(self).

__str__

Convert to string, for str().

__eq__(other)[source]

Return self==other.

__ne__(other)[source]

Return self!=other.

__lt__(other)[source]

Return self<other.

__le__(other)[source]

Return self<=other.

__gt__(other)[source]

Return self>other.

__ge__(other)[source]

Return self>=other.

__add__(other)[source]

Return self+other.

__radd__
__sub__(other)[source]

Return self-other.

__hash__()[source]

Return hash(self).

__reduce_ex__(protocol)[source]

Return object state for pickling.

__reduce__()[source]

Return object state for pickling.

class hightime.timedelta

Bases: datetime.timedelta

A timedelta represents a duration.

This class extends datetime.timedelta to support up to yoctosecond precision.

The constructor takes the same arguments as datetime.timedelta, with the addition of nanoseconds, picoseconds, femtoseconds, attoseconds, zeptoseconds, and yoctoseconds.

>>> timedelta(days=1, seconds=2, microseconds=3,
... 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()
__slots__ = ('_femtoseconds', '_yoctoseconds')
days

days

seconds

seconds

microseconds

microseconds

property femtoseconds

femtoseconds

property yoctoseconds

yoctoseconds

total_seconds()[source]

Total seconds in the duration.

precision_total_seconds()[source]

Precise total seconds in the duration.

Note

Up to 64 significant digits are used in computation.

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

__eq__(other)[source]

Return self==other.

__ne__(other)[source]

Return self!=other.

__lt__(other)[source]

Return self<other.

__le__(other)[source]

Return self<=other.

__gt__(other)[source]

Return self>other.

__ge__(other)[source]

Return self>=other.

__bool__()[source]

Return bool(self).

__pos__()[source]

Return +self.

__abs__()[source]

Return abs(self).

__add__(other)[source]

Return self+other.

__radd__
__sub__(other)[source]

Return self-other.

__neg__()[source]

Return -self.

__mul__(other)[source]

Return self*other.

__rmul__
__floordiv__(other)[source]

Return self//other.

__truediv__(other)[source]

Return self/other.

__mod__(other)[source]

Return self%other.

__divmod__(other)[source]

Return divmod(self, other).

__hash__()[source]

Return hash(self).

__reduce__()[source]

Return object state for pickling.