timing

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package timing contains helpers for tracking and recording timings.

Index

Examples

Constants

This section is empty.

Variables

View Source
var MockDate = time.Date(1997, time.May, 1, 21, 0, 0, 0, time.UTC)

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

func SpanFromDuration(start time.Time, d time.Duration) Span

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

func SpanFromInstant(t time.Time) Span

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 SpanSince

func SpanSince(start time.Time) Span

SpanSince constructs a Span representing the period of time between start and now.

func (*Span) Duration

func (t *Span) Duration() time.Duration

Duration gets the duration of the timespan. Duration is zero if either of the ends of the timespan are zero.

func (*Span) EndNoEarlierThan

func (t *Span) EndNoEarlierThan(end time.Time)

EndNoEarlierThan moves this timespan's end to become end, if end is nonzero and after this timespan's current end.

func (*Span) IsInstant

func (t *Span) IsInstant() bool

IsInstant gets whether this

func (*Span) IsUndefined

func (t *Span) IsUndefined() bool

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

func (t *Span) StartNoLaterThan(start time.Time)

StartNoLaterThan moves this timespan's start to become start, if start is nonzero and before this timespan's current start.

func (Span) String

func (t Span) String() string

String retrieves a string representation of this timespan.

Example

ExampleSpan_String is a testable example for String on Span.

package main

import (
	"fmt"

	"github.com/c4-project/c4t/internal/timing"
)

func main() {
	var zero timing.Span
	fmt.Println(zero)

}
Output:

(undefined)

func (*Span) Union

func (t *Span) Union(other Span)

Union sets this timespan's start to other's start if it is earlier, and its end to other's end if it is later.

Jump to

Keyboard shortcuts

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