pytime

package
v0.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOverflow = errors.New("OverflowError: timestamp out of range for platform Py_TIME")

ErrOverflow matches CPython's "timestamp out of range for platform" OverflowError raised by pytime_time_t_overflow.

CPython: Python/pytime.c pytime_time_t_overflow

Functions

func AsSecondsDouble

func AsSecondsDouble(t Time) float64

AsSecondsDouble converts Time to a float-seconds value.

CPython: Include/cpython/pytime.h:14 PyTime_AsSecondsDouble

func Monotonic

func Monotonic(out *Time) error

Monotonic writes a monotonic clock reading to *out. The reading is nanoseconds since process start; it never decreases on a single machine.

CPython: Python/pytime.c:1223 PyTime_Monotonic

func MonotonicWithInfo

func MonotonicWithInfo(out *Time, info *ClockInfo) error

MonotonicWithInfo writes a monotonic reading and fills info.

CPython: Python/pytime.c:1245 _PyTime_MonotonicWithInfo

func PerfCounter

func PerfCounter(out *Time) error

PerfCounter writes a high-resolution monotonic counter to *out. On every supported platform CPython aliases this to monotonic, so we do the same.

CPython: Python/pytime.c:1266 PyTime_PerfCounterRaw

func PerfCounterWithInfo

func PerfCounterWithInfo(out *Time, info *ClockInfo) error

PerfCounterWithInfo writes a high-resolution monotonic counter and fills info.

CPython: Python/pytime.c:1255 _PyTime_PerfCounterWithInfo

func TimeWithInfo

func TimeWithInfo(out *Time, info *ClockInfo) error

TimeWithInfo writes the wall-clock time and fills info.

CPython: Python/pytime.c:1031 _PyTime_TimeWithInfo

func Time_

func Time_(out *Time) error

Time_ writes the current wall-clock time (ns since the Unix epoch) to *out. The trailing underscore avoids colliding with the type.

CPython: Python/pytime.c:1010 PyTime_Time

Types

type ClockInfo

type ClockInfo struct {
	Implementation string
	Monotonic      bool
	Adjustable     bool
	Resolution     float64
}

ClockInfo mirrors _Py_clock_info_t. time.get_clock_info() returns a named tuple with these four fields.

CPython: Include/internal/pycore_time.h _Py_clock_info_t

type Rounding

type Rounding int

Rounding selects the float-to-int conversion strategy used by FromSeconds and friends.

CPython: Include/internal/pycore_time.h:69 _PyTime_round_t

const (
	RoundFloor    Rounding = 0
	RoundCeiling  Rounding = 1
	RoundHalfEven Rounding = 2
	RoundUp       Rounding = 3
)

type Time

type Time int64

Time is the gopy equivalent of PyTime_t. The epoch depends on the clock that produced the value: Monotonic returns nanoseconds since process start, Time_ returns nanoseconds since the Unix epoch.

CPython: Include/cpython/pytime.h:10 typedef int64_t PyTime_t

const (
	MinTime Time = math.MinInt64
	MaxTime Time = math.MaxInt64
)

MinTime and MaxTime mirror PyTime_MIN / PyTime_MAX.

CPython: Include/cpython/pytime.h:11 PyTime_MIN

func Deadline

func Deadline(timeout Time) Time

Deadline returns Monotonic() + timeout, the absolute time at which a timeout-bounded wait should give up.

CPython: Python/pytime.c _PyDeadline_Init

func FromNanoseconds

func FromNanoseconds(ns int64) Time

FromNanoseconds wraps an int64 ns count as Time.

func FromSeconds

func FromSeconds(s float64, round Rounding) (Time, error)

FromSeconds converts a float-seconds value to a Time using the given rounding. Returns ErrOverflow if the value falls outside the int64 ns range; returns a ValueError-shaped error on NaN.

CPython: Python/pytime.c:626 _PyTime_FromSecondsObject (float branch)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL