timeutil

package
v1.11.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: MIT Imports: 4 Imported by: 13

Documentation

Overview

Utilities for messing with time.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DurationHMS added in v1.7.55

func DurationHMS(d time.Duration) (int, int, int)

Extracts the hours, minutes, and seconds from the given duration.

func FormatTimer added in v1.7.55

func FormatTimer(d time.Duration) string

Formats the given duration in a colon-separated timer format in the form [HH:]MM:SS.

Example (Complete)
fmt.Print(FormatTimer(23*time.Hour + 4*time.Minute + 13*time.Second))
Output:

23:04:13
Example (OneHour)
fmt.Print(FormatTimer(time.Hour))
Output:

1:00:00
Example (OneMinute)
fmt.Print(FormatTimer(time.Minute))
Output:

1:00
Example (OneSecond)
fmt.Print(FormatTimer(time.Second))
Output:

0:01
Example (OverOneMinute)
fmt.Print(FormatTimer(119 * time.Second))
Output:

1:59
Example (UnderOneMinute)
fmt.Print(FormatTimer(59 * time.Second))
Output:

0:59
Example (ZeroValue)
fmt.Print(FormatTimer(0))
Output:

0:00

func FormatTimerf added in v1.7.55

func FormatTimerf(format string, d time.Duration) string

Formats the given duration using the given format string. The string follows the same formatting rules as described in the fmt package, and will receive three integer arguments: hours, minutes, and seconds.

func ParseDuration

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

Provides an API-compatible version of time.ParseDuration that accepts additional formats for parsing durations:

1y, 3year, 5years: Expands to (n*24*365) hours
1w, 3weeks, 5wks:  Expands to (n*24*7) hours
1d, 1day, 5days:   Expands to (n*24) hours

func ReferenceTime added in v1.8.41

func ReferenceTime() time.Time

Return the standard Golang reference time (2006-01-02T15:04:05.999999999Z07:00)

Types

This section is empty.

Jump to

Keyboard shortcuts

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