bigduration

package module
v0.0.0-...-88d3399 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2016 License: MIT Imports: 4 Imported by: 18

README

BidDuration

Like time.Duration but with "year", "month" and "day" making the following assumptions:

bigduration.Day   = 24 * time.Hour
bigduration.Month = 30 * bigduration.Day
bigduration.Year  = 365 * bigduration.Day

Check the godocs

Documentation

Index

Examples

Constants

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

Variables

This section is empty.

Functions

This section is empty.

Types

type BigDuration

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

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.

func (*BigDuration) Until

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.

Jump to

Keyboard shortcuts

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