Documentation
¶
Index ¶
- Constants
- type BigDuration
- func (bd *BigDuration) Add(u BigDuration) BigDuration
- func (bd *BigDuration) Compact() string
- func (bd *BigDuration) Duration() time.Duration
- func (bd *BigDuration) From(u time.Time) time.Time
- func (bd BigDuration) MarshalJSON() ([]byte, error)
- func (bd *BigDuration) String() string
- func (bd *BigDuration) UnmarshalJSON(data []byte) (err error)
- func (bd *BigDuration) Until(u time.Time) time.Time
Examples ¶
Constants ¶
const ( Day = 24 * time.Hour Month = 30 * Day Year = 365 * Day )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type 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 ¶
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
Example ¶
package main import ( "fmt" "github.com/ninibe/bigduration" ) func main() { bd, _ := bigduration.ParseBigDuration("1year2month1day5h10s") duration := bd.Duration() // convert to time.Duration fmt.Println(duration) }
Output: 10229h0m10s
func (*BigDuration) Add ¶
func (bd *BigDuration) Add(u BigDuration) BigDuration
Add returns the sum of both big durations
func (*BigDuration) Compact ¶
func (bd *BigDuration) Compact() string
Compact returns a string representation compacting smaller units into bigger ones when possible
func (*BigDuration) Duration ¶
func (bd *BigDuration) Duration() time.Duration
Duration returns equivalent time.Duration
func (*BigDuration) From ¶
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 ¶
func (bd BigDuration) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*BigDuration) String ¶
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 ¶
func (bd *BigDuration) UnmarshalJSON(data []byte) (err error)
UnmarshalJSON implements the json.Unmarshaler interface.