business-days 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/business-days.rb +42 -1
  3. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6841203b5c2dca045e7ccf02ecfebf59cde26b9f
4
- data.tar.gz: 5da6e7a559f109e2bba79077b3fe78c0958131be
3
+ metadata.gz: a49bf433a03ca5d8e9058919391bb4707f6df649
4
+ data.tar.gz: 2971b1a8c7e3b2fa6df25a47a8fd5b42517f1b94
5
5
  SHA512:
6
- metadata.gz: 946f2d3816308da6a8f8695e7d8ca4b4f52ef77eb6e32455fefa05534b93c65beefdcc659921f04cd68fc491a14b8c5b86e16a958f6c7909eceaf68fdeb6dcd2
7
- data.tar.gz: a4a0688c717256ae7caef6dc60b71d740a03c66fc0c84c4a99a9ed3c10161f23352bf522bd18924e4bdbe31ab8c14ee2b9b5d71c05f011757284846368181e11
6
+ metadata.gz: b4701bf981f722e78d28c28e9bd5cc6f91f9e5008203fd521769c8475c5a63f917f30ff43c79f7ecf1b93c7ee000fa9ce67dd7eb9dd69cae2308860bf8f3325a
7
+ data.tar.gz: c56133be9637796533c307d288373a507982b3475e0d9114ebbfe808011ff3b098b9754a4fb0a52576a004f97eed8953ce6b3859ce37b72fa061f11f5ad2d5c4
data/lib/business-days.rb CHANGED
@@ -9,7 +9,7 @@ class BusinessDaysSingleton
9
9
  @holidays = []
10
10
 
11
11
  # Setup holidays in an interval of 3 years
12
- from = Time.current.year
12
+ from = Time.current.year - 1
13
13
  to = Time.current.year + 2
14
14
 
15
15
  # 1. Get all holidays in given years interval from Holidays gem
@@ -30,6 +30,11 @@ class BusinessDaysSingleton
30
30
  end
31
31
  end
32
32
 
33
+ # Compute the date obtained by adding the given amount of business days to the given time.
34
+ #
35
+ # @param days [Integer] how many business days to add to given time.
36
+ # @param time [Time] the start time from which the business days will be added.
37
+ # @return [Date] the computed business day
33
38
  def business_days_from_utc_time(days, time)
34
39
  # We count days based on Brasilia timezone
35
40
  date = time.in_time_zone('Brasilia').to_date
@@ -46,6 +51,10 @@ class BusinessDaysSingleton
46
51
  date
47
52
  end
48
53
 
54
+ # Add the given date as a non-business day (for all commands after this).
55
+ #
56
+ # @param date [Date] the non-business date to be add.
57
+ # @return [Boolean] true if the given date is a business day, false otherwise.
49
58
  def business_day?(date)
50
59
  raise ArgumentError.new('Not a date') unless date.kind_of?(Date)
51
60
 
@@ -53,12 +62,44 @@ class BusinessDaysSingleton
53
62
  !(weekend || @holidays.include?(date))
54
63
  end
55
64
 
65
+ # Consider the given date as a non-business day for all commands after this.
66
+ #
67
+ # @param date [Date] the non-business date to be add.
56
68
  def add_holiday(date)
57
69
  raise ArgumentError.new('Not a date') unless date.kind_of?(Date)
58
70
 
59
71
  @holidays.push(date)
60
72
  end
61
73
 
74
+ # Returns the first business day after the given date.
75
+ #
76
+ # @param date [Date] the reference date.
77
+ # @return [Date] the first business day after the reference date.
78
+ def next(date)
79
+ raise ArgumentError.new('Not a date') unless date.kind_of?(Date)
80
+
81
+ date = date + 1.days
82
+ while !business_day?(date)
83
+ date = date + 1.days
84
+ end
85
+
86
+ date
87
+ end
88
+
89
+ # Returns the first business day before the given date.
90
+ #
91
+ # @param date [Date] the reference date.
92
+ # @return [Date] the first business day before the reference date.
93
+ def previous(date)
94
+ raise ArgumentError.new('Not a date') unless date.kind_of?(Date)
95
+
96
+ date = date - 1.days
97
+ while !business_day?(date)
98
+ date = date - 1.days
99
+ end
100
+
101
+ date
102
+ end
62
103
  private
63
104
 
64
105
  def latest_non_bank_businness_day(year)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business-days
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allan Costa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-29 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -77,7 +77,10 @@ files:
77
77
  homepage: http://rubygems.org/gems/business-days
78
78
  licenses:
79
79
  - MIT
80
- metadata: {}
80
+ metadata:
81
+ changelog_uri: https://github.com/cloudwalkio/business-days/blob/master/CHANGELOG.md
82
+ documentation_uri: http://www.rubydoc.info/github/cloudwalkio/business-days
83
+ source_code_uri: https://github.com/cloudwalkio/business-days
81
84
  post_install_message:
82
85
  rdoc_options: []
83
86
  require_paths: