timeutil

package
v0.0.0-...-d931726 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package timeutil provides some general purpose functionalities around the time package.

Index

Constants

View Source
const (
	ISO8601 = "2006-01-02T15:04:05.000Z"
)

Variables

View Source
var (
	ErrInvalidDurationFormat = errors.New("invalid duration format")
)

Functions

func DateOnly

func DateOnly(t time.Time) time.Time

DateOnly returns the given DateTime with time set to 00:00:00.

func FromUnix

func FromUnix(t int) time.Time

FromUnix returns a time.Time struct from the passed unix timestamp t.

func NowAddPtr

func NowAddPtr(d time.Duration) *time.Time

NowAddPtr adds t to now and returns the resulting time as *time.Time. If d is <= 0, nil is returned.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration tries to parse a duration from the passed string s. The format is composed of an integer number in combination with a time unit suffix. Following suffixes are supported:

  • w (weeks)
  • d (days)
  • h (hours)
  • m (minutes)
  • s (seconds)
  • s (seconds)
  • ms (milliseconds)
  • us / µs (microseconds)
  • ns (nanoseconds)

Also spaces and tab spaces are supported between the elements of the duration string. A valid example would be following duration string:

"3w1d 4h12m3s40ms"

Also, substractions inside the duration strings are possible. The following example results in a furation of 23 hours.

"1d -1h"

func ToUnix

func ToUnix(t time.Time) int

ToUnix returns the passed time.Time struct as unix milliseconds timestamp.

Types

This section is empty.

Jump to

Keyboard shortcuts

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