monotime

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package monotime provides a monotonic time representation that is useful for measuring elapsed time. It is designed as a memory optimized drop-in replacement for time.Time, with a monotime.Time consuming just 8 bytes instead of 24 bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Since

func Since(t Time) time.Duration

Since returns the time elapsed since t. It is shorthand for Now().Sub(t).

func Until

func Until(t Time) time.Duration

Until returns the duration until t. It is shorthand for t.Sub(Now()). If t is in the past, the returned duration will be negative.

Types

type Time

type Time int64

A Time represents an instant in monotonic time. Times can be compared using the comparison operators, but the specific value is implementation-dependent and should not be relied upon. The zero value of Time doesn't have any specific meaning.

func FromTime

func FromTime(t time.Time) Time

FromTime converts a time.Time to a monotonic Time. The conversion is relative to the package's start time and may lose precision if the time.Time is far from the start time.

func Now

func Now() Time

Now returns the current monotonic time.

func (Time) Add

func (t Time) Add(d time.Duration) Time

Add returns the time t+d.

func (Time) After

func (t Time) After(t2 Time) bool

After reports whether the time instant t is after t2.

func (Time) Before

func (t Time) Before(t2 Time) bool

Before reports whether the time instant t is before t2.

func (Time) Equal

func (t Time) Equal(t2 Time) bool

Equal reports whether t and t2 represent the same time instant.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero reports whether t represents the zero time instant.

func (Time) Sub

func (t Time) Sub(t2 Time) time.Duration

Sub returns the duration t-t2. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).

func (Time) ToTime

func (t Time) ToTime() time.Time

ToTime converts the monotonic time to a time.Time value. The returned time.Time will have the same instant as the monotonic time, but may be subject to clock adjustments.

Jump to

Keyboard shortcuts

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