business-period 0.1.3 → 0.1.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +28 -27
- data/lib/business_period/days.rb +1 -1
- data/lib/business_period/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae8d77f79fbae52d0e98e2eb490f869dc939b6a0
|
|
4
|
+
data.tar.gz: 77584003f1eb7564bb403e0140adb011af1fff79
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f42cb7a31c9c18bb6797609d8c8b3d49c3cbe484e8bf2758ec580812d09f2ce3353ad14e057ab530437fdef9915883f3b5c89f01f8f1448496313f4fc4708c4a
|
|
7
|
+
data.tar.gz: b78380a4f745c7ecf8353d59db0beca3bbf8c3660f569cb2f44a1588a86b6309534bf1edfe9d1171c31490bcb6d5ee79646c7c648581040ed5d8b19002d694f3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -26,13 +26,13 @@ Or install it yourself as:
|
|
|
26
26
|
|
|
27
27
|
There are two ways to initialize:
|
|
28
28
|
|
|
29
|
-
#####
|
|
29
|
+
##### Initialization:
|
|
30
30
|
|
|
31
31
|
```ruby
|
|
32
32
|
# config/initializers/business_period.rb
|
|
33
33
|
|
|
34
|
-
#
|
|
35
|
-
#
|
|
34
|
+
# Set locale to get config file from config/holidays path.
|
|
35
|
+
# Set work_days to define which days of week are work days.
|
|
36
36
|
|
|
37
37
|
locale = 'lt'
|
|
38
38
|
work_days = [1, 2, 3, 4, 5]
|
|
@@ -53,50 +53,51 @@ BusinessPeriod::Config.work_days = -> { work_days }
|
|
|
53
53
|
|
|
54
54
|
## How it works
|
|
55
55
|
|
|
56
|
-
1. Dynamically calculates how many days we have to add to period end (Saturdays/Sundays/Holidays)
|
|
57
|
-
2. Generates new array
|
|
58
|
-
2. Extracts weekends and holidays from newly generated array
|
|
59
|
-
3. Generates result array
|
|
56
|
+
1. Dynamically calculates how many days we have to add to period end (Saturdays/Sundays/Holidays).
|
|
57
|
+
2. Generates new array.
|
|
58
|
+
2. Extracts weekends and holidays from newly generated array.
|
|
59
|
+
3. Generates result array.
|
|
60
60
|
|
|
61
61
|
## Usage
|
|
62
62
|
|
|
63
63
|
```ruby
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
from = 2
|
|
65
|
+
to = 4
|
|
66
66
|
|
|
67
|
-
#
|
|
68
|
-
|
|
67
|
+
# You can pass optional parameters if You want to set primary day as starting point.
|
|
68
|
+
# options = { primary_day: Time.now - (3600 * 24) }
|
|
69
|
+
|
|
70
|
+
# Call BusinessPeriod::Days class to calculate period
|
|
71
|
+
BusinessPeriod::Days.call(from, to, options)
|
|
69
72
|
```
|
|
70
73
|
|
|
71
74
|
## Examples
|
|
72
|
-
Let's say we have no holidays this month and today is Wednesday
|
|
75
|
+
Let's say we have no holidays this month and today is Wednesday.
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
`work_days = [1, 2, 3, 4, 5]` (all days except weekends)
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
`from = 2`
|
|
80
|
+
`to = 4`
|
|
77
81
|
|
|
78
|
-
* Begins to count period from the coming day
|
|
79
|
-
* Tomorrow (Thursday) is the first valid day
|
|
80
|
-
* The second valid day will be Fridary (first business day)
|
|
81
|
-
* Fourth business day will be Tuesday (Saturday and Sunday are not in scope)
|
|
82
|
+
* Begins to count period from the coming day.
|
|
83
|
+
* Tomorrow (Thursday) is the first valid day.
|
|
84
|
+
* The second valid day will be Fridary (first business day).
|
|
85
|
+
* Fourth business day will be Tuesday (Saturday and Sunday are not in scope).
|
|
82
86
|
|
|
83
87
|
```console
|
|
84
88
|
irb(main):001:0> Time.current
|
|
85
89
|
=> Wed, 12 Sep 2018 05:49:10 UTC +00:00
|
|
86
|
-
irb(main):002:0>
|
|
87
|
-
=>
|
|
88
|
-
irb(main):003:0>
|
|
90
|
+
irb(main):002:0> from = 2
|
|
91
|
+
=> 2
|
|
92
|
+
irb(main):003:0> to = 4
|
|
93
|
+
=> 4
|
|
94
|
+
irb(main):004:0> BusinessPeriod::Days.call(from, to)
|
|
89
95
|
=> {:from_date=>Fri, 14 Sep 2018, :to_date=>Tue, 18 Sep 2018]
|
|
90
96
|
```
|
|
91
97
|
|
|
92
|
-
## Todo
|
|
93
|
-
- [ ] improve specs
|
|
94
|
-
- [ ] Add latvian config
|
|
95
|
-
- [ ] Add estonian config
|
|
96
|
-
|
|
97
98
|
## Development
|
|
98
99
|
|
|
99
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
|
100
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
100
101
|
|
|
101
102
|
## License
|
|
102
103
|
|
data/lib/business_period/days.rb
CHANGED