planner

package module
v0.0.0-...-c11d4ba Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2017 License: MIT Imports: 6 Imported by: 0

README

go-period

Partial implementation of ISO8601 duration/period in golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysInMonth

func DaysInMonth(year int, month time.Month, loc *time.Location) int

DaysInMonth returns the number of days in given month of given year.

func DaysInYear

func DaysInYear(year int, loc *time.Location) int

DaysInYear returns the number of days in given given year.

Types

type Period

type Period struct {
	Years   int
	Months  int
	Weeks   int
	Days    int
	Hours   int
	Minutes int
	Seconds int
}

Period ISO-8601, independent of calendar (unless at moment it is applied to a timestamp with calendar reference).

func Between

func Between(start, end time.Time, loc *time.Location) (period Period)

Between returns the period between two timestamps in a given location (hence DST may be noticeable). It first determines the date period between two timestamps (i.e. years, months, days). The start date is adjusted by the date period and then the time period between the timestamps are determined (i.e. hours, minutes, seconds). Finally the date and time parts are adjusted by flowing components, e.g. negative seconds are adjusted for positive minutes (and vice versa).

Example: 2016-02-28 and 2016-03-31 are +(1 month and 3 days) or -(1 month and 3 days) apart, note the inclusion of a leap day 2016 2017-03-26 00:00:00 and 2016-03-26 06:00:00 Europe/Amsterdam are +(5 hours) or -(5 hours) apart, note the DST transition 2017-03-26 00:00:00 and 2016-03-27 02:00:00 Europe/Amsterdam are +(1 day and 2 hours) or -(1 day and 2 hours) apart, note the DST insensitivity 2017-03-31 04:15:00 and 2016-03-31 05:10:00 are +(55 minutes) or -(55 minutes) apart, note the partial hour (similar in case of partial minute)

func FromDuration

func FromDuration(duration time.Duration) (*Period, error)

FromDuration returns period, floored to nearest second.

func FromString

func FromString(str string) (*Period, error)

FromString returns period parsed from string.

func (Period) Apply

func (period Period) Apply(t time.Time) time.Time

Apply period to timestamp and return result.

func (Period) HasDatePart

func (period Period) HasDatePart() bool

HasDatePart returns true iff any of years, months, weeks or days is not 0.

func (Period) HasTimePart

func (period Period) HasTimePart() bool

HasTimePart returns true iff any of hours, minutes or seconds is not 0.

func (Period) Normalize

func (period Period) Normalize() Period

Normalize period(seconds to minutes, minutes to hours, hours to days, weeks to days, months to years).

func (Period) String

func (period Period) String() string

Jump to

Keyboard shortcuts

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