ht

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 8 Imported by: 0

README

ht - Human-readable types

Go Reference

This package provides parsing and printing utilities for:

  • Durations with an additional d unit;
  • Byte sizes;
  • Clocks;
  • Time rates.

Documentation

Overview

Package ht provides parsing and printing utilities for human-readable types.

Index

Constants

View Source
const (
	KB ByteSizeSI = 1000
	MB            = KB * 1000
	GB            = MB * 1000
	TB            = GB * 1000
	PB            = TB * 1000
	EB            = PB * 1000
)
View Source
const (
	KiB ByteSizeIEC = 1024
	MiB             = KiB * 1024
	GiB             = MiB * 1024
	TiB             = GiB * 1024
	PiB             = TiB * 1024
	EiB             = PiB * 1024
)
View Source
const (
	Nanosecond  = Duration(time.Nanosecond)
	Microsecond = Duration(time.Microsecond)
	Millisecond = Duration(time.Millisecond)
	Second      = Duration(time.Second)
	Minute      = Duration(time.Minute)
	Hour        = Duration(time.Hour)
	Day         = Duration(24 * time.Hour)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteSizeIEC

type ByteSizeIEC uint64

ByteSizeIEC is a byte size in IEC units.

func ParseByteSizeIEC

func ParseByteSizeIEC(s string) (ByteSizeIEC, error)

ParseByteSizeIEC parses a byte size string. A byte size string is a decimal number with an optional fraction and unit suffix, such as "1k", "1.5M" or "2MB".

Valid IEC units are: - k, K, KiB - kibibyte - M, MiB - mebibyte - G, GiB - gibibyte - T, TiB - tebibyte - P, PiB - pebibyte - E, EiB - exbibyte

Valid SI units are: - kB, KB - kilobyte - MB - megabyte - GB - gigabyte - TB - terabyte - PB - petabyte - EB - exabyte

NOTE: Accepts both IEC and SI units.

func (ByteSizeIEC) AppendText added in v0.3.0

func (b ByteSizeIEC) AppendText(data []byte) ([]byte, error)

func (ByteSizeIEC) MarshalJSON

func (b ByteSizeIEC) MarshalJSON() ([]byte, error)

func (ByteSizeIEC) MarshalText

func (b ByteSizeIEC) MarshalText() ([]byte, error)

func (ByteSizeIEC) String

func (b ByteSizeIEC) String() string

func (*ByteSizeIEC) UnmarshalJSON

func (b *ByteSizeIEC) UnmarshalJSON(data []byte) error

func (*ByteSizeIEC) UnmarshalText

func (b *ByteSizeIEC) UnmarshalText(data []byte) error

type ByteSizeSI

type ByteSizeSI uint64

ByteSizeSI is a byte size in SI units.

func ParseByteSizeSI

func ParseByteSizeSI(s string) (ByteSizeSI, error)

ParseByteSizeSI parses a byte size string. A byte size string is a decimal number with an optional fraction and unit suffix, such as "1k", "1.5M" or "2MB".

Valid IEC units are: - k, K, KiB - kibibyte - M, MiB - mebibyte - G, GiB - gibibyte - T, TiB - tebibyte - P, PiB - pebibyte - E, EiB - exbibyte

Valid SI units are: - kB, KB - kilobyte - MB - megabyte - GB - gigabyte - TB - terabyte - PB - petabyte - EB - exabyte

NOTE: Accepts both IEC and SI units.

func (ByteSizeSI) AppendText added in v0.3.0

func (b ByteSizeSI) AppendText(data []byte) ([]byte, error)

func (ByteSizeSI) MarshalJSON

func (b ByteSizeSI) MarshalJSON() ([]byte, error)

func (ByteSizeSI) MarshalText

func (b ByteSizeSI) MarshalText() ([]byte, error)

func (ByteSizeSI) String

func (b ByteSizeSI) String() string

func (*ByteSizeSI) UnmarshalJSON

func (b *ByteSizeSI) UnmarshalJSON(data []byte) error

func (*ByteSizeSI) UnmarshalText

func (b *ByteSizeSI) UnmarshalText(data []byte) error

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

func ClockOf added in v0.3.0

func ClockOf(t time.Time) Clock

func NewClock

func NewClock(hour, minute, second int) Clock

func ParseClock

func ParseClock(s string) (c Clock, err error)

func (Clock) After added in v0.3.0

func (c Clock) After(u Clock) bool

func (Clock) AppendBinary added in v0.4.0

func (c Clock) AppendBinary(b []byte) ([]byte, error)

func (Clock) AppendText added in v0.3.0

func (c Clock) AppendText(b []byte) ([]byte, error)

func (Clock) Before added in v0.3.0

func (c Clock) Before(u Clock) bool

func (Clock) Clock added in v0.4.2

func (c Clock) Clock() (hour, minute, second int)

func (Clock) Compare added in v0.3.0

func (c Clock) Compare(u Clock) int

func (Clock) Hour

func (c Clock) Hour() int

func (Clock) IsZero added in v0.3.0

func (c Clock) IsZero() bool

func (Clock) MarshalBinary added in v0.4.0

func (c Clock) MarshalBinary() ([]byte, error)

func (Clock) MarshalJSON

func (c Clock) MarshalJSON() ([]byte, error)

func (Clock) MarshalText

func (c Clock) MarshalText() ([]byte, error)

func (Clock) Minute

func (c Clock) Minute() int

func (Clock) Second

func (c Clock) Second() int

func (Clock) String

func (c Clock) String() string

func (Clock) Time added in v0.3.0

func (c Clock) Time() time.Time

func (*Clock) UnmarshalBinary added in v0.4.0

func (c *Clock) UnmarshalBinary(b []byte) error

func (*Clock) UnmarshalJSON

func (c *Clock) UnmarshalJSON(b []byte) error

func (*Clock) UnmarshalText

func (c *Clock) UnmarshalText(b []byte) error

type Date added in v0.3.0

type Date struct {
	// contains filtered or unexported fields
}

func DateOf added in v0.3.0

func DateOf(t time.Time) Date

func NewDate added in v0.3.0

func NewDate(year int, month time.Month, day int) Date

func ParseDate added in v0.3.0

func ParseDate(s string) (d Date, err error)

func (Date) Add added in v0.4.1

func (d Date) Add(years, months, days int) Date

func (Date) After added in v0.3.0

func (d Date) After(u Date) bool

func (Date) AppendBinary added in v0.4.0

func (d Date) AppendBinary(b []byte) ([]byte, error)

func (Date) AppendText added in v0.3.0

func (d Date) AppendText(b []byte) ([]byte, error)

func (Date) Before added in v0.3.0

func (d Date) Before(u Date) bool

func (Date) Compare added in v0.3.0

func (d Date) Compare(u Date) int

func (Date) Date added in v0.4.2

func (d Date) Date() (year int, month time.Month, day int)

func (Date) Day added in v0.3.0

func (d Date) Day() int

func (Date) IsZero added in v0.3.0

func (d Date) IsZero() bool

func (Date) MarshalBinary added in v0.4.0

func (d Date) MarshalBinary() ([]byte, error)

func (Date) MarshalJSON added in v0.3.0

func (d Date) MarshalJSON() ([]byte, error)

func (Date) MarshalText added in v0.3.0

func (d Date) MarshalText() ([]byte, error)

func (Date) Month added in v0.3.0

func (d Date) Month() time.Month

func (Date) String added in v0.3.0

func (d Date) String() string

func (Date) Time added in v0.3.0

func (d Date) Time() time.Time

func (*Date) UnmarshalBinary added in v0.4.0

func (d *Date) UnmarshalBinary(b []byte) error

func (*Date) UnmarshalJSON added in v0.3.0

func (d *Date) UnmarshalJSON(b []byte) error

func (*Date) UnmarshalText added in v0.3.0

func (d *Date) UnmarshalText(b []byte) error

func (Date) Weekday added in v0.4.3

func (d Date) Weekday() time.Weekday

func (Date) Year added in v0.3.0

func (d Date) Year() int

type Duration

type Duration time.Duration

Duration is time.Duration with additional day unit (`d`) during parsing and with JSON and Text (un)marshaling support.

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h", "d".

func (Duration) AppendText added in v0.3.0

func (d Duration) AppendText(b []byte) ([]byte, error)

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (Duration) String

func (d Duration) String() string

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type TimeRate added in v0.2.0

type TimeRate struct {
	Period time.Duration
	Units  int
}

TimeRate represents a quantity per time period.

func ParseTimeRate added in v0.2.0

func ParseTimeRate(s string) (r TimeRate, err error)

ParseTimeRate parses a time rate string in the format "units/duration", such as "100/s", "42/1s", "1000/5m", "50/500ms", "10/.2s" or "100/1s200ms".

func (TimeRate) AppendText added in v0.3.0

func (r TimeRate) AppendText(b []byte) ([]byte, error)

func (TimeRate) MarshalJSON added in v0.2.0

func (r TimeRate) MarshalJSON() ([]byte, error)

func (TimeRate) MarshalText added in v0.2.0

func (r TimeRate) MarshalText() ([]byte, error)

func (TimeRate) String added in v0.2.0

func (r TimeRate) String() string

func (*TimeRate) UnmarshalJSON added in v0.2.0

func (r *TimeRate) UnmarshalJSON(data []byte) error

func (*TimeRate) UnmarshalText added in v0.2.0

func (r *TimeRate) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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