duration

package
v0.72.7 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (
	UnitYear        Unit = "year"
	UnitMonth       Unit = "month"
	UnitWeek        Unit = "week"
	UnitDay         Unit = "day"
	UnitHour        Unit = "hour"
	UnitMinute      Unit = "minute"
	UnitSecond      Unit = "second"
	UnitMillisecond Unit = "millisecond"
	UnitMicrosecond Unit = "microsecond"
	UnitNanosecond  Unit = "nanosecond"

	UnitYearPlural        = "years"
	UnitMonthPlural       = "months"
	UnitWeekPlural        = "weeks"
	UnitDayPlural         = "days"
	UnitHourPlural        = "hours"
	UnitMinutePlural      = "minutes"
	UnitSecondPlural      = "seconds"
	UnitMillisecondPlural = "milliseconds"
	UnitMicrosecondPlural = "microseconds"
	UnitNanosecondPlural  = "nanoseconds"

	UnitBusinessDay = "businessday"

	UnitSuffixNanosecond  = "ns"
	UnitSuffixMicrosecond = "us"
	UnitSuffixMillisecond = "ms"
	UnitSuffixSecond      = "s"
	UnitSuffixMinute      = "m"
	UnitSuffixHour        = "h"
	UnitSuffixDay         = "d"
	UnitSuffixWeek        = "w"

	Day         = 24 * time.Hour
	Week        = 7 * Day
	Year        = 365 * Day
	Decade      = 10 * Year
	Score       = 2 * Decade
	Century     = 10 * Decade
	WorkDay     = 8 * time.Hour
	WorkWeek    = 5 * WorkDay
	WorkDay996  = 12 * time.Hour
	WorkWeek996 = 6 * WorkDay996

	HoursPerDay = float32(24)
	DaysPerWeek = float32(7)

	DaySeconds  = 24 * 60 * 60
	WeekSeconds = 7 * DaySeconds
	YearSeconds = (365 * DaySeconds) + (6 * 60 * 60)
)

Variables

This section is empty.

Functions

func DurationDays

func DurationDays(d time.Duration) float64

func DurationDaysInt64

func DurationDaysInt64(dur time.Duration) int64

func DurationStringMinutesSeconds

func DurationStringMinutesSeconds(durationSeconds int64) (string, error)

func DurationStringUnit

func DurationStringUnit(d, unit time.Duration, prec int, addSuffix bool) string

DurationStringUnit converts a Duration to a string with a fixed time unit. If an invalid `unit`, is provided, the function will return the output of `time.Duration.String()`.

func DurationUnitSuffix

func DurationUnitSuffix(unit time.Duration) string

func DurationWeeks

func DurationWeeks(d time.Duration) float64

func DurationYears

func DurationYears(d time.Duration) float64

func FormatDurationInfoMinSec

func FormatDurationInfoMinSec(di DurationInfo) string

FormatDurationInfoMinSec returns the duration as a simple string like 01:01.

func MaxDuration

func MaxDuration(durs []time.Duration) time.Duration

func MustParseDuration

func MustParseDuration(s string) time.Duration

func NewDuration

func NewDuration(day, hour, min, sec, nsec int) time.Duration

func NewDurationFloat

func NewDurationFloat(day, hour, min, sec float64, nsec int64) time.Duration

func NewDurationStrings

func NewDurationStrings(hour, min, sec string) (time.Duration, error)

func NowDeltaDuration

func NowDeltaDuration(d time.Duration) time.Time

func NowDeltaParseDuration

func NowDeltaParseDuration(s string) (time.Time, error)

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration adds days (d), weeks (w), years (y).

func SubDuration

func SubDuration(dur1, dur2 time.Duration) time.Duration

SubDuration subtracts one duration from another and returns the result as a `time.Duration`.

func SumDurations

func SumDurations(durations ...time.Duration) time.Duration

Types

type DurationInfo

type DurationInfo struct {
	DaysPerWeek  float32
	HoursPerDay  float32
	Weeks        int64
	Days         int64
	Hours        int64
	Minutes      int64
	Seconds      int64
	Milliseconds int64
	Microseconds int64
	Nanoseconds  int64
}

DurationInfo is a struct that holds integer values for each time unit including hours, minutes, seconds milliseconds, microseconds, and nanoseconds.

func NewDurationInfo

func NewDurationInfo(d time.Duration, daysPerWeek, hoursPerDay float32) DurationInfo

NewDurationInfo returns a DurationInfo struct for a duration in nanos. If 'daysPerWeek` or `hoursPerDay` are set to zero, the default values of 7 and 24 are used.

func ParseDurationInfo

func ParseDurationInfo(s string) (DurationInfo, error)

ParseDurationInfo converts a Jira human readable string into a `DurationInfo` struct.

func (DurationInfo) Duration

func (di DurationInfo) Duration(hoursPerDay, daysPerWeek float32) time.Duration

Duration returns a `time.Duration` struct. Params for `hoursPerDay` and `daysPerWeek` are used for atlernate values such as working hours per day and working days per week, e.g. 8 hours per day and 5 days per week.

type DurationInfoString

type DurationInfoString struct {
	DaysPerWeek  float32
	HoursPerDay  float32
	Weeks        string
	Days         string
	Hours        string
	Minutes      string
	Seconds      string
	Milliseconds string
	Microseconds string
	Nanoseconds  string
}

DurationInfoString represets a set of time duration data. It is useful for converting parsed time data into a `time.Duration` struct. `DaysPerWeek` and `HoursPerDay` are provided as overrides to standard value of 7 and 24 in the case of business context, e.g. 5 days per week and 8 hours per day.

func (DurationInfoString) Duration

func (dis DurationInfoString) Duration() (time.Duration, error)

type Durations

type Durations []time.Duration

type Spec

type Spec struct {
	Value int64 `json:"value" yaml:"value"`
	Unit  Unit  `json:"unit" yaml:"unit"`
}

func (Spec) Duration

func (s Spec) Duration() (time.Duration, error)

type Unit

type Unit string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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