kbtime

package
v5.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: BSD-3-Clause, BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLongDuration

func AddLongDuration(tval time.Time, duration string) (ret time.Time, err error)

AddLongDuration parses time duration from `duration` argument and adds to time in `now`, returning the resulting time. The duration format is similar to `time` package duration format, with the following changes: - additional duration units are supported:

  • 'D' for days,
  • 'M' for months,
  • 'Y' for years,
  • fractional numbers are *not* supported,
  • negative numbers are *not* supported,
  • whitespace at the beginning and end of duration string is ignored,
  • optionally there can be one whitespace character between the number and unit.

Long durations are handled using Time.AddDate function, which works by adding given number of years, months, and days to tval. It normalizes its result, for example, adding one month to October 31 yields December 1, the normalized form for November 31.

Examples:

`AddLongDuration(time.Now(), "1000 Y")`
`AddLongDuration(time.Now(), "7 D")`
`AddLongDuration(then, "1 M")`

func RelTime

func RelTime(a, b time.Time, albl, blbl string) string

RelTime is a thin wrapper around github.com/dustin/go-humanize in order to provide more accurate data for large durations. Below description is from go-humanize:

RelTime formats a time into a relative string.

It takes two times and two labels. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.

RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"

Types

This section is empty.

Jump to

Keyboard shortcuts

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