Code Monkey home page Code Monkey logo

workcalendar2's Introduction

WorkCalendar

A gem to do simple date calculations

Installation

git clone https://github.com/kpandya91/WorkCalendar2.git 
cd WorkCalendar2
gem build workcalendar2.gemspec 
gem install workcalendar2-0.1.0.gem 

Configuration

WorkCalendar.configure do |c|
  c.weekdays = %i[mon tue wed thu fri]
  c.holidays = [Date.new(2014, 12, 31), Date.new(2015, 1, 1), Date.new(2015, 7, 3), Date.new(2015, 12, 25), Date.new(2015, 4, 15), Date.new(2015, 9, 15), Date.new(2015, 11, 22)]
end

Usage

Check if a date is active (is a weekday and not a holiday):

# true if the given date is active, false otherwise
WorkCalendar.active?(Date.new(2015, 7, 3))
# => false

WorkCalendar.active?(Date.new(2015, 10, 14))
# => true

Get nth active date before the given date:

WorkCalendar.days_before(7, Date.new(2015, 1, 8))
# => #<Date: 2014-12-26 ((2457018j,0s,0n),+0s,2299161j)>

Get nth active date after the given date:

WorkCalendar.days_after(5, Date.new(2015, 4, 11))
# => #<Date: 2015-04-20 ((2457133j,0s,0n),+0s,2299161j)>

Get all active dates between the two given dates

WorkCalendar.between(Date.new(2014, 12, 26), Date.new(2015, 1, 7))
#  => [
#     #<Date: 2014-12-26 ((2457018j,0s,0n),+0s,2299161j)>,
#     #<Date: 2014-12-29 ((2457021j,0s,0n),+0s,2299161j)>,
#     #<Date: 2014-12-30 ((2457022j,0s,0n),+0s,2299161j)>,
#     #<Date: 2015-01-02 ((2457025j,0s,0n),+0s,2299161j)>,
#     #<Date: 2015-01-05 ((2457028j,0s,0n),+0s,2299161j)>,
#     #<Date: 2015-01-06 ((2457029j,0s,0n),+0s,2299161j)>
#     ]

workcalendar2's People

Contributors

kpandya3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.