Skip to content

GeorgeGorbanev/weekends

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weekends Build Status Gem Version

This gem import class Weekend that help to identify weekend dates.

Usage

It is possible to pass Time, Date, DateTime or ActiveSupport::TimeWithZone to all methods and Time will be returned.

Class does't have ActiveSupport dependency, so Rails dependencies not required.

Nearest methods

This methods returns nearest weekends:

monday = Time.new(2017, 10, 2) 

Weekend.nearest_saturday(monday)
# => 2017-10-07 00:00:00 +0300 

Weekend.nearest_sunday(monday)
# => 2017-10-08 00:00:00 +0300 

Weekend.nearest_full_weekends(monday)
# => 2017-10-07 00:00:00 +0300..2017-10-08 00:00:00 +0300 

If given weekend, methods will return next weekend:

saturday = Time.new(2017, 10, 7)

Weekend.nearest_saturday(saturday)
# => 2017-10-14 00:00:00 +0300 
 
# ...

On date

There is also basic method to check if date are weekend:

monday = Time.new(2017, 10, 2) 
saturday = Time.new(2017, 10, 7)

Weekend.on_date?(monday)
# => false 

Weekend.on_date?(saturday)
# => true 

Installation

Add this line to your application's Gemfile:

gem 'weekends'

And then execute:

$ bundle

Or install it yourself as:

$ gem install weekends

TODO:

  • add Rails optional monky patching, like Date.today.weekend? and Date.today.nearest_sunday;
  • add getter of weekends on range of dates;
  • add schedule with optionals weekend (for schedule not only 5/2, but 2/2, 2/3 or first weekday not monday).

License

The gem is available as open source under the terms of the MIT License.

About

Help to find weekend dates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published