Giter VIP home page Giter VIP logo

work_calendar's Introduction

WorkCalendar

A small, lean customizable ruby library to determine work days.

Usage

Customize weekdays and/or holidays


WorkCalendar.configure do |c|
  c.weekdays = %i[sat sun mon tue wed]
  c.holidays = [Date.new(2016, 8, 8)]
end

Check if a given day is a business day

WorkCalendar.active?(DATE)

Get the last business day x days before a date

WorkCalendar.days_before(x, DATE)

Get the first business day x days after a date

WorkCalendar.days_after(x, DATE)

Get all business days between two dates

WorkCalendar.between(FROM_DATE, TO_DATE)

Implementation

I was shooting for something that was super lean and super simple. So I test drove it according to the requirements provided. I started out with the active? method since that was the core of the implementation; all other behaviour relies on it somehow. Once completed I was able to use active? to implement the rest of the required behaviour.

Considerations

  • I decided to use OpenStruct instead of a class to maintain the custom configuration because it helped make the code look simpler and shorter. All behaviour was heavily tested (Test Driven!) and using a class over OpenStruct made no difference in the behaviour. In the end I chose OpenStruct for the simplicity.

  • I added a method reset_to_default_config! as a means to avoid test pollution in my test suite. I didn't feel the need to unit test this method because the tests would fail pretty loudly anyway without a way to clear any customizations.

Running the Tests

  • clone the repo: git clone https://github.com/sufyanadam/work_calendar

  • cd /path/to/repo-you-just-cloned

  • bundle

  • rspec

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.