funtimes 0.2.0 → 0.2.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,56 +1,54 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{funtimes}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Len Smith"]
12
- s.date = %q{2010-07-25}
12
+ s.date = %q{2010-12-01}
13
13
  s.description = %q{Manage date ranges, months and quarters}
14
14
  s.email = %q{ignu.smith@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "funtimes.gemspec",
27
- "lib/funtimes.rb",
28
- "lib/funtimes/date_range.rb",
29
- "lib/funtimes/month.rb",
30
- "lib/funtimes/quarter.rb",
31
- "spec/date_range_spec.rb",
32
- "spec/month_spec.rb",
33
- "spec/quarter_spec.rb",
34
- "spec/spec.opts",
35
- "spec/spec_helper.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "funtimes.gemspec",
26
+ "lib/funtimes.rb",
27
+ "lib/funtimes/date_range.rb",
28
+ "lib/funtimes/month.rb",
29
+ "lib/funtimes/quarter.rb",
30
+ "spec/date_range_spec.rb",
31
+ "spec/month_spec.rb",
32
+ "spec/quarter_spec.rb",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb"
36
35
  ]
37
36
  s.homepage = %q{http://github.com/ignu/fun-times}
38
- s.rdoc_options = ["--charset=UTF-8"]
39
37
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.6}
38
+ s.rubygems_version = %q{1.3.7}
41
39
  s.summary = %q{Manage date ranges, months and quarters}
42
40
  s.test_files = [
43
41
  "spec/date_range_spec.rb",
44
- "spec/month_spec.rb",
45
- "spec/quarter_spec.rb",
46
- "spec/spec_helper.rb"
42
+ "spec/month_spec.rb",
43
+ "spec/quarter_spec.rb",
44
+ "spec/spec_helper.rb"
47
45
  ]
48
46
 
49
47
  if s.respond_to? :specification_version then
50
48
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
49
  s.specification_version = 3
52
50
 
53
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
52
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
53
  else
56
54
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
@@ -1,5 +1,5 @@
1
- module DateRange
2
-
1
+ module DateRange
2
+
3
3
  def days
4
4
  (_start)..(_end)
5
5
  end
@@ -15,10 +15,10 @@ module DateRange
15
15
  end
16
16
 
17
17
  def encompasses(other)
18
- _start <= other.start_date && _end >= other.end_date
18
+ _start <= other.start_date && _end >= other.end_date
19
19
  end
20
20
 
21
- def intersects(other)
21
+ def intersects(other)
22
22
  other.encompasses(self) || encompasses(other) || overlaps(other)
23
23
  end
24
24
 
@@ -30,7 +30,14 @@ module DateRange
30
30
  SimpleRange.new(_start, other.end_date)
31
31
  end
32
32
 
33
- def same_range_as(other)
33
+ def | (other)
34
+ return [] unless intersects other
35
+ return self if encompasses(other)
36
+ return other if other.encompasses(self)
37
+ SimpleRange.new([_start,other.start_date].min, [_end,other.end_date].max)
38
+ end
39
+
40
+ def same_range_as(other)
34
41
  other.start_date == _start && other.end_date == _end
35
42
  end
36
43
 
@@ -41,7 +48,7 @@ module DateRange
41
48
  end
42
49
 
43
50
  private
44
-
51
+
45
52
  def overlaps(other)
46
53
  overlaps_left_side(other) || overlaps_right_side(other)
47
54
  end
@@ -60,7 +67,7 @@ module DateRange
60
67
  @start_date
61
68
  end
62
69
 
63
- def _end
70
+ def _end
64
71
  @end_date ||= end_date
65
72
  return @end_date.to_datetime if @end_date.respond_to? :to_datetime
66
73
  @end_date
@@ -13,11 +13,11 @@ describe "DateRange" do
13
13
  let(:march) { SimpleRange.new(firstOfMarch, endOfMarch)}
14
14
  let(:july) { SimpleRange.new(firstOfJuly, endOfJuly)}
15
15
 
16
- it "should be equal if start and end dates are the same" do
17
- year.same_range_as(year).should == true
16
+ it "should be equal if start and end dates are the same" do
17
+ year.same_range_as(year).should == true
18
18
  end
19
19
 
20
- it "should have the quarters in a range" do
20
+ it "should have the quarters in a range" do
21
21
  year.quarters.first.number.should == 1
22
22
  year.quarters.to_a.length.should == 4
23
23
  end
@@ -25,20 +25,20 @@ describe "DateRange" do
25
25
  it "should count the days in the range" do
26
26
  range.days.to_a.length.should == 31+28+31+30+31+30+5
27
27
  end
28
-
28
+
29
29
  it "should be able to get the number of months in a range" do
30
30
  range.months.to_a.length.should == 7
31
31
  end
32
32
 
33
- describe DateRange, "intersecting dates" do
33
+ describe DateRange, "intersecting dates" do
34
34
 
35
- it "should tell if one date range encompasses another" do
36
- year.encompasses(march).should == true
35
+ it "should tell if one date range encompasses another" do
36
+ year.encompasses(march).should == true
37
37
  march.encompasses(year).should == false
38
38
  march.encompasses(july).should == false
39
- end
39
+ end
40
40
 
41
- it "should be able to tell if one date range intersects another" do
41
+ it "should be able to tell if one date range intersects another" do
42
42
  year.intersects(march).should == true
43
43
  year.intersects(year).should == true
44
44
  march.intersects(year).should == true
@@ -47,28 +47,42 @@ describe "DateRange" do
47
47
  july.intersects(range).should == true
48
48
  end
49
49
 
50
- it "can return the intersection" do
50
+ it "can return the intersection" do
51
51
  (year & march).should == march
52
52
  (march & year).should == march
53
53
  (march & march).should == march
54
-
54
+
55
55
  left = (range & july)
56
56
  left.start_date.should == firstOfJuly
57
57
  left.end_date.should == range.end_date
58
58
  left = (july & range)
59
59
  left.start_date.should == firstOfJuly
60
60
  left.end_date.should == range.end_date
61
-
61
+
62
62
  (march & july).should == []
63
63
  end
64
64
 
65
+ it "can return the union" do
66
+ (year | march).should == year
67
+ (march | year).should == year
68
+ (march | march).should == march
69
+
70
+ union = (range | july)
71
+ union.start_date.should == range.start_date
72
+ union.end_date.should == endOfJuly
73
+ union = (july | range)
74
+ union.start_date.should == range.start_date
75
+ union.end_date.should == endOfJuly
76
+
77
+ (march | july).should == []
78
+ end
65
79
 
66
80
  it "can figure out the number of days in" do
67
81
  year.number_of_days_in(march).should == 30
68
82
  march.number_of_days_in(july).should == 0
69
83
  end
70
84
 
71
- it "returns null collections when start or end date is not set" do
85
+ it "returns null collections when start or end date is not set" do
72
86
  r = SimpleRange.new(nil, DateTime.new)
73
87
  r.months.length.should == 0
74
88
  r = SimpleRange.new(DateTime.new, nil)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funtimes
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 21
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 0
9
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Len Smith
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-25 00:00:00 -04:00
18
+ date: 2010-12-01 00:00:00 -05:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 13
27
30
  segments:
28
31
  - 1
29
32
  - 2
@@ -42,7 +45,6 @@ extra_rdoc_files:
42
45
  - README.rdoc
43
46
  files:
44
47
  - .document
45
- - .gitignore
46
48
  - LICENSE
47
49
  - README.rdoc
48
50
  - Rakefile
@@ -62,28 +64,32 @@ homepage: http://github.com/ignu/fun-times
62
64
  licenses: []
63
65
 
64
66
  post_install_message:
65
- rdoc_options:
66
- - --charset=UTF-8
67
+ rdoc_options: []
68
+
67
69
  require_paths:
68
70
  - lib
69
71
  required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
70
73
  requirements:
71
74
  - - ">="
72
75
  - !ruby/object:Gem::Version
76
+ hash: 3
73
77
  segments:
74
78
  - 0
75
79
  version: "0"
76
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
77
82
  requirements:
78
83
  - - ">="
79
84
  - !ruby/object:Gem::Version
85
+ hash: 3
80
86
  segments:
81
87
  - 0
82
88
  version: "0"
83
89
  requirements: []
84
90
 
85
91
  rubyforge_project:
86
- rubygems_version: 1.3.6
92
+ rubygems_version: 1.3.7
87
93
  signing_key:
88
94
  specification_version: 3
89
95
  summary: Manage date ranges, months and quarters
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC