duration

package
v0.203.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration

type Duration struct {
	// contains filtered or unexported fields
}

Duration is a wrapper for durationpb.Duration to provide custom marshaling for JSON and URL query strings.

It embeds durationpb.Duration and exposes the .AsDuration() method to easily convert to time.Duration.

Example:

customDur := duration.New(30 * time.Second)
goDur := customDur.AsDuration()

func New

func New(d time.Duration) *Duration

New creates a custom Duration from a standard time.Duration.

func (*Duration) AsDuration

func (x *Duration) AsDuration() time.Duration

AsDuration returns the underlying time.Duration value.

func (Duration) EncodeValues

func (d Duration) EncodeValues(key string, v *url.Values) error

EncodeValues implements the [query.Encoder] interface by encoding the duration as a string, like "3.3s".

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements the [json.Marshaler] interface by marshalling the duration as a protobuf Duration.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the [json.Unmarshaler] interface. It can parse a duration from the protobuf Duration.

Jump to

Keyboard shortcuts

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