business_days 0.0.1 → 0.0.2

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.
@@ -1,6 +1,6 @@
1
1
  = business_days
2
2
 
3
- Business Days is a sort-of extension to ActiveSupport to allow adding business days to time objects.
3
+ Business Days is a sort-of extension to ActiveSupport to allow adding business days to time objects.
4
4
 
5
5
  == Installation
6
6
 
@@ -29,3 +29,10 @@ Or add it to your Gemfile.
29
29
  (Time.parse("Friday") - 1.business_day).strftime("%A")
30
30
  # => "Thursday"
31
31
 
32
+ == Current Limitations
33
+
34
+ * Holidays are completely ignored.
35
+
36
+ * Time.now + 123512.business_days is done iteratively, even though it would be fairly straightforward to add (5/7 * n) + or - some small number based on where in the week you started.
37
+
38
+ * saturday or sunday + 0.business_days is Monday. There are strong arguments both ways for making this result either monday or saturday. I think Monday is the more helpful. Write me hatemail if you disagree.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'business_days'
3
- gem.version = "0.0.1"
3
+ gem.version = "0.0.2"
4
4
 
5
5
  gem.author, gem.email = 'Burke Libbey', "burke@burkelibbey.org"
6
6
  gem.homepage = "http://github.com/burke/business_days"
@@ -1,5 +1,6 @@
1
1
  require 'active_support/all'
2
2
  require File.join(File.dirname(__FILE__),'business_days','time')
3
+ require File.join(File.dirname(__FILE__),'business_days','date')
3
4
 
4
5
  module BusinessDays
5
6
 
@@ -0,0 +1,42 @@
1
+ module BusinessDays
2
+ module Date
3
+ module Calculations
4
+ def self.included(base) #:nodoc:
5
+
6
+ base.class_eval do
7
+ alias_method :plus_without_business_days, :+
8
+ alias_method :+, :plus_with_business_days
9
+
10
+ alias_method :minus_without_business_days, :-
11
+ alias_method :-, :minus_with_business_days
12
+ end
13
+ end
14
+
15
+ def is_business_day?
16
+ # TODO: Holidays.
17
+ ! [0,6].include?(self.wday)
18
+ end
19
+
20
+ def plus_with_business_days(other)
21
+ if BusinessDays::BusinessDayDuration === other
22
+ other.calculate_duration(self, :+)
23
+ else
24
+ plus_without_business_days(other)
25
+ end
26
+ end
27
+
28
+ def minus_with_business_days(other)
29
+ if BusinessDays::BusinessDayDuration === other
30
+ other.calculate_duration(self, :-)
31
+ else
32
+ minus_without_business_days(other)
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+ class Date
41
+ include BusinessDays::Date::Calculations
42
+ end
@@ -3,30 +3,61 @@ require File.join(File.dirname(__FILE__),'..','lib','business_days')
3
3
 
4
4
  describe BusinessDays do
5
5
 
6
- before do
7
- @friday = Time.parse("Friday, September 10th, 2010")
8
- @thursday = @friday - 1.day
9
- @saturday = @friday + 1.day
10
- @monday = @friday + 3.days
11
- @tuesday = @friday + 4.days
12
- end
13
-
14
- it "should add properly" do
15
- (@friday + 1.business_day).should == @monday
16
- (@friday + 2.business_days).should == @tuesday
17
- (@saturday + 1.business_days).should == @tuesday
18
- (@saturday + 0.business_days).should == @monday
19
- end
20
-
21
- it "should subtract properly" do
22
- (@saturday - 0.business_days).should == @friday
23
- (@saturday - 1.business_day).should == @thursday
24
- (@monday - 1.business_days).should == @friday
25
- (@monday - 0.business_days).should == @monday
6
+ describe "with Time" do
7
+ before do
8
+ @friday = Time.parse("Friday, September 10th, 2010")
9
+ @thursday = @friday - 1.day
10
+ @saturday = @friday + 1.day
11
+ @monday = @friday + 3.days
12
+ @tuesday = @friday + 4.days
13
+ end
14
+
15
+ it "should add properly" do
16
+ (@friday + 1.business_day).should == @monday
17
+ (@friday + 2.business_days).should == @tuesday
18
+ (@saturday + 1.business_days).should == @tuesday
19
+ (@saturday + 0.business_days).should == @monday
20
+ end
21
+
22
+ it "should subtract properly" do
23
+ (@saturday - 0.business_days).should == @friday
24
+ (@saturday - 1.business_day).should == @thursday
25
+ (@monday - 1.business_days).should == @friday
26
+ (@monday - 0.business_days).should == @monday
27
+ end
28
+
29
+ it "should add with the params reversed" do
30
+ (1.business_day + @friday).should == @monday
31
+ end
26
32
  end
27
33
 
28
- it "should add with the params reversed" do
29
- (1.business_day + @friday).should == @monday
34
+ describe "with Date" do
35
+ before do
36
+ @friday = Date.parse("Friday, September 10th, 2010")
37
+ @thursday = @friday - 1.day
38
+ @saturday = @friday + 1.day
39
+ @monday = @friday + 3.days
40
+ @tuesday = @friday + 4.days
41
+ end
42
+
43
+ it "should add properly" do
44
+ (@friday + 1.business_day).should == @monday
45
+ (@friday + 2.business_days).should == @tuesday
46
+ (@saturday + 1.business_days).should == @tuesday
47
+ (@saturday + 0.business_days).should == @monday
48
+ end
49
+
50
+ it "should subtract properly" do
51
+ (@saturday - 0.business_days).should == @friday
52
+ (@saturday - 1.business_day).should == @thursday
53
+ (@monday - 1.business_days).should == @friday
54
+ (@monday - 0.business_days).should == @monday
55
+ end
56
+
57
+ it "should add with the params reversed" do
58
+ (1.business_day + @friday).should == @monday
59
+ end
60
+
30
61
  end
31
62
 
32
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business_days
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Burke Libbey
@@ -41,6 +41,7 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
 
43
43
  files:
44
+ - lib/business_days/date.rb
44
45
  - lib/business_days/time.rb
45
46
  - lib/business_days.rb
46
47
  - spec/business_days_spec.rb