business-days 0.1.0 → 0.1.1

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 +13 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfbdb115a49dd6890f10db52c93f249963b20ccc
4
- data.tar.gz: 2a62fd6c2adba50683dfaa484c47ba4c581bb453
3
+ metadata.gz: d3bbc892749b3892c56eff2cb8f86a7f7f1bd39e
4
+ data.tar.gz: ca2333f85d9465b9bb70d429784611e46fd0a1a5
5
5
  SHA512:
6
- metadata.gz: 8c161760f5f74a8d6261b8700051401f5b9352ce0c3b3735ad65c28b9fd56dddba90df848280653fe98f6778ce3992dcc225848995e2ec0005f6952210283dac
7
- data.tar.gz: b6c3dd701d722704e68228280f6327a44c2069f565271a0e852df9f16436259a807f261aa51aeb97d80293ddaf04fd3b0d98932d91a9d1ac80b680a3183aa455
6
+ metadata.gz: 39675014fef8f85089cfad6a484c2890e2bdd757998b9bd1cdb36b057fc46b57d17ce6a57331d8552f5beb531fcf95238fa6622b3261f9f2fb773f4a85fc3077
7
+ data.tar.gz: 3f1df86059f02b4226e9d192dc6ab2f25e7a79704de010dbe0279dd972c44d8a86843af13288bffd304d289eedadbaa4daae8e3bc5da45e41f82781d2115d2dc
data/lib/business-days.rb CHANGED
@@ -32,11 +32,20 @@ class BusinessDaysSingleton
32
32
  # Compute the date obtained by adding the given amount of business days to the given time.
33
33
  #
34
34
  # @param days [Integer] how many business days to add to given time.
35
- # @param time [Time] the start time from which the business days will be added.
35
+ # @param time [Time] the start time in UTC from which the business days will be added.
36
+ # @param reference [Time] the reference time in UTC from which we will compute daylight saving.
36
37
  # @return [Date] the computed business day
37
- def business_days_from_utc_time(days, time)
38
- # We count days based on Brasilia timezone
39
- date = time.in_time_zone('Brasilia').to_date
38
+ def business_days_from_utc_time(days, time, reference=nil)
39
+ # Set reference to given time if no reference is passed
40
+ if reference.nil?
41
+ reference = time
42
+ end
43
+
44
+ # Get offset from reference data (based on Brasilia timezone)
45
+ offset = reference.in_time_zone('Brasilia').formatted_offset()
46
+
47
+ # Get date from time in reference offset
48
+ date = (time + offset.to_i.hours).to_date
40
49
 
41
50
  # Add days until we reach the specified business days
42
51
  count = 0
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allan Costa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport