mono

package
v1.43.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: Apache-2.0 Imports: 1 Imported by: 14

Documentation

Overview

Package mono enforces use of monotonic time when creating/parsing time.Time from external sources.

Using time.Now produces monotonic time values that correctly measure time difference in the presence of clock resets.

On the other hand, time produce by time.Unix or time.Parse doesn't have this property. Clock reset may lead to incorrect durations computed from these timestamps. To fix this, prefer using Unix and Parse provided by this package.

Monotonic time could also be erased when using functions like Truncate, Round, In, UTC. Be careful when using these.

More details: https://go.googlesource.com/proposal/+/master/design/12914-monotonic.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromTime deprecated

func FromTime(t time.Time) time.Time

FromTime ensures that time.Time value uses monotonic clock.

Deprecated: You should probably use Unix or Parse instead.

func Now deprecated

func Now() time.Time

Now is a wrapper for time.Time.

Deprecated: time.Now always uses monotonic clock.

func Parse added in v1.42.1

func Parse(layout, value string) (time.Time, error)

Parse is an analog of time.Parse that produces monotonic time.

func Unix added in v1.42.1

func Unix(sec, nsec int64) time.Time

Unix is an analog of time.Unix that produces monotonic time.

func UnixMicro

func UnixMicro() int64

UnixMicro returns the number of microseconds elapsed, based on the application start time. This value may be different from time.Now().UnixMicro() in the presence of time resets.

func UnixNano

func UnixNano() int64

UnixNano returns the number of nanoseconds elapsed, based on the application start time. This value may be different from time.Now().UnixNano() in the presence of time resets.

Types

This section is empty.

Jump to

Keyboard shortcuts

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