timespan 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
data/lib/timespan.rb CHANGED
@@ -111,6 +111,8 @@ class Timespan
111
111
  default_from_now! unless start_time || end_time
112
112
 
113
113
  calculate_miss!
114
+ rescue ArgumentError => e
115
+ raise TimeParseError, e.message
114
116
  rescue Exception => e
115
117
  calculate_miss!
116
118
  validate!
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 = case duration
9
- when Timespan
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
- raise ArgumentError, "Unsupported duration type: #{duration}"
19
- end
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "timespan"
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
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.5
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: -867346219046105956
257
+ hash: -2757811782922718549
258
258
  required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  none: false
260
260
  requirements: