bigduration: github.com/ninibe/bigduration Index | Examples | Files

package bigduration

import "github.com/ninibe/bigduration"

Index

Examples

Package Files

bigduration.go

Constants

const (
    Day   = 24 * time.Hour
    Month = 30 * Day
    Year  = 365 * Day
)

type BigDuration Uses

type BigDuration struct {
    Years  int
    Months int
    Days   int
    Nanos  time.Duration
}

BigDuration represents a duration in years (365 days), months (30 days), weeks and days alongside stadard time.Duration that can be parsed from hours, minutes and seconds.

func ParseBigDuration Uses

func ParseBigDuration(s string) (bd BigDuration, err error)

ParseBigDuration parses a BigDuration string simply splitting by keyword and then using time.ParseDuration for smaller units

Code:

bd, _ := bigduration.ParseBigDuration("1year2month1day5h10s")
duration := bd.Duration() // convert to time.Duration
fmt.Println(duration)

Output:

10229h0m10s

func (*BigDuration) Add Uses

func (bd *BigDuration) Add(u BigDuration) BigDuration

Add returns the sum of both big durations

func (*BigDuration) Compact Uses

func (bd *BigDuration) Compact() string

Compact returns a string representation compacting smaller units into bigger ones when possible

func (*BigDuration) Duration Uses

func (bd *BigDuration) Duration() time.Duration

Duration returns equivalent time.Duration

func (*BigDuration) From Uses

func (bd *BigDuration) From(u time.Time) time.Time

From takes a time and returns the time adding the big duration in a calendar sensitive way months are no longer 30 days but calendar months instead, leap years also accounted for.

func (BigDuration) MarshalJSON Uses

func (bd BigDuration) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*BigDuration) String Uses

func (bd *BigDuration) String() string

String returns a string representing the duration in the form "2month23days2h3m0.5s". Leading zero units are omitted.

func (*BigDuration) UnmarshalJSON Uses

func (bd *BigDuration) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

func (*BigDuration) Until Uses

func (bd *BigDuration) Until(u time.Time) time.Time

Until takes a time and returns the time subtracting the big duration in a calendar sensitive way months are no longer 30 days but calendar months instead, leap years also accounted for.

Package bigduration imports 4 packages (graph) and is imported by 6 packages. Updated 2016-07-31. Refresh now. Tools for package owners.