work_day 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7b872116ba8b4ee4af1d0ba48143ef40e4e19a9
4
- data.tar.gz: cd4b722a58942bf180e28eda95d16f30d4fa4051
3
+ metadata.gz: 5dbab133cfa019db8bf4da785732cf062c5cd245
4
+ data.tar.gz: d3c89c74daaced2e046c6790d6582c15703064fb
5
5
  SHA512:
6
- metadata.gz: 7c1c33550cf10eb3259cc9e705938c2e45de0301e7b927ced7756dcb211acd3b55449d705e2e8914e9580f06f02b131430679e0c88b9c8f1fd998009da9133ee
7
- data.tar.gz: c01b64d907031857d63c61c64015411805c25296c5450ab061d9a14ced774fc671e84febe31888f367fd4a9b1a273c37e926360aebf1f69da247aef77b41a539
6
+ metadata.gz: 56638a726e8d5193403fdf3cfe5f8ae6e531cd5e710b85bcf3701f1153be0bc5038b38a7f19b58444832e7e4bffe500cdcb22781bdb9328cbae4b56f1477f0e6
7
+ data.tar.gz: 98279d2e4115ab8d3d8d924f9731c18c5d4ad4de35f9fa36c78da52b3cff59a1d7332dec60c23b2f3df0fe426f5684d96e7f5165107ebc0ea3fad8d525712f3c
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2018-03-27
10
+ ### Added
11
+ - Feature for foreign calendars
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # WorkDay
2
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
3
+ Gem para verificação de dias úteis e cálculo entre datas úteis.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,20 +20,103 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
26
23
 
27
- ## Development
24
+ ### WorkDay.work_day?(date)
25
+ Verifica se uma data é um dia útil
26
+
27
+
28
+ ```ruby
29
+ > WorkDay.work_day?("2017-01-01")
30
+ => false
31
+ > WorkDay.work_day?("2017-01-05")
32
+ => true
33
+ ```
34
+
35
+
28
36
 
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.
37
+ ### WorkDay.last_until(date, days = 0)
38
+ Retorna o n-dia útil até certa data.
30
39
 
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
40
 
33
- ## Contributing
41
+ ###### Passando uma data útil, com 0 dias
42
+ ```ruby
43
+ > WorkDay.last_until("2017-01-05")
44
+ => Thu, 05 Jan 2017 # retorna a própria data por ser uma data útil
45
+ ```
34
46
 
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.
47
+ ###### Passando uma data não-útil, com 0 dias
48
+ ```ruby
49
+ > WorkDay.last_until("2017-01-08")
50
+ => Fri, 06 Jan 2017 # retorna o primeiro dia útil anterior a data passada
51
+ ```
36
52
 
53
+ ###### Passando uma data útil, com 2 dias
54
+ ```ruby
55
+ > WorkDay.last_until("2017-01-05", 2)
56
+ => Tue, 03 Jan 2017 # retorna a data 2 dias úteis anteriores a data passada
57
+ ```
58
+
59
+ ###### Passando uma data não-útil, com 2 dias
60
+ ```ruby
61
+ > WorkDay.last_until("2017-01-08", 2)
62
+ => Wed, 04 Jan 2017 # retorna a data 2 dias úteis anteriores a data passada
63
+ ```
64
+
65
+
66
+
67
+ ### WorkDay.next_after(date, days = 1)
68
+ Retorna o n-dia útil após certa data
69
+
70
+
71
+ ###### Passando uma data útil, com 2 dias
72
+ ```ruby
73
+ > WorkDay.next_after("2017-01-05", 2)
74
+ => Mon, 09 Jan 2017
75
+ ```
76
+
77
+ ###### Passando uma data não-útil, com 2 dias
78
+ ```ruby
79
+ > WorkDay.next_after("2017-01-07", 2)
80
+ => Tue, 10 Jan 2017
81
+ ```
82
+
83
+ ###### Passando uma data útil, com 1 dia
84
+ ```ruby
85
+ > WorkDay.next_after("2017-01-05")
86
+ => Fri, 06 Jan 2017
87
+ ```
88
+
89
+ ###### Passando uma data não-útil, com 1 dia
90
+ ```ruby
91
+ > WorkDay.next_after("2017-01-07")
92
+ => Mon, 09 Jan 2017
93
+ ```
94
+
95
+
96
+ ### WorkDay.between(start_date, end_date)
97
+
98
+ Lista todas as datas úteis entre 2 datas (`start_date` e `end_date`)
99
+
100
+
101
+ ```ruby
102
+ > WorkDay.between("2013-01-05", "2013-01-10")
103
+ => [Mon, 07 Jan 2013,
104
+ Tue, 08 Jan 2013,
105
+ Wed, 09 Jan 2013,
106
+ Thu, 10 Jan 2013]
107
+ ```
108
+
109
+ ### Escolhendo calendários
110
+
111
+ Pode ser utilizado mais de um calendário ao mesmo tempo
112
+ Calendários disponíveis london, new_york e brazil
113
+
114
+ ```ruby
115
+ > wd = WorkDay.new(['london', 'new_york'])
116
+ > wd.work_day?("2018-05-28")
117
+ => false
118
+ ```
37
119
 
38
120
  ## License
39
121
 
40
122
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
@@ -0,0 +1,20 @@
1
+ image: ruby:2.2.5
2
+
3
+ pipelines:
4
+ default:
5
+ - step:
6
+ script:
7
+ - git archive --remote=git@bitbucket.org:guideinvestimentos/rails_defaults.git HEAD .rubocop.yml | tar -x
8
+ - bundle install
9
+ - gem install rubocop
10
+ - rspec -fdoc
11
+ - rubocop .
12
+
13
+ branches:
14
+ master:
15
+ - step:
16
+ script:
17
+ - gem build work_day.gemspec
18
+ - curl -u $RUBYGEMS_USERNAME:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
19
+ - chmod 0600 ~/.gem/credentials
20
+ - gem push $(ls *.gem)
File without changes
@@ -0,0 +1 @@
1
+ ["1990-01-01","1990-03-30","1990-04-02","1990-05-07","1990-05-28","1990-08-27","1990-12-25","1990-12-26","1991-01-01","1991-03-30","1991-04-02","1991-05-07","1991-05-28","1991-08-27","1991-12-25","1991-12-26","1992-01-01","1992-03-30","1992-04-02","1992-05-07","1992-05-28","1992-08-27","1992-12-25","1992-12-26","1993-01-01","1993-03-30","1993-04-02","1993-05-07","1993-05-28","1993-08-27","1993-12-25","1993-12-26","1994-01-01","1994-03-30","1994-04-02","1994-05-07","1994-05-28","1994-08-27","1994-12-25","1994-12-26","1995-01-01","1995-03-30","1995-04-02","1995-05-07","1995-05-28","1995-08-27","1995-12-25","1995-12-26","1996-01-01","1996-03-30","1996-04-02","1996-05-07","1996-05-28","1996-08-27","1996-12-25","1996-12-26","1997-01-01","1997-03-30","1997-04-02","1997-05-07","1997-05-28","1997-08-27","1997-12-25","1997-12-26","1998-01-01","1998-03-30","1998-04-02","1998-05-07","1998-05-28","1998-08-27","1998-12-25","1998-12-26","1999-01-01","1999-03-30","1999-04-02","1999-05-07","1999-05-28","1999-08-27","1999-12-25","1999-12-26","2000-01-01","2000-03-30","2000-04-02","2000-05-07","2000-05-28","2000-08-27","2000-12-25","2000-12-26","2001-01-01","2001-03-30","2001-04-02","2001-05-07","2001-05-28","2001-08-27","2001-12-25","2001-12-26","2002-01-01","2002-03-30","2002-04-02","2002-05-07","2002-05-28","2002-08-27","2002-12-25","2002-12-26","2003-01-01","2003-03-30","2003-04-02","2003-05-07","2003-05-28","2003-08-27","2003-12-25","2003-12-26","2004-01-01","2004-03-30","2004-04-02","2004-05-07","2004-05-28","2004-08-27","2004-12-25","2004-12-26","2005-01-01","2005-03-30","2005-04-02","2005-05-07","2005-05-28","2005-08-27","2005-12-25","2005-12-26","2006-01-01","2006-03-30","2006-04-02","2006-05-07","2006-05-28","2006-08-27","2006-12-25","2006-12-26","2007-01-01","2007-03-30","2007-04-02","2007-05-07","2007-05-28","2007-08-27","2007-12-25","2007-12-26","2008-01-01","2008-03-30","2008-04-02","2008-05-07","2008-05-28","2008-08-27","2008-12-25","2008-12-26","2009-01-01","2009-03-30","2009-04-02","2009-05-07","2009-05-28","2009-08-27","2009-12-25","2009-12-26","2010-01-01","2010-03-30","2010-04-02","2010-05-07","2010-05-28","2010-08-27","2010-12-25","2010-12-26","2011-01-01","2011-03-30","2011-04-02","2011-05-07","2011-05-28","2011-08-27","2011-12-25","2011-12-26","2012-01-01","2012-03-30","2012-04-02","2012-05-07","2012-05-28","2012-08-27","2012-12-25","2012-12-26","2013-01-01","2013-03-30","2013-04-02","2013-05-07","2013-05-28","2013-08-27","2013-12-25","2013-12-26","2014-01-01","2014-03-30","2014-04-02","2014-05-07","2014-05-28","2014-08-27","2014-12-25","2014-12-26","2015-01-01","2015-03-30","2015-04-02","2015-05-07","2015-05-28","2015-08-27","2015-12-25","2015-12-26","2016-01-01","2016-03-30","2016-04-02","2016-05-07","2016-05-28","2016-08-27","2016-12-25","2016-12-26","2017-01-01","2017-03-30","2017-04-02","2017-05-07","2017-05-28","2017-08-27","2017-12-25","2017-12-26","2018-01-01","2018-03-30","2018-04-02","2018-05-07","2018-05-28","2018-08-27","2018-12-25","2018-12-26","2019-01-01","2019-03-30","2019-04-02","2019-05-07","2019-05-28","2019-08-27","2019-12-25","2019-12-26","2020-01-01","2020-03-30","2020-04-02","2020-05-07","2020-05-28","2020-08-27","2020-12-25","2020-12-26","2021-01-01","2021-03-30","2021-04-02","2021-05-07","2021-05-28","2021-08-27","2021-12-25","2021-12-26","2022-01-01","2022-03-30","2022-04-02","2022-05-07","2022-05-28","2022-08-27","2022-12-25","2022-12-26","2023-01-01","2023-03-30","2023-04-02","2023-05-07","2023-05-28","2023-08-27","2023-12-25","2023-12-26","2024-01-01","2024-03-30","2024-04-02","2024-05-07","2024-05-28","2024-08-27","2024-12-25","2024-12-26","2025-01-01","2025-03-30","2025-04-02","2025-05-07","2025-05-28","2025-08-27","2025-12-25","2025-12-26","2026-01-01","2026-03-30","2026-04-02","2026-05-07","2026-05-28","2026-08-27","2026-12-25","2026-12-26","2027-01-01","2027-03-30","2027-04-02","2027-05-07","2027-05-28","2027-08-27","2027-12-25","2027-12-26","2028-01-01","2028-03-30","2028-04-02","2028-05-07","2028-05-28","2028-08-27","2028-12-25","2028-12-26","2029-01-01","2029-03-30","2029-04-02","2029-05-07","2029-05-28","2029-08-27","2029-12-25","2029-12-26","2030-01-01","2030-03-30","2030-04-02","2030-05-07","2030-05-28","2030-08-27","2030-12-25","2030-12-26","2031-01-01","2031-03-30","2031-04-02","2031-05-07","2031-05-28","2031-08-27","2031-12-25","2031-12-26","2032-01-01","2032-03-30","2032-04-02","2032-05-07","2032-05-28","2032-08-27","2032-12-25","2032-12-26","2033-01-01","2033-03-30","2033-04-02","2033-05-07","2033-05-28","2033-08-27","2033-12-25","2033-12-26","2034-01-01","2034-03-30","2034-04-02","2034-05-07","2034-05-28","2034-08-27","2034-12-25","2034-12-26","2035-01-01","2035-03-30","2035-04-02","2035-05-07","2035-05-28","2035-08-27","2035-12-25","2035-12-26","2036-01-01","2036-03-30","2036-04-02","2036-05-07","2036-05-28","2036-08-27","2036-12-25","2036-12-26","2037-01-01","2037-03-30","2037-04-02","2037-05-07","2037-05-28","2037-08-27","2037-12-25","2037-12-26","2038-01-01","2038-03-30","2038-04-02","2038-05-07","2038-05-28","2038-08-27","2038-12-25","2038-12-26","2039-01-01","2039-03-30","2039-04-02","2039-05-07","2039-05-28","2039-08-27","2039-12-25","2039-12-26","2040-01-01","2040-03-30","2040-04-02","2040-05-07","2040-05-28","2040-08-27","2040-12-25","2040-12-26","2041-01-01","2041-03-30","2041-04-02","2041-05-07","2041-05-28","2041-08-27","2041-12-25","2041-12-26","2042-01-01","2042-03-30","2042-04-02","2042-05-07","2042-05-28","2042-08-27","2042-12-25","2042-12-26","2043-01-01","2043-03-30","2043-04-02","2043-05-07","2043-05-28","2043-08-27","2043-12-25","2043-12-26","2044-01-01","2044-03-30","2044-04-02","2044-05-07","2044-05-28","2044-08-27","2044-12-25","2044-12-26","2045-01-01","2045-03-30","2045-04-02","2045-05-07","2045-05-28","2045-08-27","2045-12-25","2045-12-26","2046-01-01","2046-03-30","2046-04-02","2046-05-07","2046-05-28","2046-08-27","2046-12-25","2046-12-26","2047-01-01","2047-03-30","2047-04-02","2047-05-07","2047-05-28","2047-08-27","2047-12-25","2047-12-26","2048-01-01","2048-03-30","2048-04-02","2048-05-07","2048-05-28","2048-08-27","2048-12-25","2048-12-26","2049-01-01","2049-03-30","2049-04-02","2049-05-07","2049-05-28","2049-08-27","2049-12-25","2049-12-26","2050-01-01","2050-03-30","2050-04-02","2050-05-07","2050-05-28","2050-08-27","2050-12-25","2050-12-26"]
@@ -0,0 +1 @@
1
+ ["1990-01-01","1990-01-15","1990-02-19","1990-05-28","1990-07-04","1990-09-03","1990-10-08","1990-11-12","1990-11-22","1990-12-25","1991-01-01","1991-01-15","1991-02-19","1991-05-28","1991-07-04","1991-09-03","1991-10-08","1991-11-12","1991-11-22","1991-12-25","1992-01-01","1992-01-15","1992-02-19","1992-05-28","1992-07-04","1992-09-03","1992-10-08","1992-11-12","1992-11-22","1992-12-25","1993-01-01","1993-01-15","1993-02-19","1993-05-28","1993-07-04","1993-09-03","1993-10-08","1993-11-12","1993-11-22","1993-12-25","1994-01-01","1994-01-15","1994-02-19","1994-05-28","1994-07-04","1994-09-03","1994-10-08","1994-11-12","1994-11-22","1994-12-25","1995-01-01","1995-01-15","1995-02-19","1995-05-28","1995-07-04","1995-09-03","1995-10-08","1995-11-12","1995-11-22","1995-12-25","1996-01-01","1996-01-15","1996-02-19","1996-05-28","1996-07-04","1996-09-03","1996-10-08","1996-11-12","1996-11-22","1996-12-25","1997-01-01","1997-01-15","1997-02-19","1997-05-28","1997-07-04","1997-09-03","1997-10-08","1997-11-12","1997-11-22","1997-12-25","1998-01-01","1998-01-15","1998-02-19","1998-05-28","1998-07-04","1998-09-03","1998-10-08","1998-11-12","1998-11-22","1998-12-25","1999-01-01","1999-01-15","1999-02-19","1999-05-28","1999-07-04","1999-09-03","1999-10-08","1999-11-12","1999-11-22","1999-12-25","2000-01-01","2000-01-15","2000-02-19","2000-05-28","2000-07-04","2000-09-03","2000-10-08","2000-11-12","2000-11-22","2000-12-25","2001-01-01","2001-01-15","2001-02-19","2001-05-28","2001-07-04","2001-09-03","2001-10-08","2001-11-12","2001-11-22","2001-12-25","2002-01-01","2002-01-15","2002-02-19","2002-05-28","2002-07-04","2002-09-03","2002-10-08","2002-11-12","2002-11-22","2002-12-25","2003-01-01","2003-01-15","2003-02-19","2003-05-28","2003-07-04","2003-09-03","2003-10-08","2003-11-12","2003-11-22","2003-12-25","2004-01-01","2004-01-15","2004-02-19","2004-05-28","2004-07-04","2004-09-03","2004-10-08","2004-11-12","2004-11-22","2004-12-25","2005-01-01","2005-01-15","2005-02-19","2005-05-28","2005-07-04","2005-09-03","2005-10-08","2005-11-12","2005-11-22","2005-12-25","2006-01-01","2006-01-15","2006-02-19","2006-05-28","2006-07-04","2006-09-03","2006-10-08","2006-11-12","2006-11-22","2006-12-25","2007-01-01","2007-01-15","2007-02-19","2007-05-28","2007-07-04","2007-09-03","2007-10-08","2007-11-12","2007-11-22","2007-12-25","2008-01-01","2008-01-15","2008-02-19","2008-05-28","2008-07-04","2008-09-03","2008-10-08","2008-11-12","2008-11-22","2008-12-25","2009-01-01","2009-01-15","2009-02-19","2009-05-28","2009-07-04","2009-09-03","2009-10-08","2009-11-12","2009-11-22","2009-12-25","2010-01-01","2010-01-15","2010-02-19","2010-05-28","2010-07-04","2010-09-03","2010-10-08","2010-11-12","2010-11-22","2010-12-25","2011-01-01","2011-01-15","2011-02-19","2011-05-28","2011-07-04","2011-09-03","2011-10-08","2011-11-12","2011-11-22","2011-12-25","2012-01-01","2012-01-15","2012-02-19","2012-05-28","2012-07-04","2012-09-03","2012-10-08","2012-11-12","2012-11-22","2012-12-25","2013-01-01","2013-01-15","2013-02-19","2013-05-28","2013-07-04","2013-09-03","2013-10-08","2013-11-12","2013-11-22","2013-12-25","2014-01-01","2014-01-15","2014-02-19","2014-05-28","2014-07-04","2014-09-03","2014-10-08","2014-11-12","2014-11-22","2014-12-25","2015-01-01","2015-01-15","2015-02-19","2015-05-28","2015-07-04","2015-09-03","2015-10-08","2015-11-12","2015-11-22","2015-12-25","2016-01-01","2016-01-15","2016-02-19","2016-05-28","2016-07-04","2016-09-03","2016-10-08","2016-11-12","2016-11-22","2016-12-25","2017-01-01","2017-01-15","2017-02-19","2017-05-28","2017-07-04","2017-09-03","2017-10-08","2017-11-12","2017-11-22","2017-12-25","2018-01-01","2018-01-15","2018-02-19","2018-05-28","2018-07-04","2018-09-03","2018-10-08","2018-11-12","2018-11-22","2018-12-25","2019-01-01","2019-01-15","2019-02-19","2019-05-28","2019-07-04","2019-09-03","2019-10-08","2019-11-12","2019-11-22","2019-12-25","2020-01-01","2020-01-15","2020-02-19","2020-05-28","2020-07-04","2020-09-03","2020-10-08","2020-11-12","2020-11-22","2020-12-25","2021-01-01","2021-01-15","2021-02-19","2021-05-28","2021-07-04","2021-09-03","2021-10-08","2021-11-12","2021-11-22","2021-12-25","2022-01-01","2022-01-15","2022-02-19","2022-05-28","2022-07-04","2022-09-03","2022-10-08","2022-11-12","2022-11-22","2022-12-25","2023-01-01","2023-01-15","2023-02-19","2023-05-28","2023-07-04","2023-09-03","2023-10-08","2023-11-12","2023-11-22","2023-12-25","2024-01-01","2024-01-15","2024-02-19","2024-05-28","2024-07-04","2024-09-03","2024-10-08","2024-11-12","2024-11-22","2024-12-25","2025-01-01","2025-01-15","2025-02-19","2025-05-28","2025-07-04","2025-09-03","2025-10-08","2025-11-12","2025-11-22","2025-12-25","2026-01-01","2026-01-15","2026-02-19","2026-05-28","2026-07-04","2026-09-03","2026-10-08","2026-11-12","2026-11-22","2026-12-25","2027-01-01","2027-01-15","2027-02-19","2027-05-28","2027-07-04","2027-09-03","2027-10-08","2027-11-12","2027-11-22","2027-12-25","2028-01-01","2028-01-15","2028-02-19","2028-05-28","2028-07-04","2028-09-03","2028-10-08","2028-11-12","2028-11-22","2028-12-25","2029-01-01","2029-01-15","2029-02-19","2029-05-28","2029-07-04","2029-09-03","2029-10-08","2029-11-12","2029-11-22","2029-12-25","2030-01-01","2030-01-15","2030-02-19","2030-05-28","2030-07-04","2030-09-03","2030-10-08","2030-11-12","2030-11-22","2030-12-25","2031-01-01","2031-01-15","2031-02-19","2031-05-28","2031-07-04","2031-09-03","2031-10-08","2031-11-12","2031-11-22","2031-12-25","2032-01-01","2032-01-15","2032-02-19","2032-05-28","2032-07-04","2032-09-03","2032-10-08","2032-11-12","2032-11-22","2032-12-25","2033-01-01","2033-01-15","2033-02-19","2033-05-28","2033-07-04","2033-09-03","2033-10-08","2033-11-12","2033-11-22","2033-12-25","2034-01-01","2034-01-15","2034-02-19","2034-05-28","2034-07-04","2034-09-03","2034-10-08","2034-11-12","2034-11-22","2034-12-25","2035-01-01","2035-01-15","2035-02-19","2035-05-28","2035-07-04","2035-09-03","2035-10-08","2035-11-12","2035-11-22","2035-12-25","2036-01-01","2036-01-15","2036-02-19","2036-05-28","2036-07-04","2036-09-03","2036-10-08","2036-11-12","2036-11-22","2036-12-25","2037-01-01","2037-01-15","2037-02-19","2037-05-28","2037-07-04","2037-09-03","2037-10-08","2037-11-12","2037-11-22","2037-12-25","2038-01-01","2038-01-15","2038-02-19","2038-05-28","2038-07-04","2038-09-03","2038-10-08","2038-11-12","2038-11-22","2038-12-25","2039-01-01","2039-01-15","2039-02-19","2039-05-28","2039-07-04","2039-09-03","2039-10-08","2039-11-12","2039-11-22","2039-12-25","2040-01-01","2040-01-15","2040-02-19","2040-05-28","2040-07-04","2040-09-03","2040-10-08","2040-11-12","2040-11-22","2040-12-25","2041-01-01","2041-01-15","2041-02-19","2041-05-28","2041-07-04","2041-09-03","2041-10-08","2041-11-12","2041-11-22","2041-12-25","2042-01-01","2042-01-15","2042-02-19","2042-05-28","2042-07-04","2042-09-03","2042-10-08","2042-11-12","2042-11-22","2042-12-25","2043-01-01","2043-01-15","2043-02-19","2043-05-28","2043-07-04","2043-09-03","2043-10-08","2043-11-12","2043-11-22","2043-12-25","2044-01-01","2044-01-15","2044-02-19","2044-05-28","2044-07-04","2044-09-03","2044-10-08","2044-11-12","2044-11-22","2044-12-25","2045-01-01","2045-01-15","2045-02-19","2045-05-28","2045-07-04","2045-09-03","2045-10-08","2045-11-12","2045-11-22","2045-12-25","2046-01-01","2046-01-15","2046-02-19","2046-05-28","2046-07-04","2046-09-03","2046-10-08","2046-11-12","2046-11-22","2046-12-25","2047-01-01","2047-01-15","2047-02-19","2047-05-28","2047-07-04","2047-09-03","2047-10-08","2047-11-12","2047-11-22","2047-12-25","2048-01-01","2048-01-15","2048-02-19","2048-05-28","2048-07-04","2048-09-03","2048-10-08","2048-11-12","2048-11-22","2048-12-25","2049-01-01","2049-01-15","2049-02-19","2049-05-28","2049-07-04","2049-09-03","2049-10-08","2049-11-12","2049-11-22","2049-12-25","2050-01-01","2050-01-15","2050-02-19","2050-05-28","2050-07-04","2050-09-03","2050-10-08","2050-11-12","2050-11-22","2050-12-25"]
data/lib/holiday.rb CHANGED
@@ -1,34 +1,41 @@
1
- require "json"
2
- require "singleton"
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'singleton'
3
5
 
4
6
  class Holiday
5
- include Singleton
6
- attr_reader :holidays
7
+ attr_reader :holidays, :calendars
7
8
 
8
- def self.load_data
9
- instance.load_data
9
+ def initialize(calendars)
10
+ @calendars = calendars
10
11
  end
11
12
 
12
13
  def load_data
13
14
  @holidays = {}
14
15
 
15
- file = File.expand_path(File.dirname(__FILE__) + "/../data/holidays.json")
16
- raw_data = File.read(file)
17
- parsed = JSON.parse(raw_data)
16
+ calendars.each do |calendar|
17
+ file = File.expand_path(
18
+ File.dirname(__FILE__) + "/../data/#{calendar}_holidays.json"
19
+ )
20
+ raw_data = File.read(file)
21
+ parsed = JSON.parse(raw_data)
22
+ update_holidays(parsed)
23
+ end
24
+ end
25
+
26
+ def in(year)
27
+ load_data if holidays.nil?
28
+ holidays[year]
29
+ end
18
30
 
31
+ private
32
+
33
+ def update_holidays(parsed)
19
34
  parsed.map do |str|
20
- splitted = str.split("-")
35
+ str.split('-')
21
36
  date = Date.parse(str)
22
37
  @holidays[date.year] ||= []
23
38
  @holidays[date.year] << date
24
39
  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
40
  end
34
41
  end
@@ -1,3 +1,5 @@
1
- module WorkDay
2
- VERSION = "0.3.1"
1
+ # frozen_string_literal: true
2
+
3
+ class WorkDay
4
+ VERSION = '1.0.0'
3
5
  end
data/lib/work_day.rb CHANGED
@@ -1,27 +1,32 @@
1
- require "holiday"
2
- require "active_support"
3
- require "active_support/core_ext"
1
+ # frozen_string_literal: true
4
2
 
5
- module WorkDay
6
- @holidays = {}
3
+ require 'holiday'
4
+ require 'active_support'
5
+ require 'active_support/core_ext'
7
6
 
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
7
+ class WorkDay
8
+ attr_reader :calendars
9
+
10
+ def initialize(calendars = ['brazil'])
11
+ @calendars = calendars
12
+ @holidays = {}
12
13
  end
13
14
 
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
15
+ def work_day?(date)
16
+ date = date.try(:to_date)
17
+ return unless date
18
+ ![0, 6].include?(date.wday) && !holidays_in(date.year).include?(date)
22
19
  end
23
20
 
24
- def self.next_after(date, days = 1)
21
+ def last_until(date, days = 0)
22
+ date = date.try(:to_date)
23
+ return unless date
24
+ date -= 1 until work_day?(date)
25
+ days -= 1
26
+ days == -1 ? date : last_until(1.day.ago(date), days)
27
+ end
28
+
29
+ def next_after(date, days = 1)
25
30
  date = date.try(:to_date)
26
31
  day_counter = 0
27
32
  while day_counter < days
@@ -31,12 +36,29 @@ module WorkDay
31
36
  work_day?(date) ? date : next_after(date)
32
37
  end
33
38
 
34
- def self.between(start_date, end_date)
39
+ def between(start_date, end_date)
35
40
  (start_date.to_date..end_date.to_date).select { |date| work_day?(date) }
36
41
  end
37
42
 
43
+ def self.work_day?(date)
44
+ WorkDay.new.work_day?(date)
45
+ end
46
+
47
+ def self.last_until(date, days = 0)
48
+ WorkDay.new.last_until(date, days)
49
+ end
50
+
51
+ def self.next_after(date, days = 1)
52
+ WorkDay.new.next_after(date, days)
53
+ end
54
+
55
+ def self.between(start_date, end_date)
56
+ WorkDay.new.between(start_date, end_date)
57
+ end
58
+
38
59
  private
39
- def self.holidays_in(year)
40
- @holidays[year] ||= Holiday.in(year)
60
+
61
+ def holidays_in(year)
62
+ @holidays[year] ||= Holiday.new(calendars).in(year)
41
63
  end
42
64
  end
data/work_day.gemspec CHANGED
@@ -1,23 +1,24 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'work_day/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "work_day"
8
+ spec.name = 'work_day'
8
9
  spec.version = WorkDay::VERSION
9
- spec.authors = ["Adriano Bacha"]
10
- spec.email = ["abacha@gmail.com"]
10
+ spec.authors = ['Adriano Bacha']
11
+ spec.email = ['abacha@gmail.com']
11
12
 
12
- spec.summary = %q{work days}
13
- spec.license = "MIT"
13
+ spec.summary = 'work days'
14
+ spec.license = 'MIT'
14
15
 
15
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
17
  f.match(%r{^(test|spec|features)/})
17
18
  end
18
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
19
20
 
20
- spec.add_development_dependency "bundler", "~> 1.13"
21
- spec.add_development_dependency "rspec", "~> 3.0"
22
- spec.add_runtime_dependency "activesupport", ">= 4.0"
21
+ spec.add_development_dependency 'bundler', '~> 1.13'
22
+ spec.add_development_dependency 'rspec', '~> 3.0'
23
+ spec.add_runtime_dependency 'activesupport', '>= 4.0'
23
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adriano Bacha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-21 00:00:00.000000000 Z
11
+ date: 2018-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,11 +64,14 @@ files:
64
64
  - ".ruby-gemset"
65
65
  - ".ruby-version"
66
66
  - ".travis.yml"
67
+ - CHANGELOG.md
67
68
  - Gemfile
68
69
  - LICENSE.txt
69
70
  - README.md
70
- - circle.yml
71
- - data/holidays.json
71
+ - bitbucket-pipelines.yml
72
+ - data/brazil_holidays.json
73
+ - data/london_holidays.json
74
+ - data/new_york_holidays.json
72
75
  - lib/holiday.rb
73
76
  - lib/work_day.rb
74
77
  - lib/work_day/version.rb
@@ -93,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
96
  version: '0'
94
97
  requirements: []
95
98
  rubyforge_project:
96
- rubygems_version: 2.4.8
99
+ rubygems_version: 2.6.8
97
100
  signing_key:
98
101
  specification_version: 4
99
102
  summary: work days
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- dependencies:
2
- pre:
3
- - gem install bundler