gb_work_day 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,7 @@ class Date
15
15
  if GBWorkDay::Duration === other
16
16
  plus_with_work_duration(- other)
17
17
  elsif GBWorkDay::Date === other
18
- other - self
18
+ - (other - self)
19
19
  else
20
20
  minus_without_work_duration(other)
21
21
  end
@@ -15,7 +15,7 @@ class Time
15
15
  if GBWorkDay::Duration === other
16
16
  plus_with_work_duration(-other)
17
17
  elsif GBWorkDay::Time === other
18
- other - self
18
+ - (other - self)
19
19
  else
20
20
  minus_without_work_duration(other)
21
21
  end
@@ -5,7 +5,7 @@ module GBWorkDay
5
5
 
6
6
  def -(other)
7
7
  if other.is_a?(::Date) || other.is_a?(::Time)
8
- Interval.new(self, other, week: self.work_week).work_days
8
+ Interval.new(other, self, week: self.work_week).work_days
9
9
  else
10
10
  super
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module GBWorkDay
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -20,6 +20,7 @@ describe GBWorkDay::Date do
20
20
  wednesday = monday + 2.days
21
21
  expect(GBWorkDay::Date.from_date(wednesday) - monday).to be_kind_of GBWorkDay::Duration
22
22
  expect(GBWorkDay::Date.from_date(wednesday) - GBWorkDay::Date.from_date(monday)).to be_kind_of GBWorkDay::Duration
23
+ expect((GBWorkDay::Date.from_date(wednesday) - GBWorkDay::Date.from_date(monday)).work_days).to eq 2
23
24
  expect(GBWorkDay::Date.from_date(monday) - 1).to be_kind_of Date
24
25
  expect((wednesday - GBWorkDay::Date.from_date(monday))).to be_kind_of GBWorkDay::Duration
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gb_work_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Kawecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,8 +97,6 @@ files:
97
97
  - ".idea/runConfigurations/specs.xml"
98
98
  - ".idea/workspace.xml"
99
99
  - Gemfile
100
- - LICENSE.txt
101
- - README.md
102
100
  - Rakefile
103
101
  - gb_work_day.gemspec
104
102
  - lib/gb_work_day.rb
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2016 Kacper Kawecki
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,119 +0,0 @@
1
- # GBWorkDay
2
-
3
- Library to make calculation on work days.
4
- Unlike others libraries like [`business_time`](https://github.com/bokmann/business_time),
5
- [`working_hours`](https://github.com/Intrepidd/working_hours), [`biz`](https://github.com/zendesk/biz)
6
- it operates on whole days, not hours.
7
-
8
- ## Installation
9
-
10
- Add this line to your application's Gemfile:
11
-
12
- ```ruby
13
- gem 'gb_work_day'
14
- ```
15
-
16
- And then execute:
17
-
18
- $ bundle
19
-
20
- Or install it yourself as:
21
-
22
- $ gem install gb_work_day
23
-
24
- ## Usage
25
-
26
- ### Work week
27
-
28
- Set default work week for current thread
29
-
30
- ```ruby
31
- beginning_of_week = 1 #Monday
32
- work_days = 5 #wrokd days are Monday-Friday
33
- GBWorkDay::WorkWeek.current = GBWorkWeek.new(work_days, beginning_of_week)
34
- ```
35
-
36
- or if you want to setup per instance
37
-
38
- ```ruby
39
- beginning_of_week = 1 #Monday
40
- work_days = 5 #wrokd days are Monday-Friday
41
- week = GBWorkWeek.new(work_days, beginning_of_week)
42
- my_date = Date.today.to_work_date(week)
43
- ```
44
-
45
- or
46
-
47
- ```ruby
48
- beginning_of_week = 1 #Monday
49
- work_days = 5 #wrokd days are Monday-Friday
50
- week = GBWorkWeek.new(work_days, beginning_of_week)
51
- my_date = my_date
52
- #some code here
53
- my_date.week = week
54
- ```
55
-
56
- ### Date and Time operation
57
-
58
- Check if today is a work day
59
-
60
- ```ruby
61
- Date.today.work?
62
- ```
63
-
64
- or
65
-
66
- ```ruby
67
- Time.now.work?
68
- ```
69
-
70
- Check if today is holiday
71
-
72
- ```ruby
73
- Date.today.free?
74
- ```
75
-
76
- or
77
-
78
- ```ruby
79
- Time.now.free?
80
- ```
81
-
82
- Get next working day
83
-
84
- ```ruby
85
- Date.today.next_work_day
86
- ```
87
-
88
- or
89
-
90
- ```ruby
91
- Time.now.next_work_day
92
- ```
93
-
94
-
95
- You can also make more complicated calculations
96
-
97
- ```ruby
98
- delivery_date = Date.today + 10.work_days
99
- ```
100
-
101
- or
102
-
103
- ```ruby
104
- amount_of_work = (start_date.to_work_date - end_date).work_days
105
- ```
106
-
107
- ## Contributing
108
-
109
- 1. Fork it ( https://github.com/GenieBelt/gb-works-day/fork )
110
- 2. Create your feature branch (`git checkout -b my-new-feature`)
111
- 3. Commit your changes (`git commit -am 'Add some feature'`)
112
- 4. Push to the branch (`git push origin my-new-feature`)
113
- 5. Create a new Pull Request
114
-
115
- ## Alternatives
116
-
117
- * [`business_time`](https://github.com/bokmann/business_time)
118
- * [`working_hours`](https://github.com/Intrepidd/working_hours)
119
- * [`biz`](https://github.com/zendesk/biz)