approx

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: BSD-3-Clause Imports: 4 Imported by: 1

README

approx

Build Status codecov.io Go Report Card GitHub Release GoDoc

Package approx adds support for durations of days, weeks and years.

Documentation

Overview

Package approx provides a set of approximate duration units that extend the standard go package time.Duration.

Index

Constants

This section is empty.

Variables

View Source
var (
	Day  = time.Hour * 24
	Week = Day * 7
	Year = Day * 365
)
View Source
var (
	ErrInvalidDuration = errors.New("time: invalid duration")
)

Functions

func ParseDuration

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", "w", "y". Units "day", "week" and "year" are all approximate units with the values of "24h" in a day, "7d" in a week, "365d" in a year.

func String

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

String converts a time.Duration into the larger approximate units for output. The default form is to prefix days, but weeks and years may be prepended, too. Passing a string with the options "d", "w", and "y" will enable each. Order and repeats are ignored.

Types

This section is empty.

Jump to

Keyboard shortcuts

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