Skip to content

Period provides a set of missing Time Range to Go, it cover all basic operations regardings time ranges.

License

Notifications You must be signed in to change notification settings

garagegigs/period

 
 

Repository files navigation

Go Period

Author GoDoc Software License

Period provides a set of missing Time Range to Go, it cover all basic operations regardings time ranges. A Go port of thephpleague/period based on Resolving Feature Envy in the Domain by Mathias Verraes and extends the concept to cover all basic operations regarding time ranges.

Highlights

  • Treats Time Range as time objects
  • Exposes many named constructors to ease time range creation
  • Covers all basic manipulations related to time range

Install Period using go get.

$ go get github.com/studiofrenetic/period

Doc

https://godoc.org/github.com/studiofrenetic/period

Examples

// Accessing time range properties
p, err := period.CreateFromMonth(2015, 3) // {2015-01-12 00:00:00 +0000 UTC 2015-01-19 00:00:00 +0000 UTC}
if err != nil {
    log.Fatal(err)
}

// Comparing time ranges
p, err := period.CreateFromWeek(2015, 3)
if err != nil {
    log.Fatal(err)
}
alt := period.CreateFromDuration(time.Date(2015, 1, 14, 0, 0, 0, 0, time.UTC), time.Duration(24*7)*time.Hour) // {2015-01-14 00:00:00 +0000 UTC 2015-01-21 00:00:00 +0000 UTC}
sameDuration := p.SameDurationAs(alt) // true

p := period.CreateFromDuration(time.Date(2015, 1, 1, 0, 0, 0, 0, time.UTC), (time.Duration(2) * time.Hour))
shouldContains := time.Date(2015, 1, 1, 0, 30, 0, 0, time.UTC)
contains := p.Contains(shouldContains)

// Modifying time ranges
p.Next()

Testing

$ go test -v

Roadmap

Constructor

  • Period{}
  • CreateFromYear
  • CreateFromSemester
  • CreateFromQuarter
  • CreateFromMonth
  • CreateFromWeek
  • CreateFromDuration
  • CreateFromDurationBeforeEnd

Comparing Periods

Comparing endpoints

  • Contains(another_period)
  • Overlaps
  • SameValueAs
  • Abuts
  • IsBefore
  • IsAfter
  • Diff

Comparing durations

  • DurationGreaterThan
  • DurationLessThan
  • SameDurationAs
  • CompareDuration
  • DurationDiff
  • TimestampDurationDiff

Modifying Periods

Using endpoints

  • StartingOn
  • EndingOn

Using duration

  • WithDuration
  • Add
  • Sub
  • Next
  • Previous

Using Period objects

  • Merge
  • Intersect
  • Gap

Doc

  • API
  • Accessing time range properties
  • Iterate over a time range
  • Comparing time ranges
  • Modifying time ranges

Contributing

Please feel free to submit issues, fork the repository and send pull requests!

Contributions are welcome and will be fully credited. Please see CONTRIBUTING for details.


Licence

Copyright (c) 2015 Studio Frenetic

Please consider promoting this project if you find it useful.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Period provides a set of missing Time Range to Go, it cover all basic operations regardings time ranges.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%