funtimes 0.2.1 → 0.3.0
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/Rakefile +5 -8
- data/VERSION +1 -1
- data/funtimes.gemspec +14 -19
- data/lib/funtimes.rb +1 -0
- data/lib/funtimes/month.rb +9 -9
- data/lib/funtimes/week.rb +32 -0
- data/spec/date_range_spec.rb +1 -1
- data/spec/month_spec.rb +5 -6
- data/spec/spec_helper.rb +1 -6
- data/spec/week_spec.rb +25 -0
- metadata +32 -58
data/Rakefile
CHANGED
@@ -10,22 +10,19 @@ begin
|
|
10
10
|
gem.email = "ignu.smith@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/ignu/fun-times"
|
12
12
|
gem.authors = ["Len Smith"]
|
13
|
-
gem.add_development_dependency "rspec", ">=
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
gem.add_development_dependency "rspec", ">= 2.5.0"
|
15
14
|
end
|
16
15
|
Jeweler::GemcutterTasks.new
|
17
16
|
rescue LoadError
|
18
17
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
18
|
end
|
20
19
|
|
21
|
-
require '
|
22
|
-
|
23
|
-
spec.
|
24
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
20
|
+
require 'rspec/core/rake_task'
|
21
|
+
RSpec::Core::RakeTask.new do |spec|
|
22
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
25
23
|
end
|
26
24
|
|
27
|
-
|
28
|
-
spec.libs << 'lib' << 'spec'
|
25
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
29
26
|
spec.pattern = 'spec/**/*_spec.rb'
|
30
27
|
spec.rcov = true
|
31
28
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/funtimes.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "funtimes"
|
8
|
+
s.version = "0.3.0"
|
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 =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-10-03"
|
13
|
+
s.description = "Manage date ranges, months and quarters"
|
14
|
+
s.email = "ignu.smith@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -27,34 +27,29 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/funtimes/date_range.rb",
|
28
28
|
"lib/funtimes/month.rb",
|
29
29
|
"lib/funtimes/quarter.rb",
|
30
|
+
"lib/funtimes/week.rb",
|
30
31
|
"spec/date_range_spec.rb",
|
31
32
|
"spec/month_spec.rb",
|
32
33
|
"spec/quarter_spec.rb",
|
33
34
|
"spec/spec.opts",
|
34
|
-
"spec/spec_helper.rb"
|
35
|
+
"spec/spec_helper.rb",
|
36
|
+
"spec/week_spec.rb"
|
35
37
|
]
|
36
|
-
s.homepage =
|
38
|
+
s.homepage = "http://github.com/ignu/fun-times"
|
37
39
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version =
|
39
|
-
s.summary =
|
40
|
-
s.test_files = [
|
41
|
-
"spec/date_range_spec.rb",
|
42
|
-
"spec/month_spec.rb",
|
43
|
-
"spec/quarter_spec.rb",
|
44
|
-
"spec/spec_helper.rb"
|
45
|
-
]
|
40
|
+
s.rubygems_version = "1.8.10"
|
41
|
+
s.summary = "Manage date ranges, months and quarters"
|
46
42
|
|
47
43
|
if s.respond_to? :specification_version then
|
48
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
44
|
s.specification_version = 3
|
50
45
|
|
51
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_development_dependency(%q<rspec>, [">=
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
|
53
48
|
else
|
54
|
-
s.add_dependency(%q<rspec>, [">=
|
49
|
+
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
55
50
|
end
|
56
51
|
else
|
57
|
-
s.add_dependency(%q<rspec>, [">=
|
52
|
+
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
data/lib/funtimes.rb
CHANGED
data/lib/funtimes/month.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'funtimes/date_range'
|
3
|
+
|
3
4
|
class Month
|
4
5
|
include Comparable
|
5
6
|
include DateRange
|
6
7
|
attr_accessor :year, :number, :start_date, :end_date
|
7
|
-
|
8
|
+
|
8
9
|
def self.from(date)
|
9
10
|
Month.new(date.month, date.year)
|
10
11
|
end
|
@@ -21,39 +22,38 @@ class Month
|
|
21
22
|
|
22
23
|
def name
|
23
24
|
@start_date.strftime("%B")
|
24
|
-
end
|
25
|
+
end
|
25
26
|
|
26
27
|
def <=> (other)
|
27
28
|
return @year <=> other.year unless @year == other.year
|
28
29
|
@number <=> other.number
|
29
30
|
end
|
30
31
|
|
31
|
-
def succ
|
32
|
+
def succ
|
32
33
|
Month.from next_months_start
|
33
34
|
end
|
34
35
|
|
35
|
-
def prev
|
36
|
+
def prev
|
36
37
|
return Month.new(12, @year-1) if (@number == 1)
|
37
38
|
Month.new @number-1, @year
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
def + (amount)
|
41
42
|
rv = self
|
42
43
|
amount.times {rv = rv.succ}
|
43
|
-
rv
|
44
|
+
rv
|
44
45
|
end
|
45
46
|
|
46
47
|
def -(amount)
|
47
48
|
rv = self
|
48
49
|
amount.times {rv = rv.prev}
|
49
|
-
rv
|
50
|
+
rv
|
50
51
|
end
|
51
52
|
|
52
53
|
private
|
53
54
|
|
54
55
|
def next_months_start
|
55
56
|
return DateTime.new(@year+1, 1, 1) if (@number == 12)
|
56
|
-
DateTime.new(@year, @number+1, 1)
|
57
|
+
DateTime.new(@year, @number+1, 1)
|
57
58
|
end
|
58
59
|
end
|
59
|
-
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'funtimes/date_range'
|
3
|
+
|
4
|
+
class Week
|
5
|
+
START_DAY = 0
|
6
|
+
|
7
|
+
include DateRange
|
8
|
+
|
9
|
+
def initialize(date)
|
10
|
+
start_date = get_start_date(date)
|
11
|
+
@start_date, @end_date = start_date, start_date + 6
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from(start_date)
|
15
|
+
Week.new start_date
|
16
|
+
end
|
17
|
+
|
18
|
+
def previous
|
19
|
+
Week.new(@start_date - 7)
|
20
|
+
end
|
21
|
+
|
22
|
+
def next
|
23
|
+
Week.new(@start_date + 7)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_start_date(date)
|
29
|
+
date = date -1 while date.wday != START_DAY
|
30
|
+
date
|
31
|
+
end
|
32
|
+
end
|
data/spec/date_range_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe "DateRange" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should count the days in the range" do
|
26
|
-
range.days.to_a.length.should == 31+28+31+30+31+30+5
|
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
|
data/spec/month_spec.rb
CHANGED
@@ -7,10 +7,10 @@ describe "Month" do
|
|
7
7
|
it "can initialize the month of a date" do
|
8
8
|
july.to_s.should == "July 1977"
|
9
9
|
july.name.should == "July"
|
10
|
-
july.year.should == 1977
|
10
|
+
july.year.should == 1977
|
11
11
|
july.number.should == 7
|
12
|
-
july.start_date.should == Date.new(1977, 7, 1)
|
13
|
-
july.end_date.should == Date.new(1977, 7, 31)
|
12
|
+
july.start_date.should == Date.new(1977, 7, 1)
|
13
|
+
july.end_date.should == Date.new(1977, 7, 31)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "can use the less than operator" do
|
@@ -29,13 +29,12 @@ describe "Month" do
|
|
29
29
|
range.to_a.length.should == 7
|
30
30
|
end
|
31
31
|
|
32
|
-
it "can add and subtract months" do
|
32
|
+
it "can add and subtract months" do
|
33
33
|
(july+1).to_s.should == "August 1977"
|
34
34
|
(july-1).to_s.should == "June 1977"
|
35
35
|
end
|
36
36
|
|
37
|
-
it "is a daterange" do
|
37
|
+
it "is a daterange" do
|
38
38
|
july.days.to_a.length.should == 31
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/week_spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Week do
|
4
|
+
let(:first_week) { Week.from(DateTime.new(2011, 10, 5)) }
|
5
|
+
|
6
|
+
it "can initialize the week from a day" do
|
7
|
+
first_week.days.to_a.length.should == 7
|
8
|
+
end
|
9
|
+
|
10
|
+
it "starts the week on a sunday" do
|
11
|
+
first_week.days.first.should == Date.new(2011, 10, 2)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#next" do
|
15
|
+
it "returns the next week" do
|
16
|
+
first_week.next.days.first.should == Date.new(2011, 10, 9)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#previous" do
|
21
|
+
it "returns the previous week" do
|
22
|
+
first_week.previous.days.first.should == Date.new(2011, 9, 25)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,49 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: funtimes
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 1
|
10
|
-
version: 0.2.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Len Smith
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-03 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70267984884580 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 2
|
33
|
-
- 9
|
34
|
-
version: 1.2.9
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.5.0
|
35
22
|
type: :development
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70267984884580
|
37
25
|
description: Manage date ranges, months and quarters
|
38
26
|
email: ignu.smith@gmail.com
|
39
27
|
executables: []
|
40
|
-
|
41
28
|
extensions: []
|
42
|
-
|
43
|
-
extra_rdoc_files:
|
29
|
+
extra_rdoc_files:
|
44
30
|
- LICENSE
|
45
31
|
- README.rdoc
|
46
|
-
files:
|
32
|
+
files:
|
47
33
|
- .document
|
48
34
|
- LICENSE
|
49
35
|
- README.rdoc
|
@@ -54,47 +40,35 @@ files:
|
|
54
40
|
- lib/funtimes/date_range.rb
|
55
41
|
- lib/funtimes/month.rb
|
56
42
|
- lib/funtimes/quarter.rb
|
43
|
+
- lib/funtimes/week.rb
|
57
44
|
- spec/date_range_spec.rb
|
58
45
|
- spec/month_spec.rb
|
59
46
|
- spec/quarter_spec.rb
|
60
47
|
- spec/spec.opts
|
61
48
|
- spec/spec_helper.rb
|
62
|
-
|
49
|
+
- spec/week_spec.rb
|
63
50
|
homepage: http://github.com/ignu/fun-times
|
64
51
|
licenses: []
|
65
|
-
|
66
52
|
post_install_message:
|
67
53
|
rdoc_options: []
|
68
|
-
|
69
|
-
require_paths:
|
54
|
+
require_paths:
|
70
55
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
57
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
- 0
|
79
|
-
version: "0"
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
63
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
version: "0"
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
89
68
|
requirements: []
|
90
|
-
|
91
69
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.8.10
|
93
71
|
signing_key:
|
94
72
|
specification_version: 3
|
95
73
|
summary: Manage date ranges, months and quarters
|
96
|
-
test_files:
|
97
|
-
- spec/date_range_spec.rb
|
98
|
-
- spec/month_spec.rb
|
99
|
-
- spec/quarter_spec.rb
|
100
|
-
- spec/spec_helper.rb
|
74
|
+
test_files: []
|