util

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateParentDirs

func CreateParentDirs(file string) error

CreateParentDir creates the necessary parent directories for file.

func FmtDuration

func FmtDuration(dur time.Duration) string

func ParseDuration

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

ParseDuration parses a string into a time.Duration, assuming that a year always has 365d, a week always has 7d, and a day always has 24h.

It is similar to time.ParseDuration, but differs in the following ways: - It adds support for the following units: "y", "w", "d" - It requires a unit suffix - It does not support mixed unit durations (e.g. `1h10m10s` is not supported). - It does not support negative durations.

func SecsToCompact

func SecsToCompact(t uint32) string

SecsToCompact creates a compact string representation from the seconds.

func SecsToTime

func SecsToTime(t uint32) time.Time

SecsToTime takes seconds stored in a uint32.

func TimeToCompact

func TimeToCompact(t time.Time) string

TimeToCompact formats the time as a compat string, e.g. it discards the milliseconds parts if the time only has second resolution.

func TimeToSecs

func TimeToSecs(t time.Time) uint32

TimeToSecs returns seconds stored as uint32.

func TimeToString

func TimeToString(t time.Time) string

TimeToString formats the time as a string.

Types

type DurWrap

type DurWrap struct {
	time.Duration
}

DurWrap is a wrapper to enable marshalling and unmarshalling of durations with the custom format.

func (DurWrap) MarshalText

func (d DurWrap) MarshalText() (text []byte, err error)

func (*DurWrap) Set

func (d *DurWrap) Set(text string) error

func (DurWrap) String

func (d DurWrap) String() string

func (*DurWrap) UnmarshalText

func (d *DurWrap) UnmarshalText(text []byte) error

type FileMode

type FileMode os.FileMode

func (*FileMode) UnmarshalText

func (f *FileMode) UnmarshalText(text []byte) error

type UnixTime

type UnixTime struct {
	time.Time
}

UnixTime allows parsing and packing timestamps in seconds since epoch.

func (UnixTime) MarshalJSON

func (t UnixTime) MarshalJSON() ([]byte, error)

MarshalJSON marshals the time as seconds since unix epoch. This must be a value receiver.

func (*UnixTime) String

func (t *UnixTime) String() string

func (*UnixTime) UnmarshalJSON

func (t *UnixTime) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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