Hightime Python API

1.0.0 · active · verified Fri Apr 17

Hightime is a Python library from National Instruments designed for representing and manipulating durations and time intervals with high precision. It provides classes like `Interval` and `Unit` to define time quantities, enabling arithmetic operations and conversions between different units. The current stable version is 1.0.0, which includes significant improvements in Python version compatibility and type hinting. Releases appear to be driven by feature additions and Python version updates rather than a fixed schedule.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create `Interval` objects, perform basic arithmetic, and convert intervals between different `Unit` types. It also shows how to retrieve precise total seconds.

from hightime import Interval, Unit

# Create an interval of 5.5 seconds
interval_a = Interval(5.5, Unit.SECONDS)
print(f"Interval A: {interval_a}")

# Create another interval of 1000 milliseconds
interval_b = Interval(1000, Unit.MILLISECONDS)
print(f"Interval B: {interval_b}")

# Perform arithmetic operations
interval_sum = interval_a + interval_b
print(f"Sum: {interval_sum}")  # Should be 6.5 seconds

# Convert an interval to different units
milliseconds = interval_sum.in_units(Unit.MILLISECONDS)
print(f"Sum in milliseconds: {milliseconds} ms")

# Access total seconds with higher precision
total_seconds_precise = interval_sum.precision_total_seconds
print(f"Sum in precise total seconds: {total_seconds_precise} s")

view raw JSON →