Documentation
¶
Overview ¶
Package timeutils provides time utility functions for ppacer.
Index ¶
- Constants
- func CurrentTz() *time.Location
- func Duration(start, end string) time.Duration
- func FromString(s string) (time.Time, error)
- func FromStringMust(s string) time.Time
- func Now() time.Time
- func RandomUtcTime(minYear int) time.Time
- func SetTimezone(timezoneName string) error
- func ToDateUTCString(t time.Time) string
- func ToString(t time.Time) string
- func ToStringUI(t time.Time) string
Constants ¶
const ( // Timestamp format for time.Time serialization and deserialization. This // format is used to store timestamps in the database. TimestampFormat = "2006-01-02T15:04:05.999999MST-07:00" // Date format for time.Time serialization and deserialization. DateFormat = "2006-01-02" // String identifier for local time zone in standard time package. LocalTimezoneName = "Local" // Time format used on the UI. UiTimeFormat = "15:04:05" // As UiTimeFormat but including sub-second information. UiTimeDetailedFormat = "15:04:05.999999" // Date format used on the UI. UiDateFormat = "2006-01-02" // Timestamp format used on the UI for non-today timestamps. UiTimestampFormat = "2006-01-02 15:04:05" )
Variables ¶
This section is empty.
Functions ¶
func Duration ¶ added in v0.0.7
Duration parses start and end using FromStringMust and calculate duration between start and end.
func FromString ¶
FromString tries to recreate time.Time based on given string value according to TimestampFormat format.
func FromStringMust ¶
In most cases FromString should be called on strings created by ToString and should succeed. In cases when we are pretty sure that FromString will succeed, we can use FromStringMust. If FromString would fail for given input, error would be logged and time.Time{} would be returned.
func RandomUtcTime ¶
func SetTimezone ¶
SetTimezone sets package-level timezone. By default it's time.Local. If incorrect timezone name is provided, then non-nil error is returned and the timezone is not overwritten.
func ToDateUTCString ¶
ToDateUTCString move given time.Time to UTC location and serialize it to date string based on DateFormat format.
func ToStringUI ¶ added in v0.0.3
ToStringUI serialize given time.Time to string based on Ui* formats. That string is meant to be placed on the UI.
Types ¶
This section is empty.