tmu

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 7 Imported by: 8

Documentation

Index

Constants

View Source
const (
	Nanosecond  = time.Nanosecond
	Microsecond = time.Microsecond
	Millisecond = time.Millisecond
	Second      = time.Second
	Minute      = time.Minute
	Hour        = time.Hour
	Day         = time.Hour * 24
)

Variables

View Source
var GeneralLayouts = []string{time.RFC3339, "2006-1-2 15:04:05", "2006-1-2", "15:04:05"}

Functions

func AddMonth added in v1.0.27

func AddMonth(t time.Time, m int) time.Time

AddMonth2019-12-31, 1) = 2020-01-31 AddMonth2019-12-31, 2) = 2020-02-29 AddMonth2019-12-31, 3) = 2020-03-31 AddMonth2019-12-31, 12) = 2020-12-31 AddMonth2019-12-31, 13) = 2021-01-31 AddMonth2019-12-31, 14) = 2021-02-28 AddMonth2020-03-31, -1) = 2020-02-29 AddMonth2020-03-31, -2) = 2020-01-31 AddMonth2020-03-31, -3) = 2019-12-31 AddMonth2020-03-31, -4) = 2019-11-30

func AddYear added in v1.0.27

func AddYear(t time.Time, y int) time.Time

AddYear(2020-02-29, 1) = 2021-02-28 AddYear(2020-02-29, 10) = 2030-02-28 AddYear(2020-02-29, 12) = 2032-02-29 AddYear(2020-02-29, -1) = 2019-02-28 AddYear(2020-02-29, -10) = 2010-02-28 AddYear(2020-02-29, -12) = 2008-02-29

func Atod added in v1.0.17

func Atod(s string, defs ...time.Duration) time.Duration

Atod convert string to time.Duration. if not found or convert error, returns the first non-zero value from defs.

func HumanDuration added in v1.0.27

func HumanDuration(d time.Duration) string

HumanDuration returns a string representing the duration in the form "3d23h3m5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.

func IsLeapYear added in v1.0.27

func IsLeapYear(t time.Time) bool

func LocalFormat added in v1.2.3

func LocalFormat(a any, f string) string

func LocalFormatDate added in v1.2.3

func LocalFormatDate(a any) string

func LocalFormatDateTime added in v1.2.3

func LocalFormatDateTime(a any) string

func LocalFormatTime added in v1.2.3

func LocalFormatTime(a any) string

func NonZeroDuration added in v1.0.27

func NonZeroDuration(ds ...time.Duration) time.Duration

func NonZeroTime added in v1.0.27

func NonZeroTime(ts ...time.Time) time.Time

func Parse added in v1.0.26

func Parse(value string, layouts ...string) (tt time.Time, err error)

func ParseDuration added in v1.2.4

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

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".

func ParseInLocation added in v1.0.26

func ParseInLocation(value string, loc *time.Location, layouts ...string) (tt time.Time, err error)

func TruncateHours added in v1.0.26

func TruncateHours(t time.Time) time.Time

TruncateHours tuncate hours for time t. Returns the time (local: yyyy-MM-dd 00:00:00).

func TruncateMinutes added in v1.0.26

func TruncateMinutes(t time.Time) time.Time

TruncateMinutes tuncate minutes for time t. Returns the time (yyyy-MM-dd hh:00:00).

func TruncateSeconds added in v1.0.26

func TruncateSeconds(t time.Time) time.Time

TruncateSeconds tuncate seconds for time t. Returns the time (yyyy-MM-dd hh:mm:00).

Types

type HHMM

type HHMM int

HHMM HH:MM (Minutes)

func ParseHHMM

func ParseHHMM(s string) (HHMM, error)

func (HHMM) MarshalJSON

func (hm HHMM) MarshalJSON() ([]byte, error)

func (HHMM) Minutes

func (hm HHMM) Minutes() int

func (HHMM) String

func (hm HHMM) String() string

func (*HHMM) UnmarshalJSON

func (hm *HHMM) UnmarshalJSON(data []byte) (err error)

type MMSS

type MMSS int

MMSS MM:SS (Seconds)

func ParseMMSS

func ParseMMSS(s string) (MMSS, error)

func (MMSS) MarshalJSON

func (ms MMSS) MarshalJSON() ([]byte, error)

func (MMSS) Seconds

func (ms MMSS) Seconds() int

func (MMSS) String

func (ms MMSS) String() string

func (*MMSS) UnmarshalJSON

func (ms *MMSS) UnmarshalJSON(data []byte) (err error)

Jump to

Keyboard shortcuts

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