times

package
v0.0.0-...-7638cb1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package times provides a set of utilities related to processing time.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultClock = &defaultClock{}

DefaultClock implements Clock by delegating to methods in package time.

Functions

func ParseIso8601UTC

func ParseIso8601UTC(t string) time.Time

ParseIso8601UTC parses a time in Iso8601 format and UTC timezone (yyyy-MM-ddTHH:mm:ss.fffZ).

func ParseIsoDashUTC

func ParseIsoDashUTC(t string) (time.Time, error)

ParseIsoDashUTC parses a time in IsoDash format and UTC timezone (yyyy-MM-ddTHH-mm-ss.fffZ).

func ToIso8601UTC

func ToIso8601UTC(t time.Time) string

ToIso8601UTC converts a time into a string in Iso8601 format in UTC timezone (yyyy-MM-ddTHH:mm:ss.fffZ).

Example
fmt.Println(ToIso8601UTC(time.Date(2015, 6, 30, 0, 29, 4, 569000000, time.UTC)))
Output:

2015-06-30T00:29:04.569Z
Example (Locale)
mst := time.FixedZone("MST", -7*3600) // seven hours west of UTC
fmt.Println(ToIso8601UTC(time.Date(2015, 6, 3, 0, 9, 4, 569100000, mst)))
Output:

2015-06-03T07:09:04.569Z

func ToIsoDashUTC

func ToIsoDashUTC(t time.Time) string

ToIsoDashUTC converts a time into a string in Iso format yyyy-MM-ddTHH-mm-ss.fffZ in UTC timezone.

Example
fmt.Println(ToIsoDashUTC(time.Date(2015, 6, 30, 0, 29, 3, 148000000, time.UTC)))
Output:

2015-06-30T00-29-03.148Z

Types

type Clock

type Clock interface {
	// Now returns the current time.
	Now() time.Time

	// After returns a channel that will receive after the given duration.
	After(time.Duration) chan struct{}
}

Clock is an interface that can provide time related functionality.

type MockedClock

type MockedClock struct {
	mock.Mock
	AfterChannel chan struct{}
}

MockedClock implements the Now method to return a predictable time and the After method to return a channel that ca be woken up on demand.

func NewMockedClock

func NewMockedClock() *MockedClock

NewMockedClock creates a new instance of a mocked clock

func (*MockedClock) After

func (c *MockedClock) After(d time.Duration) chan struct{}

After returns a channel that receives when we tell it to.

func (*MockedClock) Now

func (c *MockedClock) Now() time.Time

Now returns a predefined value.

Jump to

Keyboard shortcuts

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