Thanks to visit codestin.com
Credit goes to github.com

Skip to content

manuelarte/gotimeplus

Repository files navigation

🕐GoTime Plus(+)

Go Go Report Card coverage version

GoTime Plus is a Go library that adds some missing functionality to the standard time.Time Go package.

⬇️How to use it

go get github.com/manuelarte/gotimeplus@latest

🚀Features

GoTime Plus contains the following features:

LocalDate

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)

LocalTime

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)

LocalDateTime

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))

TimePeriod

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. Use time.Time{} for no lower limit.
  • endTime: The end of the time period. Use time.Time{} for no upper limit.

Returns:

  • tp: The resulting TimePeriod.
  • 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  ____|‾‾‾‾|_________...

📂Examples

Refer to the examples directory for usage examples.

About

Utility TimePeriod struct for Golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •