humanize

package module
v0.0.0-...-3c422bf Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 3 Imported by: 3

README

go-humanize an humanization library

Yes, I know https://github.com/dustin/go-humanize exists. However I do not like its implementation for duration, as you path a time and not a duration.

There are far less stuff in this repos, it is just my private package made in a few minutes, in order to avoid to duplicate code in other projects.

Use it if you want, but if your jobs or others jobs depends on it, you should probably not.

Documentation

Overview

Package humanize provides utility type to format values in a readable manner. It focuse on concision over precision.

Index

Examples

Constants

View Source
const (
	Day   = 24 * time.Hour // a day
	Week  = 7 * Day        // a Week
	Month = 30 * Day       // a Month
	Year  = 365 * Day      // a Year
)

Missing time package constants for larger times

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSize

type ByteSize int64

A ByteSize represents a number of bytes, that formats itself using IEC binary prefixes with a radix of 2^10 (1024) like KiB, MiB GiB. It cannot go beyond a fe EbbiByte because we use int64.

Example
fmt.Printf("%s\n", ByteSize(123456))
Output:

120.6 KiB

func (ByteSize) String

func (s ByteSize) String() string

String implement the fmt.Stringer interface

type Duration

type Duration time.Duration

A Duration is a time.Duration that is more readable for long time. i.e. 103h03m15s will format to 4 days 7 hours

Example
fmt.Printf("%s\n", Duration(9*Day+45*time.Hour))
Output:

1 week 3 days

func (Duration) String

func (d Duration) String() string

String implements fmt.Stringer interface

Jump to

Keyboard shortcuts

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