Documentation ¶
Overview ¶
Package timing contains helpers for tracking and recording timings.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
MockDate is an arbitrary date useful for timespan tests.
Functions ¶
This section is empty.
Types ¶
type Span ¶
type Span struct { // Start is the start time of the timespan. Start time.Time `json:"start,omitempty"` // End is the end time of the timespan. End time.Time `json:"end,omitempty"` }
Span is a pair of times, representing the start and end of a process.
func SpanFromDuration ¶
SpanFromDuration constructs a Span from the start time start and duration d.
Example ¶
ExampleSpanFromDuration is a testable example for SpanFromDuration.
package main import ( "fmt" "time" "github.com/c4-project/c4t/internal/timing" ) func main() { ts := timing.SpanFromDuration(time.Date(1990, time.January, 1, 12, 00, 00, 00, time.UTC), 10*time.Minute) fmt.Println(ts) fmt.Println(ts.IsInstant()) fmt.Println(ts.IsUndefined()) fmt.Printf("%.0f", ts.Duration().Minutes()) }
Output: 10m0s (from 1990-01-01T12:00:00Z to 1990-01-01T12:10:00Z) false false 10
func SpanFromInstant ¶
SpanFromInstant constructs a Span representing the instant in time t.
Example ¶
ExampleSpanFromInstant is a testable example for SpanFromInstant.
package main import ( "fmt" "time" "github.com/c4-project/c4t/internal/timing" ) func main() { ts := timing.SpanFromInstant(time.Date(1990, time.January, 1, 12, 00, 00, 00, time.UTC)) fmt.Println(ts) fmt.Println(ts.IsInstant()) fmt.Println(ts.IsUndefined()) fmt.Printf("%.0f", ts.Duration().Minutes()) }
Output: 1990-01-01T12:00:00Z true false 0
func (*Span) Duration ¶
Duration gets the duration of the timespan. Duration is zero if either of the ends of the timespan are zero.
func (*Span) EndNoEarlierThan ¶
EndNoEarlierThan moves this timespan's end to become end, if end is nonzero and after this timespan's current end.
func (*Span) IsUndefined ¶
IsUndefined gets whether this span is ill-defined. This happens if either time is zero, or the end is before the start.
func (*Span) StartNoLaterThan ¶
StartNoLaterThan moves this timespan's start to become start, if start is nonzero and before this timespan's current start.