timeutils

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package timeutils provides time utility functions for ppacer.

Index

Constants

View Source
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 CurrentTz

func CurrentTz() *time.Location

CurrentTz returns currently configured, on package level, timezone.

func Duration added in v0.0.7

func Duration(start, end string) time.Duration

Duration parses start and end using FromStringMust and calculate duration between start and end.

func FromString

func FromString(s string) (time.Time, error)

FromString tries to recreate time.Time based on given string value according to TimestampFormat format.

func FromStringMust

func FromStringMust(s string) time.Time

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 Now

func Now() time.Time

Now return the current time in ppacer timezone.

func RandomUtcTime

func RandomUtcTime(minYear int) time.Time

func SetTimezone

func SetTimezone(timezoneName string) error

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

func ToDateUTCString(t time.Time) string

ToDateUTCString move given time.Time to UTC location and serialize it to date string based on DateFormat format.

func ToString

func ToString(t time.Time) string

ToString serialize given time.Time to string based on TimestampFormat format.

func ToStringUI added in v0.0.3

func ToStringUI(t time.Time) string

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.

Jump to

Keyboard shortcuts

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