Documentation ¶
Overview ¶
Package humanize provides methods for formatting and parsing values in human readable form.
Index ¶
- Constants
- type Humanizer
- func (humanizer *Humanizer) BitPrefix(value float64, decimals int, threshold int64, short bool) string
- func (humanizer *Humanizer) BitPrefixFast(value float64) string
- func (humanizer *Humanizer) HumanizeNumber(value float64, digits int) string
- func (humanizer *Humanizer) HumanizeParts(value float64, allowedZeroes int) string
- func (humanizer *Humanizer) ParseDuration(input string) (time.Duration, error)
- func (humanizer *Humanizer) ParsePrefix(input string) (*big.Float, error)
- func (humanizer *Humanizer) SecondsToTimeString(duration int64) string
- func (humanizer *Humanizer) SiPrefix(value float64, decimals int, threshold int64, short bool) string
- func (humanizer *Humanizer) SiPrefixFast(value float64) string
- func (humanizer *Humanizer) TimeDiff(startDate, endDate time.Time, precise bool) string
- func (humanizer *Humanizer) TimeDiffNow(date time.Time, precise bool) string
Constants ¶
const ( Second = 1 Minute = 60 Hour = 60 * Minute Day = 24 * Hour Week = 7 * Day Month = 30 * Day Year = 12 * Month LongTime = 35 * Year )
Time constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Humanizer ¶
type Humanizer struct {
// contains filtered or unexported fields
}
Humanizer is the main struct that provides the public methods.
func (*Humanizer) BitPrefix ¶
func (humanizer *Humanizer) BitPrefix(value float64, decimals int, threshold int64, short bool) string
BitPrefix appends a bit prefix to the value and converts it accordingly. Arguments:
value - value to be converted (should be in bytes). decimals - decimal precision for the converted value. threshold - upper bound of the value range to be ignored. Lower bound is 1/threshold. short - whether to use short or long prefix.
func (*Humanizer) BitPrefixFast ¶
BitPrefixFast is a convenience wrapper over BitPrefix. Precision is 2 decimal place. Will not prefix values smaller than 1024 and will append only the short prefix.
func (*Humanizer) HumanizeNumber ¶
HumanizeNumber makes the number easily readable by adding decimal separators. Arguments:
value - the value to be formatted digits - number of (max) fraction digits to be shown
func (*Humanizer) HumanizeParts ¶
HumanizeParts makes part of one fractions human readable, e.g.: 0.02 -> 2%, 0.007 -> 7‰. Arguments:
value - the value to be formatted allowedZeroes - number of leading zeroes allowed in the fraction before moving to a smaller unit
func (*Humanizer) ParseDuration ¶
ParseDuration will return time duration as parsed from input string.
func (*Humanizer) ParsePrefix ¶
ParsePrefix will return a number as parsed from input string.
func (*Humanizer) SecondsToTimeString ¶
SecondsToTimeString converts the time in seconds into a human readable timestamp, eg.:
76 -> 01:16 3620 -> 1:00:20
func (*Humanizer) SiPrefix ¶
func (humanizer *Humanizer) SiPrefix(value float64, decimals int, threshold int64, short bool) string
SiPrefix appends a SI prefix to the value and converts it accordingly. Arguments:
value - value to be converted. decimals - decimal precision for the converted value. threshold - upper bound of the value range to be ignored. Lower bound is 1/threshold. short - whether to use short or long prefix.
func (*Humanizer) SiPrefixFast ¶
SiPrefixFast is a convenience function for easy prefixing with a SI prefix. Precision is 1 decimal place. Will not prefix values in range 0.01 - 1000 and will append only the short prefix.