timeutil

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 14 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 GetLocales added in v0.9.8

func GetLocales() map[string]*LocaleInfo

GetLocales returns a map of locale identifiers to English labels.

func GetTimeZones added in v0.9.8

func GetTimeZones() map[string]*TimezoneInfo

GetTimeZones returns a map of canonical timezone names to region names.

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

type LocaleInfo added in v0.9.9

type LocaleInfo struct {
	// Base is the base language as defined by BCP47.
	Base string `json:"base"`
	// Script is the script character set used as defined by BCP47.
	Script string `json:"script"`
	// Region is the geolocation as defined by BCP47.
	Region string `json:"region"`
	// UI contains human-friendly labels for UIs to display.
	UI map[string]string `json:"ui"`
}

LocaleInfo is the descriptor for a locale.

type TimezoneInfo added in v0.9.9

type TimezoneInfo struct {
	// UI contains human-friendly labels for UIs to display.
	UI map[string]string `json:"ui"`
}

TimezoneInfo is the descriptor for a time zone.

Jump to

Keyboard shortcuts

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