work_day 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +18 -1
- data/README.md +21 -4
- data/bitbucket-pipelines.yml +3 -2
- data/data/calendars.json +20 -0
- data/data/sinacor_holidays.json +1 -0
- data/lib/holiday.rb +44 -21
- data/lib/work_day.rb +23 -16
- data/lib/work_day/version.rb +1 -1
- data/work_day.gemspec +3 -2
- metadata +8 -24
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0a81fa0ae71aa762151e9db42a0b906570f8c5c7ac1f13b3249b93beeb4f1543
|
4
|
+
data.tar.gz: b98c1bd13614ae192c4b9ed408e8a43823cba82d5d677815856db3c283b170bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f141ae6807c1fedbb7f64470209c3daa4a1a1df8266c76a12a59cf75544f7e3f1cf2dd3b5c9210ed10434eeac01a3b2b1dda60acf8b1750fe1a05455274e8d
|
7
|
+
data.tar.gz: 3f7f8b1550afe7229657185295652e303e9b8e26ed704a5c21ad0a2c35b2bb4b636c06bf566e2b2a94dc066e5813216fa5cf65c97c379be1f0b8f518223f8fde
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,24 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## [
|
7
|
+
## [2.0.0] - 2021-01-20
|
8
|
+
### Changed
|
9
|
+
- Dropping support for ruby < 2.4. Preferred version is > 2.5
|
10
|
+
- Updated sinacor calendar, with holidays going as far as 2022
|
11
|
+
- Updated gems dependencies
|
12
|
+
|
13
|
+
## [1.3.0] - 2019-02-05
|
14
|
+
### Added
|
15
|
+
- Added new sinacor calendar, with São Paulo's municipal holidays and Brazil's national holidays.
|
16
|
+
|
17
|
+
## [1.2.0] - 2018-09-10
|
18
|
+
### Added
|
19
|
+
- Feature to use the same calendar with different names
|
20
|
+
|
21
|
+
## [1.1.0] - 2018-08-29
|
22
|
+
### Added
|
23
|
+
- Feature to use diferent calendars in a block
|
24
|
+
- Thread safety
|
8
25
|
|
9
26
|
## [1.0.0] - 2018-03-27
|
10
27
|
### Added
|
data/README.md
CHANGED
@@ -108,15 +108,32 @@ Thu, 10 Jan 2013]
|
|
108
108
|
|
109
109
|
### Escolhendo calendários
|
110
110
|
|
111
|
-
Pode ser utilizado mais de um calendário ao mesmo tempo
|
112
|
-
|
111
|
+
Pode ser utilizado mais de um calendário ao mesmo tempo, através de qualquer um dos nomes disponíveis:
|
112
|
+
|
113
|
+
- `london`: `london`, `londres`
|
114
|
+
- `new_york`: `new_york`, `nova_iorque`
|
115
|
+
- `brazil`: `brazil`, `brasil`, `anbima`
|
116
|
+
- `sinacor`: `sinacor`, `b3`, `sao_paulo`
|
117
|
+
|
118
|
+
###### Configurando os calendários default
|
113
119
|
|
114
120
|
```ruby
|
115
|
-
>
|
116
|
-
>
|
121
|
+
> WorkDay.calendars(['london', 'new_york'])
|
122
|
+
> WorkDay.work_day?("2018-05-28")
|
117
123
|
=> false
|
118
124
|
```
|
119
125
|
|
126
|
+
###### Usando calendários apenas em um bloco específico (ex.: por request)
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
> WorkDay.calendars(['new_york'])
|
130
|
+
> WorkDay.work_day?("2018-07-04")
|
131
|
+
=> false
|
132
|
+
> WorkDay.use_calendars('london') { WorkDay.work_day?("2018-07-04") }
|
133
|
+
=> true
|
134
|
+
```
|
135
|
+
|
136
|
+
|
120
137
|
## License
|
121
138
|
|
122
139
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/bitbucket-pipelines.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
image: ruby:2.
|
1
|
+
image: ruby:2.4
|
2
2
|
|
3
3
|
pipelines:
|
4
4
|
default:
|
5
5
|
- step:
|
6
6
|
script:
|
7
|
-
-
|
7
|
+
- wget -O .rubocop.yml $RUBOCOP_CONFIG_URL
|
8
8
|
- bundle install
|
9
9
|
- gem install rubocop
|
10
10
|
- rspec -fdoc
|
@@ -15,6 +15,7 @@ pipelines:
|
|
15
15
|
- step:
|
16
16
|
script:
|
17
17
|
- gem build work_day.gemspec
|
18
|
+
- mkdir -p ~/.gem && > ~/.gem/credentials
|
18
19
|
- curl -u $RUBYGEMS_USERNAME:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
|
19
20
|
- chmod 0600 ~/.gem/credentials
|
20
21
|
- gem push $(ls *.gem)
|
data/data/calendars.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"brazil_holidays.json": [
|
3
|
+
"brasil",
|
4
|
+
"brazil",
|
5
|
+
"anbima"
|
6
|
+
],
|
7
|
+
"london_holidays.json": [
|
8
|
+
"london",
|
9
|
+
"londres"
|
10
|
+
],
|
11
|
+
"new_york_holidays.json": [
|
12
|
+
"new_york",
|
13
|
+
"nova_iorque"
|
14
|
+
],
|
15
|
+
"sinacor_holidays.json": [
|
16
|
+
"sinacor",
|
17
|
+
"b3",
|
18
|
+
"sao_paulo"
|
19
|
+
]
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
["1996-11-15","1996-12-24","1996-12-25","1996-12-31","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-12-24","1997-12-25","1997-12-31","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-12","1998-11-02","1998-12-24","1998-12-25","1998-12-31","1999-01-01","1999-02-15","1999-02-16","1999-04-01","1999-04-02","1999-04-21","1999-06-03","1999-09-07","1999-10-12","1999-11-02","1999-11-15","1999-12-24","1999-12-31","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","2000-12-29","2001-01-01","2001-01-25","2001-02-26","2001-02-27","2001-04-13","2001-05-01","2001-06-14","2001-07-09","2001-09-07","2001-10-12","2001-11-02","2001-11-15","2001-12-24","2001-12-25","2001-12-31","2002-01-01","2002-01-25","2002-02-11","2002-02-12","2002-03-29","2002-05-01","2002-05-30","2002-07-09","2002-11-15","2002-12-24","2002-12-25","2002-12-31","2003-01-01","2003-03-03","2003-03-04","2003-04-18","2003-04-21","2003-05-01","2003-06-19","2003-07-09","2003-12-24","2003-12-25","2003-12-31","2004-01-01","2004-02-23","2004-02-24","2004-04-09","2004-04-21","2004-06-10","2004-07-09","2004-09-07","2004-10-12","2004-11-02","2004-11-15","2004-12-24","2004-12-31","2005-01-25","2005-02-07","2005-02-08","2005-03-25","2005-04-21","2005-05-26","2005-09-07","2005-10-12","2005-11-02","2005-11-15","2005-12-30","2006-01-25","2006-01-28","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-11-20","2006-12-25","2006-12-29","2007-01-01","2007-01-25","2007-02-19","2007-02-20","2007-04-06","2007-05-01","2007-06-07","2007-07-09","2007-09-07","2007-10-12","2007-11-02","2007-11-15","2007-11-20","2007-12-24","2007-12-25","2007-12-31","2008-01-01","2008-01-25","2008-02-04","2008-02-05","2008-03-21","2008-04-21","2008-05-01","2008-05-22","2008-07-09","2008-11-20","2008-12-24","2008-12-25","2008-12-31","2009-01-01","2009-02-23","2009-02-24","2009-04-10","2009-04-21","2009-05-01","2009-06-11","2009-07-09","2009-09-07","2009-10-12","2009-11-02","2009-11-20","2009-12-24","2009-12-25","2009-12-31","2010-01-01","2010-01-25","2010-02-15","2010-02-16","2010-04-02","2010-04-21","2010-06-03","2010-07-09","2010-09-07","2010-10-12","2010-11-02","2010-11-15","2010-12-24","2010-12-31","2011-01-25","2011-03-07","2011-03-08","2011-04-21","2011-04-22","2011-06-23","2011-09-07","2011-10-12","2011-11-02","2011-11-15","2011-12-30","2012-01-25","2012-02-20","2012-02-21","2012-04-06","2012-05-01","2012-06-07","2012-07-09","2012-09-07","2012-10-12","2012-11-02","2012-11-15","2012-11-20","2012-12-24","2012-12-25","2012-12-31","2013-01-01","2013-01-25","2013-02-11","2013-02-12","2013-03-29","2013-05-01","2013-05-30","2013-07-09","2013-11-15","2013-11-20","2013-12-24","2013-12-25","2013-12-31","2014-01-01","2014-03-03","2014-03-04","2014-04-18","2014-04-21","2014-05-01","2014-06-12","2014-06-19","2014-07-09","2014-11-20","2014-12-24","2014-12-25","2014-12-31","2015-01-01","2015-02-16","2015-02-17","2015-04-03","2015-04-21","2015-05-01","2015-06-04","2015-07-09","2015-09-07","2015-10-12","2015-11-02","2015-11-20","2015-12-24","2015-12-25","2015-12-31","2016-01-01","2016-01-25","2016-02-08","2016-02-09","2016-03-25","2016-04-21","2016-05-26","2016-09-07","2016-10-12","2016-11-02","2016-11-15","2016-12-30","2017-01-25","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-11-20","2017-12-25","2017-12-29","2018-01-01","2018-01-25","2018-02-12","2018-02-13","2018-03-30","2018-05-01","2018-05-31","2018-07-09","2018-09-07","2018-10-12","2018-11-02","2018-11-15","2018-11-20","2018-12-24","2018-12-25","2018-12-31","2019-01-01","2019-01-25","2019-03-04","2019-03-05","2019-04-19","2019-05-01","2019-06-20","2019-07-09","2019-11-15","2019-11-20","2019-12-24","2019-12-25","2019-12-31","2020-01-01","2020-02-24","2020-02-25","2020-04-10","2020-04-21","2020-05-01","2020-06-11","2020-07-09","2020-09-07","2020-10-12","2020-11-02","2020-11-20","2020-12-24","2020-12-25","2020-12-31","2021-01-01","2021-01-25","2021-02-15","2021-02-16","2021-04-02","2021-04-21","2021-06-03","2021-07-09","2021-09-07","2021-10-12","2021-11-02","2021-11-15","2021-12-24","2021-12-31","2022-02-28","2022-03-01","2022-04-15","2022-04-21","2022-06-16","2022-09-07","2022-10-12","2022-11-02","2022-11-15","2022-12-30"]
|
data/lib/holiday.rb
CHANGED
@@ -4,38 +4,61 @@ require 'json'
|
|
4
4
|
require 'singleton'
|
5
5
|
|
6
6
|
class Holiday
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :calendars
|
8
|
+
|
9
|
+
CALENDARS_FILENAME = File.expand_path(
|
10
|
+
"#{File.dirname(__FILE__)}/../data/calendars.json"
|
11
|
+
)
|
8
12
|
|
9
13
|
def initialize(calendars)
|
10
14
|
@calendars = calendars
|
11
15
|
end
|
12
16
|
|
17
|
+
def in(year)
|
18
|
+
holidays[year]
|
19
|
+
end
|
20
|
+
|
13
21
|
def load_data
|
14
|
-
|
22
|
+
# TODO: remove this in a major version
|
23
|
+
holidays
|
24
|
+
calendars
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
15
28
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
)
|
20
|
-
raw_data = File.read(file)
|
21
|
-
parsed = JSON.parse(raw_data)
|
22
|
-
update_holidays(parsed)
|
23
|
-
end
|
29
|
+
def holidays
|
30
|
+
@holidays ||= calendars.flat_map(&method(:to_holidays)).uniq.
|
31
|
+
reduce({}, &method(:by_year))
|
24
32
|
end
|
25
33
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
34
|
+
def by_year(holidays_by_year, date)
|
35
|
+
holidays_by_year ||= {}
|
36
|
+
holidays_by_year[date.year] ||= []
|
37
|
+
holidays_by_year[date.year] << date
|
38
|
+
holidays_by_year
|
29
39
|
end
|
30
40
|
|
31
|
-
|
41
|
+
def to_holidays(calendar)
|
42
|
+
holiday_file(calendar).map(&:to_date)
|
43
|
+
end
|
44
|
+
|
45
|
+
def holiday_file(calendar)
|
46
|
+
filename = holiday_filename(calendar)
|
47
|
+
|
48
|
+
return if filename.nil?
|
49
|
+
|
50
|
+
path = File.dirname(__FILE__) + "/../data/#{filename}"
|
51
|
+
JSON.parse(File.read(File.expand_path(path)))
|
52
|
+
end
|
53
|
+
|
54
|
+
def holiday_filename(calendar)
|
55
|
+
holiday_files.select do |_filename, calendar_names|
|
56
|
+
calendar_names.include?(calendar)
|
57
|
+
end.keys.first
|
58
|
+
end
|
32
59
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
date = Date.parse(str)
|
37
|
-
@holidays[date.year] ||= []
|
38
|
-
@holidays[date.year] << date
|
39
|
-
end
|
60
|
+
def holiday_files
|
61
|
+
@holiday_files ||= JSON.parse(File.read(CALENDARS_FILENAME))
|
62
|
+
@holiday_files
|
40
63
|
end
|
41
64
|
end
|
data/lib/work_day.rb
CHANGED
@@ -6,21 +6,26 @@ require 'active_support/core_ext'
|
|
6
6
|
|
7
7
|
class WorkDay
|
8
8
|
include Singleton
|
9
|
-
attr_accessor :calendars
|
10
9
|
|
11
|
-
def
|
12
|
-
|
10
|
+
def calendars
|
11
|
+
Thread.current[:work_day_calendars]
|
12
|
+
end
|
13
|
+
|
14
|
+
def calendars=(new_calendars)
|
15
|
+
Thread.current[:work_day_calendars] = new_calendars
|
13
16
|
end
|
14
17
|
|
15
18
|
def work_day?(date)
|
16
19
|
date = date.try(:to_date)
|
17
20
|
return unless date
|
21
|
+
|
18
22
|
![0, 6].include?(date.wday) && !holidays_in(date.year).include?(date)
|
19
23
|
end
|
20
24
|
|
21
25
|
def last_until(date, days = 0)
|
22
26
|
date = date.try(:to_date)
|
23
27
|
return unless date
|
28
|
+
|
24
29
|
date -= 1 until work_day?(date)
|
25
30
|
days -= 1
|
26
31
|
days == -1 ? date : last_until(1.day.ago(date), days)
|
@@ -37,29 +42,31 @@ class WorkDay
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def between(start_date, end_date)
|
40
|
-
(start_date.to_date..end_date.to_date).select
|
45
|
+
(start_date.to_date..end_date.to_date).select(&method(:work_day?))
|
41
46
|
end
|
42
47
|
|
43
|
-
def
|
44
|
-
|
48
|
+
def use_calendars(*new_calendars)
|
49
|
+
old_calendars = calendars
|
50
|
+
self.calendars = new_calendars
|
51
|
+
yield
|
52
|
+
ensure
|
53
|
+
self.calendars = old_calendars
|
45
54
|
end
|
46
55
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
def self.next_after(date, days = 1)
|
52
|
-
WorkDay.instance.next_after(date, days)
|
53
|
-
end
|
56
|
+
class << self
|
57
|
+
delegate :work_day?, :last_until, :next_after, :between,
|
58
|
+
:calendars=, :use_calendars, to: :instance
|
54
59
|
|
55
|
-
|
56
|
-
|
60
|
+
# TODO: remove in favor of #calendars=. Requires major version upgrade.
|
61
|
+
def calendars(new_calendars)
|
62
|
+
self.calendars = new_calendars
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
private
|
60
67
|
|
61
68
|
def holidays_in(year)
|
62
|
-
|
69
|
+
self.calendars ||= ['brazil']
|
63
70
|
@holidays ||= {}
|
64
71
|
@holidays[calendars] ||= {}
|
65
72
|
@holidays[calendars][year] ||= Holiday.new(calendars).in(year)
|
data/lib/work_day/version.rb
CHANGED
data/work_day.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
end
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
|
21
|
+
spec.required_ruby_version = '>= 2.4.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'rspec', '> 3.0'
|
23
24
|
spec.add_runtime_dependency 'activesupport', '>= 4.0'
|
24
25
|
end
|
metadata
CHANGED
@@ -1,41 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: work_day
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.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:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
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
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rspec
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - ">"
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '3.0'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - ">"
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '3.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
@@ -61,17 +47,16 @@ extra_rdoc_files: []
|
|
61
47
|
files:
|
62
48
|
- ".gitignore"
|
63
49
|
- ".rspec"
|
64
|
-
- ".ruby-gemset"
|
65
|
-
- ".ruby-version"
|
66
|
-
- ".travis.yml"
|
67
50
|
- CHANGELOG.md
|
68
51
|
- Gemfile
|
69
52
|
- LICENSE.txt
|
70
53
|
- README.md
|
71
54
|
- bitbucket-pipelines.yml
|
72
55
|
- data/brazil_holidays.json
|
56
|
+
- data/calendars.json
|
73
57
|
- data/london_holidays.json
|
74
58
|
- data/new_york_holidays.json
|
59
|
+
- data/sinacor_holidays.json
|
75
60
|
- lib/holiday.rb
|
76
61
|
- lib/work_day.rb
|
77
62
|
- lib/work_day/version.rb
|
@@ -88,15 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
73
|
requirements:
|
89
74
|
- - ">="
|
90
75
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
76
|
+
version: 2.4.0
|
92
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
78
|
requirements:
|
94
79
|
- - ">="
|
95
80
|
- !ruby/object:Gem::Version
|
96
81
|
version: '0'
|
97
82
|
requirements: []
|
98
|
-
|
99
|
-
rubygems_version: 2.4.8
|
83
|
+
rubygems_version: 3.0.3
|
100
84
|
signing_key:
|
101
85
|
specification_version: 4
|
102
86
|
summary: work days
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
bigbang_services
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.2.5
|