humanize

package
v0.1.71 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package humanize converts raw machine values into human-presentable strings — comma-grouped integers today; the same category of helper as byte-size ("4.2 MB"), relative-time ("3 days ago"), or ordinal ("1st") formatting belongs here too as those needs come up (see dustin/go-humanize for the shape of a mature version of this idea). It has no boxy-specific coupling and is safe to use from any consumer, in-repo or not. Scope discipline: this package formats values for *display*; it does not parse human input back into machine values, and it is not a general string- utilities dumping ground — a helper that doesn't fit "raw value -> human string" belongs elsewhere.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommaInt

func CommaInt(value int64) string

CommaInt formats value with thousands separators, e.g. 4096 -> "4,096" and -1234567 -> "-1,234,567".

func ShortDuration added in v0.1.68

func ShortDuration(d time.Duration) string

ShortDuration formats a non-negative duration as a compact single-unit approximation — "42s", "3m", "11m", "1h", "2d" — the style used for a dashboard's "how long has this been in its current state" column, rather than Go's own more precise but noisier "1h2m3s". A negative duration (e.g. a zero/unset timestamp subtracted from now, producing a negative elapsed value) returns "—" rather than a misleading negative-looking string. A zero duration is not treated as "unknown" here, since a real zero-elapsed duration ("0s", just happened) is a valid input distinct from an unknown one — callers with a genuinely unknown source timestamp should check that timestamp before calling, not rely on this function to detect it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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