double_entry 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -12,9 +12,8 @@ module DoubleEntry
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def make(start = nil, finish = nil)
|
15
|
-
|
16
|
-
|
17
|
-
finish = finish ? type.from_time(Time.parse(finish)) : type.current
|
15
|
+
start = start_range(start)
|
16
|
+
finish = finish_range(finish)
|
18
17
|
[ start ].tap do |array|
|
19
18
|
while start != finish
|
20
19
|
start = start.next
|
@@ -23,6 +22,16 @@ module DoubleEntry
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
25
|
+
def start_range(start = nil)
|
26
|
+
raise "Must specify start of range" if start.blank? && require_start?
|
27
|
+
start_time = start ? Time.parse(start) : Reporting.configuration.start_of_business
|
28
|
+
type.from_time(start_time)
|
29
|
+
end
|
30
|
+
|
31
|
+
def finish_range(finish = nil)
|
32
|
+
finish ? type.from_time(Time.parse(finish)) : type.current
|
33
|
+
end
|
34
|
+
|
26
35
|
FACTORIES = {
|
27
36
|
'hour' => new(:type => HourRange, :require_start => true),
|
28
37
|
'day' => new(:type => DayRange, :require_start => true),
|
data/lib/double_entry/version.rb
CHANGED
@@ -110,12 +110,13 @@ module DoubleEntry::Reporting
|
|
110
110
|
context 'for "year" range type' do
|
111
111
|
let(:range_type) { 'year' }
|
112
112
|
|
113
|
-
context 'given
|
114
|
-
|
115
|
-
|
113
|
+
context 'given the date is "2009-11-23"' do
|
114
|
+
before { Timecop.freeze(Time.new(2009, 11, 23)) }
|
115
|
+
|
116
|
+
context 'given start is "2007-05-03" and finish is "2008-08-24"' do
|
117
|
+
let(:start) { '2007-05-03' }
|
118
|
+
let(:finish) { '2008-08-24' }
|
116
119
|
|
117
|
-
context 'and the date is "2009-11-23"' do
|
118
|
-
before { Timecop.freeze(Time.new(2009, 11, 23)) }
|
119
120
|
|
120
121
|
it 'takes notice of start and finish' do
|
121
122
|
should eq [
|
@@ -123,9 +124,17 @@ module DoubleEntry::Reporting
|
|
123
124
|
YearRange.from_time(Time.new(2008)),
|
124
125
|
]
|
125
126
|
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'given the start of business is "2006-07-10"' do
|
130
|
+
before do
|
131
|
+
allow(DoubleEntry::Reporting).
|
132
|
+
to receive_message_chain('configuration.start_of_business').
|
133
|
+
and_return(Time.new(2006, 7, 10))
|
134
|
+
end
|
126
135
|
|
127
|
-
context 'given finish
|
128
|
-
let(:start) {
|
136
|
+
context 'given start and finish are nil' do
|
137
|
+
let(:start) { nil }
|
129
138
|
let(:finish) { nil }
|
130
139
|
it {
|
131
140
|
should eq [
|