Documentation ¶
Overview ¶
Package timeutil provides utilities for working with time related objects.
Index ¶
- Constants
- func Duration(ds *dpb.Duration) time.Duration
- func DurationProto(d time.Duration) *dpb.Duration
- func GetLocales() map[string]*LocaleInfo
- func GetTimeZones() map[string]*TimezoneInfo
- func IsLocale(name string) bool
- func IsTimeZone(name string) bool
- func KeyTTL(maxRequestedTTL time.Duration, numKeys int) time.Duration
- func ParseDuration(d string) (time.Duration, error)
- func ParseDurationWithDefault(d string, def time.Duration) time.Duration
- func ParseRFC3339(s string) time.Time
- func ParseSeconds(d string) (time.Duration, error)
- func RFC3339(ts *tspb.Timestamp) string
- func TTLString(ttl time.Duration) string
- func Time(ts *tspb.Timestamp) time.Time
- func TimestampProto(t time.Time) *tspb.Timestamp
- func TimestampString(secs int64) string
- type LocaleInfo
- type TimezoneInfo
Constants ¶
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 ¶
Duration returns the time for a given timestamp. Returns 0 if the timestamp is invalid.
func DurationProto ¶
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 ¶
IsLocale returns true if the "name" provided is a locale name as per https://tools.ietf.org/html/bcp47.
func IsTimeZone ¶
IsTimeZone returns true if the "name" provided is an IANA Time Zone name.
func ParseDuration ¶
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 ¶
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
ParseRFC3339 converts an RFC3339 string to time.Time. Returns default value of time.Time if the string is invalid.
func ParseSeconds ¶
ParseSeconds returns a duration from a numeric string in seconds.
func RFC3339 ¶
RFC3339 convers a Timestamp to RFC3339 string. Returns "" if the timestamp is invalid.
func TimestampProto ¶
TimestampProto returns the timestamp proto for a given time. Returns empty if the time is invalid.
func TimestampString ¶
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.