timespan 0.2.5 → 0.2.6
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 +1 -1
- data/lib/timespan.rb +2 -0
- data/lib/timespan/span.rb +15 -11
- data/spec/timespan/mongoid/mongoid_timespan_spec.rb +11 -0
- data/timespan.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/timespan.rb
CHANGED
data/lib/timespan/span.rb
CHANGED
@@ -5,18 +5,22 @@ class Timespan
|
|
5
5
|
attr_reader :duration
|
6
6
|
|
7
7
|
def duration= duration
|
8
|
-
@duration =
|
9
|
-
|
10
|
-
duration.duration
|
11
|
-
when Duration
|
12
|
-
duration
|
13
|
-
when Numeric, Hash
|
14
|
-
Duration.new duration
|
15
|
-
when String
|
16
|
-
Duration.new parse_duration(duration)
|
8
|
+
@duration = if duration.kind_of? Numeric
|
9
|
+
Duration.new duration
|
17
10
|
else
|
18
|
-
|
19
|
-
|
11
|
+
case duration
|
12
|
+
when Timespan
|
13
|
+
duration.duration
|
14
|
+
when Duration
|
15
|
+
duration
|
16
|
+
when Hash
|
17
|
+
Duration.new duration
|
18
|
+
when String
|
19
|
+
Duration.new parse_duration(duration)
|
20
|
+
else
|
21
|
+
raise ArgumentError, "Unsupported duration type: #{duration.inspect} of class #{duration.class}"
|
22
|
+
end
|
23
|
+
end
|
20
24
|
unless is_new?
|
21
25
|
add_dirty :duration
|
22
26
|
refresh!
|
@@ -18,6 +18,17 @@ describe Timespan do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
context '2 days duration using integer' do
|
22
|
+
let(:account) do
|
23
|
+
Account.create :period => {:duration => 2.days }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.start_date' do
|
27
|
+
it 'should default to today' do
|
28
|
+
DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
21
32
|
|
22
33
|
context '2 days duration (from now - default)' do
|
23
34
|
let(:account) do
|
data/timespan.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timespan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -254,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
segments:
|
256
256
|
- 0
|
257
|
-
hash: -
|
257
|
+
hash: -2757811782922718549
|
258
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
259
|
none: false
|
260
260
|
requirements:
|