v.io: v.io/v23/vdlroot/time Index | Files

package time

import "v.io/v23/vdlroot/time"

Package time defines standard representations of absolute and relative times.

The representations described below are required to provide wire compatibility between different programming environments. Generated code for different environments typically provide automatic conversions into native representations, for simpler idiomatic usage. nolint:golint

Index

Package Files

time.go time.vdl.go

func DurationFromNative Uses

func DurationFromNative(wire *Duration, native time.Duration) error

DurationFromNative is called by VDL for conversions from native to wire durations.

func DurationToNative Uses

func DurationToNative(wire Duration, native *time.Duration) error

DurationToNative is called by VDL for conversions from wire to native durations.

func TimeFromNative Uses

func TimeFromNative(wire *Time, native time.Time) error

TimeFromNative is called by VDL for conversions from native to wire times. nolint:golint // API change required.

func TimeToNative Uses

func TimeToNative(wire Time, native *time.Time) error

TimeToNative is called by VDL for conversions from wire to native times. nolint:golint // API change required.

func WireDeadlineFromNative Uses

func WireDeadlineFromNative(wire *WireDeadline, native Deadline) error

WireDeadlineFromNative is called by VDL for conversions from native to wire deadlines.

func WireDeadlineToNative Uses

func WireDeadlineToNative(wire WireDeadline, native *Deadline) error

WireDeadlineToNative is called by VDL for conversions from wire to native deadlines.

type Deadline Uses

type Deadline struct {
    // Time represents the deadline as an absolute point in time.
    time.Time
}

Deadline represents the deadline for an operation; it is the native representation for WireDeadline, and is automatically converted to/from WireDeadline during marshaling.

Deadline represents the deadline as an absolute time, while WireDeadline represents the deadline as a relative duration from "now".

To represent "no deadline", use the zero value for Deadline.

type Duration Uses

type Duration struct {
    // Seconds represents the seconds in the duration.  The range is roughly
    // +/-290 billion years, larger than the estimated age of the universe.
    Seconds int64
    // Nanos represents the fractions of a second at nanosecond resolution.  Must
    // be in the inclusive range between +/-999,999,999.
    //
    // In normalized form, durations less than one second are represented with 0
    // Seconds and +/-Nanos.  For durations one second or more, the sign of Nanos
    // must match Seconds, or be 0.
    Nanos int32
}

Duration represents the elapsed duration between two points in time, with up to nanosecond precision.

func (Duration) Normalize Uses

func (x Duration) Normalize() Duration

Normalize returns the normalized representation of x. It makes a best-effort attempt to clean up invalid values, e.g. if Nanos is outside the valid range, or the sign of Nanos doesn't match the sign of Seconds. The behavior is undefined for large invalid values, e.g. {int64max,int32max}.

func (Duration) VDLIsZero Uses

func (x Duration) VDLIsZero() bool

func (*Duration) VDLRead Uses

func (x *Duration) VDLRead(dec vdl.Decoder) error

func (Duration) VDLReflect Uses

func (Duration) VDLReflect(struct {
    Name string `vdl:"time.Duration"`
})

func (Duration) VDLWrite Uses

func (x Duration) VDLWrite(enc vdl.Encoder) error

type Time Uses

type Time struct {
    Seconds int64
    Nanos   int32
}

Time represents an absolute point in time with up to nanosecond precision.

Time is represented as the duration before or after a fixed epoch. The zero Time represents the epoch 0001-01-01T00:00:00.000000000Z. This uses the proleptic Gregorian calendar; the calendar runs on an exact 400 year cycle. Leap seconds are "smeared", ensuring that no leap second table is necessary for interpretation.

This is similar to Go time.Time, but always in the UTC location. http://golang.org/pkg/time/#Time

This is similar to conventional "unix time", but with the epoch defined at year 1 rather than year 1970. This allows the zero Time to be used as a natural sentry, since it isn't a valid time for many practical applications. http://en.wikipedia.org/wiki/Unix_time

func Now Uses

func Now() Time

Now returns the current time.

func (Time) Normalize Uses

func (x Time) Normalize() Time

Normalize returns the normalized representation of x. It makes a best-effort attempt to clean up invalid values, e.g. if Nanos is outside the valid range, or the sign of Nanos doesn't match the sign of Seconds. The behavior is undefined for large invalid values, e.g. {int64max,int32max}.

func (Time) VDLIsZero Uses

func (x Time) VDLIsZero() bool

func (*Time) VDLRead Uses

func (x *Time) VDLRead(dec vdl.Decoder) error

func (Time) VDLReflect Uses

func (Time) VDLReflect(struct {
    Name string `vdl:"time.Time"`
})

func (Time) VDLWrite Uses

func (x Time) VDLWrite(enc vdl.Encoder) error

type WireDeadline Uses

type WireDeadline struct {
    // FromNow represents the deadline as a duration from "now".  As a
    // special-case, the 0 duration indicates that there is no deadline; i.e. the
    // deadline is "infinite".
    FromNow time.Duration
}

WireDeadline represents the deadline for an operation, where the operation is expected to finish before the deadline. The intended usage is for a client to set a deadline on an operation, say one minute from "now", and send the deadline to a server. The server is expected to finish the operation before the deadline.

On a single device, it is simplest to represent a deadline as an absolute time; when the time now reaches the deadline, the deadline has expired. However when sending a deadline between devices with potential clock skew, it is often more robust to represent the deadline as a duration from "now". The sender computes the duration from its notion of "now", while the receiver computes the absolute deadline from its own notion of "now".

This representation doesn't account for propagation delay, but does ensure that the deadline used by the receiver is no earlier than the deadline intended by the client. In many common scenarios the propagation delay is small compared to the potential clock skew, making this a simple but effective approach.

WireDeadline typically has a native representation called Deadline that is an absolute Time, which automatically performs the sender and receiver conversions from "now".

func (WireDeadline) VDLIsZero Uses

func (x WireDeadline) VDLIsZero() bool

func (*WireDeadline) VDLRead Uses

func (x *WireDeadline) VDLRead(dec vdl.Decoder) error

func (WireDeadline) VDLReflect Uses

func (WireDeadline) VDLReflect(struct {
    Name string `vdl:"time.WireDeadline"`
})

func (WireDeadline) VDLWrite Uses

func (x WireDeadline) VDLWrite(enc vdl.Encoder) error

Package time imports 3 packages (graph) and is imported by 68 packages. Updated 2020-10-24. Refresh now. Tools for package owners.