Documentation
¶
Index ¶
- Constants
- func Bytes(s uint64) string
- func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
- func FormatNumber[T constraints.Float](n T, max_num_of_decimals ...int) string
- func IBytes(s uint64) string
- func RelTime(a, b time.Time, albl, blbl string) string
- func ShortDuration(val time.Duration) (ans string)
- func Size[T constraints.Integer | constraints.Float](s T, opts ...SizeOptions) string
- func Time(then time.Time) string
- type RelTimeMagnitude
- type SizeOptions
Constants ¶
const ( Byte = 1 << (iota * 10) KiByte MiByte GiByte TiByte PiByte EiByte )
IEC Sizes. kibis of bits
const ( IByte = 1 KByte = IByte * 1000 MByte = KByte * 1000 GByte = MByte * 1000 TByte = GByte * 1000 PByte = TByte * 1000 EByte = PByte * 1000 )
SI Sizes.
const ( Day = 24 * time.Hour Week = 7 * Day Month = 30 * Day Year = 12 * Month LongTime = 37 * Year )
Seconds-based time units
Variables ¶
This section is empty.
Functions ¶
func CustomRelTime ¶
func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
CustomRelTime formats a time into a relative string.
It takes two times two labels and a table of relative time formats. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.
func FormatNumber ¶
func FormatNumber[T constraints.Float](n T, max_num_of_decimals ...int) string
func IBytes ¶
IBytes produces a human readable representation of an IEC size. IBytes(82854982) -> 79 MiB
func RelTime ¶
RelTime formats a time into a relative string.
It takes two times and two labels. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.
RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"
func ShortDuration ¶
Render the duration in exactly 8 visual chars
func Size ¶
func Size[T constraints.Integer | constraints.Float](s T, opts ...SizeOptions) string
Types ¶
type RelTimeMagnitude ¶
A RelTimeMagnitude struct contains a relative time point at which the relative format of time will switch to a new format string. A slice of these in ascending order by their "D" field is passed to CustomRelTime to format durations.
The Format field is a string that may contain a "%s" which will be replaced with the appropriate signed label (e.g. "ago" or "from now") and a "%d" that will be replaced by the quantity.
The DivBy field is the amount of time the time difference must be divided by in order to display correctly.
e.g. if D is 2*time.Minute and you want to display "%d minutes %s" DivBy should be time.Minute so whatever the duration is will be expressed in minutes.