timeutil

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package timeutil provides utilities for working with time related objects.

Index

Constants

View Source
const (
	// DurationREStr is a regexp for a duration string consiting of
	// days, hours, minutess, and seconds (each one is optional).
	DurationREStr = "^([0-9]+d)?([0-9]+h)?([0-9]+m)?([0-9]+s)?$"
)

Variables

This section is empty.

Functions

func Duration

func Duration(ds *dpb.Duration) time.Duration

Duration returns the time for a given timestamp. Returns 0 if the timestamp is invalid.

func DurationProto

func DurationProto(d time.Duration) *dpb.Duration

DurationProto returns the duration proto for a given duration.

func IsLocale

func IsLocale(name string) bool

IsLocale returns true if the "name" provided is a locale name as per https://tools.ietf.org/html/bcp47.

func IsTimeZone

func IsTimeZone(name string) bool

IsTimeZone returns true if the "name" provided is an IANA Time Zone name.

func KeyTTL

func KeyTTL(maxRequestedTTL time.Duration, numKeys int) time.Duration

KeyTTL retuns the ttl for a number of keys.

func ParseDuration

func ParseDuration(d string) (time.Duration, error)

ParseDuration parses the given duration string to time.Duration. It supports "d" for days which time.ParseDuration does not. Each day is 24 hours.

func ParseDurationWithDefault

func ParseDurationWithDefault(d string, def time.Duration) time.Duration

ParseDurationWithDefault parses the given duration string. Returns the provided default if the string is empty or on error.

func ParseRFC3339 added in v0.8.6

func ParseRFC3339(s string) time.Time

ParseRFC3339 converts an RFC3339 string to time.Time. Returns default value of time.Time if the string is invalid.

func ParseSeconds

func ParseSeconds(d string) (time.Duration, error)

ParseSeconds returns a duration from a numeric string in seconds.

func RFC3339

func RFC3339(ts *tspb.Timestamp) string

RFC3339 convers a Timestamp to RFC3339 string. Returns "" if the timestamp is invalid.

func TTLString

func TTLString(ttl time.Duration) string

TTLString removes tailing 0s, 0m, 0h for human readable.

func Time

func Time(ts *tspb.Timestamp) time.Time

Time returns the time for a given timestamp. Returns 0 if the timestamp is invalid.

func TimestampProto

func TimestampProto(t time.Time) *tspb.Timestamp

TimestampProto returns the timestamp proto for a given time. Returns empty if the time is invalid.

func TimestampString

func TimestampString(secs int64) string

TimestampString returns a RFC3339 date/time string for seconds sinc epoch.

Types

This section is empty.

Jump to

Keyboard shortcuts

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