time

package
v1.1.57 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Date

func Date(t time.Time) string

Date creates a string representing the time in YYYY-MM-DD format

func Epoch added in v1.1.16

func Epoch(d time.Duration) string

Epoch creates a Unix timestamp from the duration object

func StartOfDay

func StartOfDay(t time.Time) time.Time

StartOfDay trims everything after the day from the provided time

func StartOfHour

func StartOfHour(t time.Time) time.Time

StartOfHour trims everything after the hour from the provided time

func TimeframeAdder added in v1.1.18

func TimeframeAdder(multiplier int, freq data.Frequency) func(time.Time) time.Time

TimeframeAdder generates an adder that can be used to get the next time from the current time based on the timeframe provided. This function will panic if the frequency is not one we recognize or the multiplier is zero. Note that this function operates differently on times and dates. For times, this function relies on time.Add and for dates it relies on time.AddDate. Note that this is done to ensure that addition works with respect to unevenly-spaced durations (months, quarters, years) as well as evenly-spaced durations (seconds, minutes, hours, days).

func Today added in v1.1.52

func Today() time.Time

Today returns a time.Time object representing the current day

func UnixNanoString

func UnixNanoString(t time.Time) string

UnixNanoString creates a string containing the Unix nano timestamp that is valid up to the limit of Unix

Types

type Convertible added in v1.1.8

type Convertible struct {
	yaml.Marshaler
	time.Time
	Layout string
}

Convertible represents a wrapper for a time.Time object, allowing it to be converted to and from various formats, including SQL, DynamoDB, JSON, YAML and CSV. The exact format the time should take will be determined by the value provided to the Layout field and will operate according to Go's documentation for time.Time.

func WithLayout added in v1.1.8

func WithLayout(inner time.Time, layout string) Convertible

WithLayout creates a new Convertible time from an inner time and a layout.

func (Convertible) MarshalCSV added in v1.1.8

func (c Convertible) MarshalCSV() (string, error)

MarshalCSV converts the time contained in the Convertible to a CSV column, using the Layout field associated with this Convertible to format the time (or RFC3339 if no layout was provided).

func (Convertible) MarshalDynamoDBAttributeValue added in v1.1.8

func (c Convertible) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)

MarshalDynamoDBAttributeValue converts the time contained in the Convertible to a DynamoDB AttributeValue object, using the Layout field associated with this Convertible to format the time (or RFC3339 if no layout was provided). The Convertible converts to a DynamoDB string attribute.

func (Convertible) MarshalJSON added in v1.1.8

func (c Convertible) MarshalJSON() ([]byte, error)

MarshalJSON converts the time contained in the Convertible to JSON, using the Layout field associated with this Convertible to format the time (or RFC3339 if no layout was provided).

func (Convertible) MarshalYAML added in v1.1.9

func (c Convertible) MarshalYAML() (interface{}, error)

MarshalYAML converts the time contained in the Convertible to a YAML node, using the Layout field associated with this Convertible to format the time (or RFC3339 if no layout was provided).

func (*Convertible) Scan added in v1.1.8

func (c *Convertible) Scan(value interface{}) error

Scan converts an SQL driver value to a time.Time and sets the inner Time on this Convertible to that value, using the Layout field to parse the raw data (or RFC3339 if no layout was provided). This function expects the driver value to be convertible to a string.

func (*Convertible) UnmarshalCSV added in v1.1.8

func (c *Convertible) UnmarshalCSV(raw string) error

UnmarshalCSV converts a CSV column to a time.Time and sets the inner Time on this Convertible to that value, using the Layout field to parse the raw data (or RFC3339 if no layout was provided).

func (*Convertible) UnmarshalDynamoDBAttributeValue added in v1.1.8

func (c *Convertible) UnmarshalDynamoDBAttributeValue(value types.AttributeValue) error

UnmarshalDynamoDBAttributeValue converts a DynamoDB AttributeValue object to a time.Time and sets the inner Time on this Convertible to that value, using the Layout field to parse the raw data (or RFC3339 if no layout was provided). String or byte array AttributeValues can be converted and NULL AttributeValues will result in no change to the object. Any other type of AttributeValue will result in an error.

func (*Convertible) UnmarshalJSON added in v1.1.8

func (c *Convertible) UnmarshalJSON(raw []byte) error

UnmarshalJSON converts a JSON string to a time.Time and sets the inner Time on this Convertible to that value, using the Layout field to parse the raw data (or RFC3339 if no layout was provided).

func (*Convertible) UnmarshalYAML added in v1.1.9

func (c *Convertible) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML converts a YAML node to a time.Time and sets the inner Time on this Convertible to that value, using the Layout field to parse the raw data (or RFC3339 if no layout was provided).

func (Convertible) Value added in v1.1.8

func (c Convertible) Value() (driver.Value, error)

Value converts the time contained in the Convertible to an SQL driver value, using the Layout field associated with this Convertible to format the time (or RFC3339 if no layout was provided).

Jump to

Keyboard shortcuts

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