timeframe 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,9 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/rossmeissl/timeframe"
12
12
  gem.authors = ["Andy Rossmeissl", "Seamus Abshere", "Derek Kastner"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_dependency 'activesupport', '>=2.3.8'
15
- gem.add_dependency 'to_json_fix', '>=0.0.1'
16
- gem.add_dependency 'andand'
14
+ gem.add_dependency 'activesupport', '>=2.3.5'
17
15
  end
18
16
  Jeweler::GemcutterTasks.new
19
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/lib/timeframe.rb CHANGED
@@ -6,12 +6,9 @@ require 'active_support/version'
6
6
  active_support/core_ext/date/conversions
7
7
  active_support/core_ext/integer/time
8
8
  active_support/core_ext/numeric/time
9
- active_support/json/encoding
10
9
  }.each do |active_support_3_requirement|
11
10
  require active_support_3_requirement
12
11
  end if ActiveSupport::VERSION::MAJOR == 3
13
- require 'andand'
14
- require 'to_json_fix'
15
12
  require 'timeframe/ykk'
16
13
 
17
14
  # Encapsulates a timeframe between two dates. The dates provided to the class are always until the last date. That means
@@ -54,8 +51,8 @@ class Timeframe
54
51
  to = Date.new(year+1, 1, 1)
55
52
  end
56
53
 
57
- from ||= args.shift.andand.to_date
58
- to ||= args.shift.andand.to_date
54
+ from = args.shift.to_date if from.nil? and args.any?
55
+ to = args.shift.to_date if to.nil? and args.any?
59
56
 
60
57
  raise ArgumentError, "Please supply a start and end date, `#{args.map(&:inspect).to_sentence}' is not enough" if from.nil? or to.nil?
61
58
  raise ArgumentError, "Start date #{from} should be earlier than end date #{to}" if from > to
@@ -248,7 +245,6 @@ class Timeframe
248
245
  end
249
246
 
250
247
  # Just a string that can be processed by Timeframe.interval... identical to #to_param
251
- # accepts multiple arguments because of disagreements between active_support/json and json gem
252
248
  def to_json(*)
253
249
  to_param
254
250
  end
@@ -259,6 +255,10 @@ class Timeframe
259
255
  end
260
256
 
261
257
  class << self
258
+ def make_dates(from, to) # :nodoc:
259
+ return from.to_date, to.to_date
260
+ end
261
+
262
262
  # Shortcut method to return the Timeframe representing the current year (as defined by Time.now)
263
263
  def this_year
264
264
  new :year => Time.now.year
@@ -266,7 +266,8 @@ class Timeframe
266
266
 
267
267
  # Construct a new Timeframe, but constrain it by another
268
268
  def constrained_new(from, to, constraint)
269
- raise ArgumentError, 'Need Date, Date, Timeframe as args' unless from.is_a? Date and to.is_a? Date and constraint.is_a? Timeframe
269
+ from, to = make_dates from, to
270
+ raise ArgumentError, 'Constraint must be a Timeframe' unless constraint.is_a? Timeframe
270
271
  raise ArgumentError, "Start date #{from} should be earlier than end date #{to}" if from > to
271
272
  if to <= constraint.from or from >= constraint.to
272
273
  new constraint.from, constraint.from
@@ -281,8 +282,7 @@ class Timeframe
281
282
 
282
283
  # Shortcut for #new that automatically skips year boundary crossing checks
283
284
  def multiyear(from, to)
284
- from = Date.parse(from) if from.is_a?(String)
285
- to = Date.parse(to) if to.is_a?(String)
285
+ from, to = make_dates from, to
286
286
  new from, to, :skip_year_boundary_crossing_check => true
287
287
  end
288
288
 
@@ -298,8 +298,7 @@ class Timeframe
298
298
  def interval(str)
299
299
  raise ArgumentError, 'Intervals should be specified as a string' unless str.is_a? String
300
300
  raise ArgumentError, 'Intervals should be specified according to ISO 8601, method 1, eliding times' unless str =~ /^\d\d\d\d-\d\d-\d\d\/\d\d\d\d-\d\d-\d\d$/
301
-
302
- new(*str.split('/').map { |date| Date.parse date })
301
+ multiyear *str.split('/')
303
302
  end
304
303
  alias :from_json :interval
305
304
  end
@@ -244,6 +244,11 @@ describe Timeframe do
244
244
  it 'should parse ISO 8601 interval format' do
245
245
  Timeframe.interval('2009-01-01/2010-01-01').should == Timeframe.new(:year => 2009)
246
246
  end
247
+ it 'should skip year boundary checking' do
248
+ lambda {
249
+ Timeframe.interval '2009-01-01/2011-01-01'
250
+ }.should_not raise_error
251
+ end
247
252
  it 'should understand its own #to_param' do
248
253
  t = Timeframe.new(:year => 2009)
249
254
  Timeframe.interval(t.to_param).should == t
data/timeframe.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{timeframe}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Rossmeissl", "Seamus Abshere", "Derek Kastner"]
12
- s.date = %q{2010-07-16}
12
+ s.date = %q{2010-07-20}
13
13
  s.description = %q{A Ruby class for describing and interacting with timeframes.}
14
14
  s.email = %q{andy@rossmeissl.net}
15
15
  s.extra_rdoc_files = [
@@ -46,20 +46,14 @@ Gem::Specification.new do |s|
46
46
 
47
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
48
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
49
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.8"])
50
- s.add_runtime_dependency(%q<to_json_fix>, [">= 0.0.1"])
51
- s.add_runtime_dependency(%q<andand>, [">= 0"])
49
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
52
50
  else
53
51
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
- s.add_dependency(%q<activesupport>, [">= 2.3.8"])
55
- s.add_dependency(%q<to_json_fix>, [">= 0.0.1"])
56
- s.add_dependency(%q<andand>, [">= 0"])
52
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
57
53
  end
58
54
  else
59
55
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
- s.add_dependency(%q<activesupport>, [">= 2.3.8"])
61
- s.add_dependency(%q<to_json_fix>, [">= 0.0.1"])
62
- s.add_dependency(%q<andand>, [">= 0"])
56
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
63
57
  end
64
58
  end
65
59
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeframe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Rossmeissl
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-07-16 00:00:00 -05:00
20
+ date: 2010-07-20 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -44,44 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- hash: 19
47
+ hash: 9
48
48
  segments:
49
49
  - 2
50
50
  - 3
51
- - 8
52
- version: 2.3.8
51
+ - 5
52
+ version: 2.3.5
53
53
  type: :runtime
54
54
  version_requirements: *id002
55
- - !ruby/object:Gem::Dependency
56
- name: to_json_fix
57
- prerelease: false
58
- requirement: &id003 !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 29
64
- segments:
65
- - 0
66
- - 0
67
- - 1
68
- version: 0.0.1
69
- type: :runtime
70
- version_requirements: *id003
71
- - !ruby/object:Gem::Dependency
72
- name: andand
73
- prerelease: false
74
- requirement: &id004 !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
83
- type: :runtime
84
- version_requirements: *id004
85
55
  description: A Ruby class for describing and interacting with timeframes.
86
56
  email: andy@rossmeissl.net
87
57
  executables: []