work_day 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +15 -2
- data/lib/work_day/version.rb +1 -1
- data/lib/work_day.rb +21 -16
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad2e90243c135cdf7a6f7435370a29813ff9f49
|
4
|
+
data.tar.gz: b3f3cfb88d70229f837ccffc1d08b21bcd3e7b8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66865b24e8e13099f91d1d3044ceba82bcdc4a7d091bdcecfdf4edb28decb852db802ee05e0347b9be29f76f60867feb7f3f1bca53e8b5a0e88d5f726942c5df
|
7
|
+
data.tar.gz: 721b82d582cfd2f9f71197ba4422658805cd9a3c700a6e2bc8ec0830959bea603fcd3d1bc4e9ad82bbbf2d622a135eeffb0312459fa13a27b65283186d35c5c4
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.1.0] - 2018-08-29
|
10
|
+
### Added
|
11
|
+
- Feature to use diferent calendars in a block
|
12
|
+
- Thread safety
|
13
|
+
|
9
14
|
## [1.0.0] - 2018-03-27
|
10
15
|
### Added
|
11
16
|
- Feature for foreign calendars
|
data/README.md
CHANGED
@@ -111,12 +111,25 @@ Thu, 10 Jan 2013]
|
|
111
111
|
Pode ser utilizado mais de um calendário ao mesmo tempo
|
112
112
|
Calendários disponíveis london, new_york e brazil
|
113
113
|
|
114
|
+
###### Configurando os calendários default
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
> WorkDay.calendars(['london', 'new_york'])
|
118
|
+
> WorkDay.work_day?("2018-05-28")
|
119
|
+
=> false
|
120
|
+
```
|
121
|
+
|
122
|
+
###### Usando calendários apenas em um bloco específico (ex.: por request)
|
123
|
+
|
114
124
|
```ruby
|
115
|
-
>
|
116
|
-
>
|
125
|
+
> WorkDay.calendars(['new_york'])
|
126
|
+
> WorkDay.work_day?("2018-07-04")
|
117
127
|
=> false
|
128
|
+
> WorkDay.use_calendars('london') { WorkDay.work_day?("2018-07-04") }
|
129
|
+
=> true
|
118
130
|
```
|
119
131
|
|
132
|
+
|
120
133
|
## License
|
121
134
|
|
122
135
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/work_day/version.rb
CHANGED
data/lib/work_day.rb
CHANGED
@@ -6,10 +6,13 @@ 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)
|
@@ -37,29 +40,31 @@ class WorkDay
|
|
37
40
|
end
|
38
41
|
|
39
42
|
def between(start_date, end_date)
|
40
|
-
(start_date.to_date..end_date.to_date).select
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.work_day?(date)
|
44
|
-
WorkDay.instance.work_day?(date)
|
43
|
+
(start_date.to_date..end_date.to_date).select(&method(:work_day?))
|
45
44
|
end
|
46
45
|
|
47
|
-
def
|
48
|
-
|
46
|
+
def use_calendars(*new_calendars)
|
47
|
+
old_calendars = calendars
|
48
|
+
self.calendars = new_calendars
|
49
|
+
yield
|
50
|
+
ensure
|
51
|
+
self.calendars = old_calendars
|
49
52
|
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
class << self
|
55
|
+
delegate :work_day?, :last_until, :next_after, :between,
|
56
|
+
:calendars=, :use_calendars, to: :instance
|
54
57
|
|
55
|
-
|
56
|
-
|
58
|
+
# TODO: remove in favor of #calendars=. Requires major version upgrade.
|
59
|
+
def calendars(new_calendars)
|
60
|
+
self.calendars = new_calendars
|
61
|
+
end
|
57
62
|
end
|
58
63
|
|
59
64
|
private
|
60
65
|
|
61
66
|
def holidays_in(year)
|
62
|
-
|
67
|
+
self.calendars ||= ['brazil']
|
63
68
|
@holidays ||= {}
|
64
69
|
@holidays[calendars] ||= {}
|
65
70
|
@holidays[calendars][year] ||= Holiday.new(calendars).in(year)
|
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: 1.0
|
4
|
+
version: 1.1.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: 2018-08-
|
11
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.6.8
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: work days
|