import "github.com/ninibe/bigduration"
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(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 (bd *BigDuration) Add(u BigDuration) BigDuration
Add returns the sum of both big durations
func (bd *BigDuration) Compact() string
Compact returns a string representation compacting smaller units into bigger ones when possible
func (bd *BigDuration) Duration() time.Duration
Duration returns equivalent time.Duration
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 (bd BigDuration) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (bd *BigDuration) String() string
String returns a string representing the duration in the form "2month23days2h3m0.5s". Leading zero units are omitted.
func (bd *BigDuration) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON implements the json.Unmarshaler interface.
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.