work_day 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a428d5a0985e7bc9a97563a73037097c22f2720c
4
+ data.tar.gz: 4b47fed8f749dc917584d0444658d8a673f0e509
5
+ SHA512:
6
+ metadata.gz: 265921473bf6875bc20b4d3e4e76062883e7c9096043ea488c2f4707a88cb6507123bb1c1cf2faae6f98e76056c9c49ae7f3f341b640f94e108d17827b4fa564
7
+ data.tar.gz: c187b4043062a25300cad50401d81e3143a44424b98352d5776d7b689a296f01cbe912240e4c2ce6cc4ae7cfe9066e441172fffeee8ed7579fc5ffe9ce51e82a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.5
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in work_day.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Adriano Bacha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # WorkDay
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/work_day`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'work_day'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install work_day
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/work_day. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1 @@
1
+ ["1990-06-14","1990-09-07","1990-10-03","1990-10-08","1990-11-02","1990-11-15","1990-12-24","1990-12-25","1990-12-31","1991-01-01","1991-02-01","1991-02-11","1991-02-12","1991-03-28","1991-03-29","1991-05-01","1991-05-30","1991-11-15","1991-12-24","1991-12-25","1991-12-31","1992-01-01","1992-03-02","1992-03-03","1992-03-04","1992-04-16","1992-04-17","1992-04-21","1992-05-01","1992-06-18","1992-09-07","1992-10-12","1992-11-02","1992-12-24","1992-12-25","1992-12-31","1993-01-01","1993-02-22","1993-02-23","1993-02-24","1993-04-08","1993-04-09","1993-04-21","1993-05-01","1993-06-10","1993-09-07","1993-10-12","1993-11-02","1993-11-15","1993-12-24","1993-12-25","1993-12-31","1994-02-14","1994-02-15","1994-02-16","1994-03-31","1994-04-01","1994-04-21","1994-05-01","1994-06-02","1994-07-01","1994-09-07","1994-10-03","1994-10-12","1994-11-02","1994-11-15","1994-12-25","1994-12-31","1995-01-01","1995-02-27","1995-02-28","1995-04-13","1995-04-14","1995-04-21","1995-05-01","1995-06-15","1995-09-07","1995-10-12","1995-11-02","1995-11-15","1995-12-25","1995-12-31","1996-01-01","1996-02-19","1996-02-20","1996-04-04","1996-04-05","1996-04-21","1996-05-01","1996-06-06","1996-09-07","1996-10-03","1996-10-12","1996-11-02","1996-11-15","1996-12-25","1997-01-01","1997-02-10","1997-02-11","1997-03-27","1997-03-28","1997-04-21","1997-05-01","1997-05-29","1997-09-07","1997-10-12","1997-11-02","1997-11-15","1997-12-25","1998-01-01","1998-02-23","1998-02-24","1998-04-09","1998-04-10","1998-04-21","1998-05-01","1998-06-11","1998-09-07","1998-10-03","1998-10-12","1998-11-02","1998-11-15","1998-12-25","1999-01-01","1999-02-15","1999-02-16","1999-04-01","1999-04-02","1999-04-21","1999-05-01","1999-06-03","1999-09-07","1999-10-12","1999-11-02","1999-11-15","1999-12-25","2000-01-01","2000-03-06","2000-03-07","2000-04-21","2000-05-01","2000-06-22","2000-09-07","2000-10-12","2000-11-02","2000-11-15","2000-12-25","2001-01-01","2001-02-26","2001-02-27","2001-04-13","2001-04-21","2001-05-01","2001-06-14","2001-09-07","2001-10-12","2001-11-02","2001-11-15","2001-12-25","2002-01-01","2002-02-11","2002-02-12","2002-03-29","2002-04-21","2002-05-01","2002-05-30","2002-09-07","2002-10-12","2002-11-02","2002-11-15","2002-12-25","2003-01-01","2003-03-03","2003-03-04","2003-04-18","2003-04-21","2003-05-01","2003-06-19","2003-09-07","2003-10-12","2003-11-02","2003-11-15","2003-12-25","2004-01-01","2004-02-23","2004-02-24","2004-04-09","2004-04-21","2004-05-01","2004-06-10","2004-09-07","2004-10-12","2004-11-02","2004-11-15","2004-12-25","2005-01-01","2005-02-07","2005-02-08","2005-03-25","2005-04-21","2005-05-01","2005-05-26","2005-09-07","2005-10-12","2005-11-02","2005-11-15","2005-12-25","2006-01-01","2006-02-27","2006-02-28","2006-04-14","2006-04-21","2006-05-01","2006-06-15","2006-09-07","2006-10-12","2006-11-02","2006-11-15","2006-12-25","2007-01-01","2007-02-19","2007-02-20","2007-04-06","2007-04-21","2007-05-01","2007-06-07","2007-09-07","2007-10-12","2007-11-02","2007-11-15","2007-12-25","2008-01-01","2008-02-04","2008-02-05","2008-03-21","2008-04-21","2008-05-01","2008-05-22","2008-09-07","2008-10-12","2008-11-02","2008-11-15","2008-12-25","2009-01-01","2009-02-23","2009-02-24","2009-04-10","2009-04-21","2009-05-01","2009-06-11","2009-09-07","2009-10-12","2009-11-02","2009-11-15","2009-12-25","2010-01-01","2010-02-15","2010-02-16","2010-04-02","2010-04-21","2010-05-01","2010-06-03","2010-09-07","2010-10-12","2010-11-02","2010-11-15","2010-12-25","2011-01-01","2011-03-07","2011-03-08","2011-04-21","2011-04-22","2011-05-01","2011-06-23","2011-09-07","2011-10-12","2011-11-02","2011-11-15","2011-12-25","2012-01-01","2012-02-20","2012-02-21","2012-04-06","2012-04-21","2012-05-01","2012-06-07","2012-09-07","2012-10-12","2012-11-02","2012-11-15","2012-12-25","2013-01-01","2013-02-11","2013-02-12","2013-03-29","2013-04-21","2013-05-01","2013-05-30","2013-09-07","2013-10-12","2013-11-02","2013-11-15","2013-12-25","2014-01-01","2014-03-03","2014-03-04","2014-04-18","2014-04-21","2014-05-01","2014-06-19","2014-09-07","2014-10-12","2014-11-02","2014-11-15","2014-12-25","2015-01-01","2015-02-16","2015-02-17","2015-04-03","2015-04-21","2015-05-01","2015-06-04","2015-09-07","2015-10-12","2015-11-02","2015-11-15","2015-12-25","2016-01-01","2016-02-08","2016-02-09","2016-03-25","2016-04-21","2016-05-01","2016-05-26","2016-09-07","2016-10-12","2016-11-02","2016-11-15","2016-12-25","2017-01-01","2017-02-27","2017-02-28","2017-04-14","2017-04-21","2017-05-01","2017-06-15","2017-09-07","2017-10-12","2017-11-02","2017-11-15","2017-12-25","2018-01-01","2018-02-12","2018-02-13","2018-03-30","2018-04-21","2018-05-01","2018-05-31","2018-09-07","2018-10-12","2018-11-02","2018-11-15","2018-12-25","2019-01-01","2019-03-04","2019-03-05","2019-04-19","2019-04-21","2019-05-01","2019-06-20","2019-09-07","2019-10-12","2019-11-02","2019-11-15","2019-12-25","2020-01-01","2020-02-24","2020-02-25","2020-04-10","2020-04-21","2020-05-01","2020-06-11","2020-09-07","2020-10-12","2020-11-02","2020-11-15","2020-12-25","2021-01-01","2021-02-15","2021-02-16","2021-04-02","2021-04-21","2021-05-01","2021-06-03","2021-09-07","2021-10-12","2021-11-02","2021-11-15","2021-12-25","2022-01-01","2022-02-28","2022-03-01","2022-04-15","2022-04-21","2022-05-01","2022-06-16","2022-09-07","2022-10-12","2022-11-02","2022-11-15","2022-12-25","2023-01-01","2023-02-20","2023-02-21","2023-04-07","2023-04-21","2023-05-01","2023-06-08","2023-09-07","2023-10-12","2023-11-02","2023-11-15","2023-12-25","2024-01-01","2024-02-12","2024-02-13","2024-03-29","2024-04-21","2024-05-01","2024-05-30","2024-09-07","2024-10-12","2024-11-02","2024-11-15","2024-12-25","2025-01-01","2025-03-03","2025-03-04","2025-04-18","2025-04-21","2025-05-01","2025-06-19","2025-09-07","2025-10-12","2025-11-02","2025-11-15","2025-12-25","2026-01-01","2026-02-16","2026-02-17","2026-04-03","2026-04-21","2026-05-01","2026-06-04","2026-09-07","2026-10-12","2026-11-02","2026-11-15","2026-12-25","2027-01-01","2027-02-08","2027-02-09","2027-03-26","2027-04-21","2027-05-01","2027-05-27","2027-09-07","2027-10-12","2027-11-02","2027-11-15","2027-12-25","2028-01-01","2028-02-28","2028-02-29","2028-04-14","2028-04-21","2028-05-01","2028-06-15","2028-09-07","2028-10-12","2028-11-02","2028-11-15","2028-12-25","2029-01-01","2029-02-12","2029-02-13","2029-03-30","2029-04-21","2029-05-01","2029-05-31","2029-09-07","2029-10-12","2029-11-02","2029-11-15","2029-12-25","2030-01-01","2030-03-04","2030-03-05","2030-04-19","2030-04-21","2030-05-01","2030-06-20","2030-09-07","2030-10-12","2030-11-02","2030-11-15","2030-12-25","2031-01-01","2031-02-24","2031-02-25","2031-04-11","2031-04-21","2031-05-01","2031-06-12","2031-09-07","2031-10-12","2031-11-02","2031-11-15","2031-12-25","2032-01-01","2032-02-09","2032-02-10","2032-03-26","2032-04-21","2032-05-01","2032-05-27","2032-09-07","2032-10-12","2032-11-02","2032-11-15","2032-12-25","2033-01-01","2033-02-28","2033-03-01","2033-04-15","2033-04-21","2033-05-01","2033-06-16","2033-09-07","2033-10-12","2033-11-02","2033-11-15","2033-12-25","2034-01-01","2034-02-20","2034-02-21","2034-04-07","2034-04-21","2034-05-01","2034-06-08","2034-09-07","2034-10-12","2034-11-02","2034-11-15","2034-12-25","2035-01-01","2035-02-05","2035-02-06","2035-03-23","2035-04-21","2035-05-01","2035-05-24","2035-09-07","2035-10-12","2035-11-02","2035-11-15","2035-12-25","2036-01-01","2036-02-25","2036-02-26","2036-04-11","2036-04-21","2036-05-01","2036-06-12","2036-09-07","2036-10-12","2036-11-02","2036-11-15","2036-12-25","2037-01-01","2037-02-16","2037-02-17","2037-04-03","2037-04-21","2037-05-01","2037-06-04","2037-09-07","2037-10-12","2037-11-02","2037-11-15","2037-12-25","2038-01-01","2038-03-08","2038-03-09","2038-04-21","2038-04-23","2038-05-01","2038-06-24","2038-09-07","2038-10-12","2038-11-02","2038-11-15","2038-12-25","2039-01-01","2039-02-21","2039-02-22","2039-04-08","2039-04-21","2039-05-01","2039-06-09","2039-09-07","2039-10-12","2039-11-02","2039-11-15","2039-12-25","2040-01-01","2040-02-13","2040-02-14","2040-03-30","2040-04-21","2040-05-01","2040-05-31","2040-09-07","2040-10-12","2040-11-02","2040-11-15","2040-12-25","2041-01-01","2041-03-04","2041-03-05","2041-04-19","2041-04-21","2041-05-01","2041-06-20","2041-09-07","2041-10-12","2041-11-02","2041-11-15","2041-12-25","2042-01-01","2042-02-17","2042-02-18","2042-04-04","2042-04-21","2042-05-01","2042-06-05","2042-09-07","2042-10-12","2042-11-02","2042-11-15","2042-12-25","2043-01-01","2043-02-09","2043-02-10","2043-03-27","2043-04-21","2043-05-01","2043-05-28","2043-09-07","2043-10-12","2043-11-02","2043-11-15","2043-12-25","2044-01-01","2044-02-29","2044-03-01","2044-04-15","2044-04-21","2044-05-01","2044-06-16","2044-09-07","2044-10-12","2044-11-02","2044-11-15","2044-12-25","2045-01-01","2045-02-20","2045-02-21","2045-04-07","2045-04-21","2045-05-01","2045-06-08","2045-09-07","2045-10-12","2045-11-02","2045-11-15","2045-12-25","2046-01-01","2046-02-05","2046-02-06","2046-03-23","2046-04-21","2046-05-01","2046-05-24","2046-09-07","2046-10-12","2046-11-02","2046-11-15","2046-12-25","2047-01-01","2047-02-25","2047-02-26","2047-04-12","2047-04-21","2047-05-01","2047-06-13","2047-09-07","2047-10-12","2047-11-02","2047-11-15","2047-12-25","2048-01-01","2048-02-17","2048-02-18","2048-04-03","2048-04-21","2048-05-01","2048-06-04","2048-09-07","2048-10-12","2048-11-02","2048-11-15","2048-12-25","2049-01-01","2049-03-01","2049-03-02","2049-04-16","2049-04-21","2049-05-01","2049-06-17","2049-09-07","2049-10-12","2049-11-02","2049-11-15","2049-12-25","2050-01-01","2050-02-21","2050-02-22","2050-04-08","2050-04-21","2050-05-01","2050-06-09","2050-09-07","2050-10-12","2050-11-02","2050-11-15","2050-12-25"]
data/lib/holiday.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "json"
2
+ require "singleton"
3
+
4
+ class Holiday
5
+ include Singleton
6
+ attr_reader :holidays
7
+
8
+ def self.load_data
9
+ instance.load_data
10
+ end
11
+
12
+ def load_data
13
+ @holidays = {}
14
+
15
+ file = File.expand_path(File.dirname(__FILE__) + "/../data/holidays.json")
16
+ raw_data = File.read(file)
17
+ parsed = JSON.parse(raw_data)
18
+
19
+ parsed.map do |str|
20
+ splitted = str.split("-")
21
+ date = Date.parse(str)
22
+ @holidays[date.year] ||= []
23
+ @holidays[date.year] << date
24
+ end
25
+
26
+ @holidays
27
+ end
28
+
29
+ def self.in(year)
30
+ load_data if instance.holidays.nil?
31
+ holidays = instance.holidays[year]
32
+ holidays
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module WorkDay
2
+ VERSION = "0.2.0"
3
+ end
data/lib/work_day.rb ADDED
@@ -0,0 +1,41 @@
1
+ require "holiday"
2
+ require "active_support"
3
+ require "active_support/core_ext"
4
+
5
+ module WorkDay
6
+ @holidays = {}
7
+
8
+ def self.work_day?(date)
9
+ if date = date.try(:to_date)
10
+ ![0, 6].include?(date.wday) && !holidays_in(date.year).include?(date)
11
+ end
12
+ end
13
+
14
+ def self.last_until(date, days = 0)
15
+ if date = date.try(:to_date)
16
+ while !work_day?(date)
17
+ date -= 1
18
+ end
19
+ days -= 1
20
+ days == -1 ? date : last_until(1.day.ago(date), days)
21
+ end
22
+ end
23
+
24
+ def self.next_after(date, days = 1)
25
+ day_counter = 0
26
+ while day_counter < days
27
+ date += 1
28
+ day_counter += 1 if work_day?(date)
29
+ end
30
+ work_day?(date) ? date : next_after(date)
31
+ end
32
+
33
+ def self.between(start_date, end_date)
34
+ (start_date.to_date..end_date.to_date).select { |date| work_day?(date) }
35
+ end
36
+
37
+ private
38
+ def self.holidays_in(year)
39
+ @holidays[year] ||= Holiday.in(year)
40
+ end
41
+ end
data/work_day.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'work_day/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "work_day"
8
+ spec.version = WorkDay::VERSION
9
+ spec.authors = ["Adriano Bacha"]
10
+ spec.email = ["abacha@gmail.com"]
11
+
12
+ spec.summary = %q{work days}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.13"
21
+ spec.add_development_dependency "rspec", "~> 3.0"
22
+ spec.add_runtime_dependency "activesupport", "~> 5.0"
23
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: work_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Adriano Bacha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - abacha@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - data/holidays.json
70
+ - lib/holiday.rb
71
+ - lib/work_day.rb
72
+ - lib/work_day/version.rb
73
+ - work_day.gemspec
74
+ homepage:
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.10
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: work days
98
+ test_files: []