GoTime Plus is a Go library that adds some missing functionality to the standard time.Time Go package.
go get github.com/manuelarte/gotimeplus@latestGoTime Plus contains the following features:
Same concept as java LocalDate, this struct represents a date, often viewed as year-month-day.
This struct does not represent a time or time-zone. Instead, it is a description of the date, as used for birthdays.
It cannot represent a time.Time without additional information such a time-zone.
e.g.:
goBirthdate := localdate.New(2009, time.November, 10)Same concept as java LocalTime. This struct represents a time without a time-zone, such as 10:15:30.
This struct does not represent a time or time-zone. Instead, it is a description of the local time, as seen on a wall clock.
It cannot represent a time.Time without additional information such as date and a time-zone.
e.g.:
lunchTime := localtime.New(12, 0, 0, 0)Same concept as java LocalDateTime. This struct represents a date-time, such as 2007-12-03T10:15:30.
This struct does not represent a time-zone. Instead, it is a description of the date plus a time.
It cannot represent a time.Time without additional information such as a time-zone.
e.g.:
newYear2025 := localdatetime.New(localdate.New(2025, 1, 1), localtime.New(0, 0, 0, 0))Create a TimePeriod instance by specifying a start time and an end time:
tp, err := timeperiod.New(startTime, endTime)
startTime: The beginning of the time period. Usetime.Time{}for no lower limit.endTime: The end of the time period. Usetime.Time{}for no upper limit.
Returns:
tp: The resultingTimePeriod.err: An error if the inputs are invalid.
Note
The TimePeriod is built based on the overlapping period between the two dates.
Input Times
start time ____|________...
end time _________|___...
Resulting Time Period
tp ____|‾‾‾‾|___...
Warning
Passing a zero value for startTime or endTime indicates an unbounded period on that side.
The struct also provides a function Overlaps. This method checks whether two time periods overlap.
If so, returns the overlapping period, e.g.:
Input Time Periods
tp1 ____|‾‾‾‾‾‾‾‾‾‾‾‾‾‾...
tp2 _________|‾‾‾‾‾‾|__...
Resulting Overlap
tp ____|‾‾‾‾|_________...
Refer to the examples directory for usage examples.