timeutil

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ISO8601 = "2006-01-02T15:04:05-0700"

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

func FormatSimplifiedDuration

func FormatSimplifiedDuration(d time.Duration) string

func ParseDuration

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

ParseDuration parses a duration string. This works the same as time.ParseDuration except that it supports additional approximated units:

  • d: days (defined as 24 hours)
  • w: weeks (defined as 7 days)

func ParseExpr

func ParseExpr(s string) (time.Time, error)

ParseExpr is a convenience interface to ParseExprRef which provides time.Now as the reference time. It's usually the one you want.

func ParseExprRef

func ParseExprRef(s string, ref time.Time) (time.Time, error)

ParseExprRef parses a time expression and returns the point in time that it represents. Many expression refer to relative time, which is evaluated relative to the provided reference time.

This function supports a variety of inputs:

  • The special constants: "today", "yesterday", and "tomorrow", which refers to midnight on those days, relative to the reference time;

  • The special constant: "now", which refers to the reference time, which is simply returned;

  • A relative time adjustment, in the form: "(+|-)duration", where "duration" is a duration (as implemented in this package) relative to the reference time. For example, the expression "-10d" refers to the point in time 10 days ago at the same time as this function is invoked;

  • A date expressed as the day and month, which is assumed to be in the reference year; for example "11-14" refers to midnight on November 14th of the year of the reference time;

  • A date expressed as the day, month, and year without a time, which refers to midnight on that date.

Any other input, including an empty string is an error.

Types

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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