hightime
This package extends the built-in datetime types to support sub-microsecond values.
The classes defined in this package are:
hightime.datetime: A subclass ofdatetime.datetimewith sub-microsecond capabilities.hightime.timedelta: A subclass ofdatetime.timedeltawith 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
A datetime represents a point in time. |
|
A timedelta represents a duration. |
Package Contents
- class hightime.datetime
Bases:
datetime.datetimeA datetime represents a point in time.
This class extends
datetime.datetimeto support up to yoctosecond precision.The constructor takes the same arguments as
datetime.datetime, with the addition offemtosecondandyoctosecond.>>> 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.
- 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.
- __str__
Convert to string, for str().
- __radd__
- class hightime.timedelta
Bases:
datetime.timedeltaA timedelta represents a duration.
This class extends
datetime.timedeltato support up to yoctosecond precision.The constructor takes the same arguments as
datetime.timedelta, with the addition ofnanoseconds,picoseconds,femtoseconds,attoseconds,zeptoseconds, andyoctoseconds.>>> 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
- precision_total_seconds()[source]
Precise total seconds in the duration.
Note
Up to 64 significant digits are used in computation.
- __radd__
- __rmul__