timehlp

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FullTimeFormat           = "2006-01-02 15:04:05"
	SimplerTimeFormat        = "2006-01-02 15:04"
	OnlyTimeFormat           = "15:04:05"
	SimplerOnlyTimeFormat    = "15:04"
	SimplerOnlyTimeFormatWL  = "5:04"
	NowTimeFormat            = "now"
	SimplestOnlyTimeFormat   = "1504"
	SimplestOnlyTimeFormatWL = "504"
)

Variables

View Source
var ErrInvalidReliveTime = errors.New(
	"supported relative time formats are: " +
		"+15:04:05, +15:04 or unit descriptive +1d15h4m5s, " +
		"+15h5s, 120m",
)

Functions

func ConvertToTime

func ConvertToTime(timeString string) (t time.Time, err error)

ConvertToTime will try to convert a string do time.Time looking for the format that best fits it and assuming "today" when necessary. If the string starts with `yesterday`, than it will be exchanged for a date-string with the format: 2006-01-02 If the string starts with `+` or `-` than the string will be treated as "relative time expressions", and will be calculated as the diff from now and it. If the string is "now" than `time.Now()` in the local timezone will be returned.

func GetMonthRange

func GetMonthRange(ref time.Time) (first, last time.Time)

GetMonthRange given a time it returns the first and last date of a month

func GetWeekRange

func GetWeekRange(ref time.Time) (first, last time.Time)

GetWeekRange given a time it returns the first and last date of a week

func Now added in v0.44.1

func Now() time.Time

Now returns a time.Time using the local timezone

func Today

func Today() time.Time

Today will return a UTC time.Time for the same day as time.Now() in Local time, but at 0:00:00.000

func TruncateDate

func TruncateDate(t time.Time) time.Time

TruncateDate clears the hours, minutes and seconds of a time.Time for UTC

func TruncateDateWithTimezone added in v0.44.1

func TruncateDateWithTimezone(t time.Time, l *time.Location) time.Time

TruncateDateWithTimezone clears the hours, minutes and seconds of a time.Time for a time.Location

Types

This section is empty.

Jump to

Keyboard shortcuts

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