human

package
v0.0.0-...-b945540 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: BSD-3-Clause Imports: 7 Imported by: 10

Documentation

Overview

Package human provides human friendly display formats.

Index

Constants

View Source
const MIN_TICKS = 2

Variables

This section is empty.

Functions

func Duration

func Duration(duration time.Duration) string

Duration returns a human friendly description of the given time.Duration.

For example Duration(61*time.Second) returns " 1m 1s".

The length of the string returned is guaranteed to always be 7. A negative duration is treated the same as a positive duration.

func FlotTickMarks

func FlotTickMarks(ts []int64, tz string) []interface{}

FlotTickMarks returns a struct that will serialize into JSON that Flot expects for a value for tick marks.

If an error occurs the tick list will be empty.

tz is the timezone, and can be the empty string if the default (Eastern) timezone is acceptable.

func ParseDuration

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

ParseDuration parses a human readable duration. Note that this understands both days and weeks, which time.ParseDuration does not support.

func ToFlot

func ToFlot(ticks []*Tick) []interface{}

ToFlot converts a slice of Ticks into something that will serialize into JSON that Flot consumes, which is an array of 2 element arrays. The 2 element arrays contain an x offset and then a label as a string. For example:

[ [ 0.5, "Saturday" ], [ 1.5, "Sunday" ] ]

Types

type JSONDuration

type JSONDuration time.Duration

JSONDuration is a type that implements the json.Unmarshal interface and can be used to parse human readable durations from configuration files.

func (*JSONDuration) String

func (d *JSONDuration) String() string

func (*JSONDuration) UnmarshalJSON

func (d *JSONDuration) UnmarshalJSON(durBytes []byte) error

type Tick

type Tick struct {
	X     float64
	Value string
}

Tick represents a single tick mark.

func TickMarks

func TickMarks(timestamps []int64, in *time.Location) []*Tick

TickMarks produces human readable tickmarks to span the given timestamps.

The array of timestamps are presumed to be in ascending order. If 'in' is nil then the "Local" time zone is used.

The choice of how to label the tick marks is based on the full time range of the timestamps.

type TimeOp

type TimeOp func(time.Time) string

TimeOp is a function that given a time will return a string that would be a good label for that time.

Jump to

Keyboard shortcuts

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