timestring

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 3 Imported by: 2

README

go-timestring

Go GoDoc GitHub issues GitHub forks GitHub stars GitHub license

Yet another readable time formatter for Golang

Documentation

Overview

Package timestring provides some helper functions for displaying time in a human readable way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Duration added in v0.2.0

type Duration struct {
	Days         int64
	Hours        int64
	Minutes      int64
	Seconds      int64
	Milliseconds int64
}

Duration contains the absolute number of each field with all fields adding up to the total duration, so Hours is only the amount of hours to be displayed, unlike (time.Duration).Hours().

func TimeDurationToDuration added in v0.2.0

func TimeDurationToDuration(td time.Duration) Duration

TimeDurationToDuration converts a time.Duration to the timestring.Duration for easier display of durations.

type Formatter

type Formatter interface {
	Option(...FormatterOption) Formatter
	String(time.Duration) string
}

Formatter is the interface that any timestring formatter should match.

var LongProcess Formatter = LongProcessFormatter{}

LongProcess is the ready-to-use Long Process Formatter.

type FormatterOption added in v0.2.0

type FormatterOption uint

FormatterOption is a list of options that can be applied to the standard formatters.

const (
	// NoSpaces is a FormatterOption that tells the formatter to ignore spaces between values.
	NoSpaces FormatterOption = iota

	// NoUnitSpaces is a FormatterOption that tells the formatter to ignore spaces betwee values and
	// units.
	NoUnitSpaces

	// Abbreviated  is a FormatterOption that tells the formatter to abbreviate the units
	// (eg. "d" instead of "days").
	Abbreviated

	// ShowMSOnSeconds is a FormatterOption that tells the formatter to show milliseconds when
	// the value is less than a minute (59 seconds or less).
	ShowMSOnSeconds
)

type LongProcessFormatter

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

LongProcessFormatter is a Long Process Formatter.

It is a formatter that handles processes that would be considered long running, like displaying the uptime of a server or service.

func (LongProcessFormatter) Option added in v0.2.0

Option returns a Long Process Formatter with the applied options.

func (LongProcessFormatter) String

String returns a human readable string using the Long Process Formatter.

Jump to

Keyboard shortcuts

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