ruby-units 1.3.1 → 1.3.2.a

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,14 +14,14 @@ class Time
14
14
  def self.at(arg)
15
15
  case arg
16
16
  when Unit
17
- unit_time_at(arg.to("s").scalar)
17
+ unit_time_at(arg.convert_to("s").scalar)
18
18
  else
19
19
  unit_time_at(arg)
20
20
  end
21
21
  end
22
22
 
23
23
  def to_unit(other = nil)
24
- other ? Unit.new(self).to(other) : Unit.new(self)
24
+ other ? Unit.new(self).convert_to(other) : Unit.new(self)
25
25
  end
26
26
  alias :unit :to_unit
27
27
  alias :u :to_unit
@@ -37,9 +37,9 @@ class Time
37
37
  def +(other)
38
38
  case other
39
39
  when Unit
40
- other = other.to('d').round.to('s') if ['y', 'decade', 'century'].include? other.units
40
+ other = other.convert_to('d').round.convert_to('s') if ['y', 'decade', 'century'].include? other.units
41
41
  begin
42
- unit_add(other.to('s').scalar)
42
+ unit_add(other.convert_to('s').scalar)
43
43
  rescue RangeError
44
44
  self.to_datetime + other
45
45
  end
@@ -58,9 +58,9 @@ class Time
58
58
  def -(other)
59
59
  case other
60
60
  when Unit
61
- other = other.to('d').round.to('s') if ['y', 'decade', 'century'].include? other.units
61
+ other = other.convert_to('d').round.convert_to('s') if ['y', 'decade', 'century'].include? other.units
62
62
  begin
63
- unit_sub(other.to('s').scalar)
63
+ unit_sub(other.convert_to('s').scalar)
64
64
  rescue RangeError
65
65
  self.send(:to_datetime) - other
66
66
  end
@@ -47,7 +47,7 @@ class Unit < Numeric
47
47
  @@UNIT_MAP = {}
48
48
  @@UNIT_VALUES = {}
49
49
  @@OUTPUT_MAP = {}
50
- @@BASE_UNITS = ['<meter>','<kilogram>','<second>','<mole>', '<farad>', '<ampere>','<radian>','<kelvin>','<temp-K>','<byte>','<dollar>','<candela>','<each>','<steradian>','<decibel>']
50
+ @@BASE_UNITS = ['<meter>','<kilogram>','<second>','<mole>', '<ampere>','<radian>','<kelvin>','<tempK>','<byte>','<dollar>','<candela>','<each>','<steradian>','<decibel>']
51
51
  UNITY = '<1>'
52
52
  UNITY_ARRAY= [UNITY]
53
53
  FEET_INCH_REGEX = /(\d+)\s*(?:'|ft|feet)\s*(\d+)\s*(?:"|in|inches)/
@@ -69,35 +69,46 @@ class Unit < Numeric
69
69
  CELSIUS = ['<celsius>']
70
70
  TEMP_REGEX = /(?:temp|deg)[CFRK]/
71
71
 
72
- SIGNATURE_VECTOR = [:length, :time, :temperature, :mass, :current, :substance, :luminosity, :currency, :memory, :angle, :capacitance]
72
+ SIGNATURE_VECTOR = [:length, :time, :temperature, :mass, :current, :substance, :luminosity, :currency, :memory, :angle]
73
73
  @@KINDS = {
74
- -312058=>:resistance,
74
+ -312078 => :elastance,
75
+ -312058=>:resistance,
75
76
  -312038=>:inductance,
76
77
  -152040=>:magnetism,
77
78
  -152038=>:magnetism,
78
- -152058=>:potential,
79
+ -152058=>:potential,
80
+ -7997 => :specific_volume,
81
+ -79 => :snap,
82
+ -59 => :jolt,
79
83
  -39=>:acceleration,
80
84
  -38=>:radiation,
81
85
  -20=>:frequency,
82
86
  -19=>:speed,
83
87
  -18=>:viscosity,
88
+ -17 => :volumetric_flow,
89
+ -1 => :wavenumber,
84
90
  0=>:unitless,
85
91
  1=>:length,
86
92
  2=>:area,
87
93
  3=>:volume,
88
94
  20=>:time,
89
95
  400=>:temperature,
96
+ 7941 => :yank,
90
97
  7942=>:power,
91
98
  7959=>:pressure,
92
99
  7962=>:energy,
93
100
  7979=>:viscosity,
94
101
  7961=>:force,
95
- 7997=>:mass_concentration,
102
+ 7981 => :momentum,
103
+ 7982 => :angular_momentum,
104
+ 7997 => :density,
105
+ 7998 => :area_density,
96
106
  8000=>:mass,
97
107
  159999=>:magnetism,
98
108
  160000=>:current,
99
109
  160020=>:charge,
100
- 312058=>:resistance,
110
+ 312058=>:resistance,
111
+ 312078=>:capacitance,
101
112
  3199980=>:activity,
102
113
  3199997=>:molar_concentration,
103
114
  3200000=>:substance,
@@ -106,8 +117,7 @@ class Unit < Numeric
106
117
  1280000000=>:currency,
107
118
  25600000000=>:memory,
108
119
  511999999980=>:angular_velocity,
109
- 512000000000=>:angle,
110
- 10240000000000=>:capacitance,
120
+ 512000000000=>:angle
111
121
  }
112
122
 
113
123
  @@cached_units = {}
@@ -286,7 +296,7 @@ class Unit < Numeric
286
296
  #
287
297
  def self.parse(input)
288
298
  first, second = input.scan(/(.+)\s(?:in|to|as)\s(.+)/i).first
289
- second.nil? ? first.unit : first.unit.to(second)
299
+ second.nil? ? first.unit : first.unit.convert_to(second)
290
300
  end
291
301
 
292
302
  def to_unit
@@ -320,9 +330,9 @@ class Unit < Numeric
320
330
  end
321
331
  base = case
322
332
  when self.is_temperature?
323
- self.to('tempK')
333
+ self.convert_to('tempK')
324
334
  when self.is_degree?
325
- self.to('degK')
335
+ self.convert_to('degK')
326
336
  end
327
337
  return base
328
338
  end
@@ -380,17 +390,17 @@ class Unit < Numeric
380
390
  else
381
391
  case target_units
382
392
  when :ft
383
- inches = self.to("in").scalar.to_int
393
+ inches = self.convert_to("in").scalar.to_int
384
394
  out = "#{(inches / 12).truncate}\'#{(inches % 12).round}\""
385
395
  when :lbs
386
- ounces = self.to("oz").scalar.to_int
396
+ ounces = self.convert_to("oz").scalar.to_int
387
397
  out = "#{(ounces / 16).truncate} lbs, #{(ounces % 16).round} oz"
388
398
  when String
389
399
  out = case target_units
390
400
  when /(%[\-+\.\w#]+)\s*(.+)*/ #format string like '%0.2f in'
391
401
  begin
392
402
  if $2 #unit specified, need to convert
393
- self.to($2).to_s($1)
403
+ self.convert_to($2).to_s($1)
394
404
  else
395
405
  "#{$1 % @scalar} #{$2 || self.units}".strip
396
406
  end
@@ -398,7 +408,7 @@ class Unit < Numeric
398
408
  (DateTime.new(0) + self).strftime(target_units)
399
409
  end
400
410
  when /(\S+)/ #unit only 'mm' or '1/mm'
401
- "#{self.to($1).to_s}"
411
+ "#{self.convert_to($1).to_s}"
402
412
  else
403
413
  raise "unhandled case"
404
414
  end
@@ -533,9 +543,9 @@ class Unit < Numeric
533
543
  raise ArgumentError, "Cannot add two temperatures" if ([self, other].all? {|x| x.is_temperature?})
534
544
  if [self, other].any? {|x| x.is_temperature?}
535
545
  if self.is_temperature?
536
- Unit.new(:scalar => (self.scalar + other.to(self.temperature_scale).scalar), :numerator => @numerator, :denominator=>@denominator, :signature => @signature)
546
+ Unit.new(:scalar => (self.scalar + other.convert_to(self.temperature_scale).scalar), :numerator => @numerator, :denominator=>@denominator, :signature => @signature)
537
547
  else
538
- Unit.new(:scalar => (other.scalar + self.to(other.temperature_scale).scalar), :numerator => other.numerator, :denominator=>other.denominator, :signature => other.signature)
548
+ Unit.new(:scalar => (other.scalar + self.convert_to(other.temperature_scale).scalar), :numerator => other.numerator, :denominator=>other.denominator, :signature => other.signature)
539
549
  end
540
550
  else
541
551
  @q ||= ((@@cached_units[self.units].scalar / @@cached_units[self.units].base_scalar) rescue (self.units.unit.to_base.scalar))
@@ -563,9 +573,9 @@ class Unit < Numeric
563
573
  when self =~ other
564
574
  case
565
575
  when [self, other].all? {|x| x.is_temperature?}
566
- Unit.new(:scalar => (self.base_scalar - other.base_scalar), :numerator => KELVIN, :denominator => UNITY_ARRAY, :signature => @signature).to(self.temperature_scale)
576
+ Unit.new(:scalar => (self.base_scalar - other.base_scalar), :numerator => KELVIN, :denominator => UNITY_ARRAY, :signature => @signature).convert_to(self.temperature_scale)
567
577
  when self.is_temperature?
568
- Unit.new(:scalar => (self.base_scalar - other.base_scalar), :numerator => ['<temp-K>'], :denominator => UNITY_ARRAY, :signature => @signature).to(self)
578
+ Unit.new(:scalar => (self.base_scalar - other.base_scalar), :numerator => ['<tempK>'], :denominator => UNITY_ARRAY, :signature => @signature).convert_to(self)
569
579
  when other.is_temperature?
570
580
  raise ArgumentError, "Cannot subtract a temperature from a differential degree unit"
571
581
  else
@@ -731,7 +741,7 @@ class Unit < Numeric
731
741
  #
732
742
  # Note that if temperature is part of a compound unit, the temperature will be treated as a differential
733
743
  # and the units will be scaled appropriately.
734
- def to(other)
744
+ def convert_to(other)
735
745
  return self if other.nil?
736
746
  return self if TrueClass === other
737
747
  return self if FalseClass === other
@@ -778,18 +788,6 @@ class Unit < Numeric
778
788
  _numerator2 = target.numerator.map {|x| @@PREFIX_VALUES[x] ? @@PREFIX_VALUES[x] : x}.map {|x| x.kind_of?(Numeric) ? x : @@UNIT_VALUES[x][:scalar] }.compact
779
789
  _denominator2 = target.denominator.map {|x| @@PREFIX_VALUES[x] ? @@PREFIX_VALUES[x] : x}.map {|x| x.kind_of?(Numeric) ? x : @@UNIT_VALUES[x][:scalar] }.compact
780
790
 
781
- # eliminate common terms
782
-
783
- (_numerator1 & _denominator2).each do |common|
784
- _numerator1.delete(common)
785
- _denominator2.delete(common)
786
- end
787
-
788
- (_numerator2 & _denominator1).each do |common|
789
- _numerator1.delete(common)
790
- _denominator2.delete(common)
791
- end
792
-
793
791
  q = @scalar * ( (_numerator1 + _denominator2).inject(1) {|product,n| product*n} ) /
794
792
  ( (_numerator2 + _denominator1).inject(1) {|product,n| product*n} )
795
793
 
@@ -797,8 +795,8 @@ class Unit < Numeric
797
795
  Unit.new(:scalar=>q, :numerator=>target.numerator, :denominator=>target.denominator, :signature => target.signature)
798
796
  end
799
797
  end
800
- alias :>> :to
801
- alias :convert_to :to
798
+ alias :>> :convert_to
799
+ alias :to :convert_to
802
800
 
803
801
  # converts the unit back to a float if it is unitless. Otherwise raises an exception
804
802
  def to_f
@@ -921,11 +919,11 @@ class Unit < Numeric
921
919
  # convert a duration to a DateTime. This will work so long as the duration is the duration from the zero date
922
920
  # defined by DateTime
923
921
  def to_datetime
924
- DateTime.new!(self.to('d').scalar)
922
+ DateTime.new!(self.convert_to('d').scalar)
925
923
  end
926
924
 
927
925
  def to_date
928
- Date.new0(self.to('d').scalar)
926
+ Date.new0(self.convert_to('d').scalar)
929
927
  end
930
928
 
931
929
 
@@ -941,50 +939,46 @@ class Unit < Numeric
941
939
 
942
940
  # '5 min'.before(time)
943
941
  def before(time_point = ::Time.now)
944
- raise ArgumentError, "Must specify a Time" unless time_point
945
- if String === time_point
946
- time_point.time - self rescue time_point.datetime - self
947
- else
942
+ case time_point
943
+ when Time, Date, DateTime
948
944
  time_point - self rescue time_point.to_datetime - self
945
+ else
946
+ raise ArgumentError, "Must specify a Time, Date, or DateTime"
949
947
  end
950
948
  end
951
949
  alias :before_now :before
952
950
 
953
951
  # 'min'.since(time)
954
- def since(time_point = ::Time.now)
952
+ def since(time_point)
955
953
  case time_point
956
954
  when Time
957
- (Time.now - time_point).unit('s').to(self)
955
+ (Time.now - time_point).unit('s').convert_to(self)
958
956
  when DateTime, Date
959
- (DateTime.now - time_point).unit('d').to(self)
960
- when String
961
- (DateTime.now - time_point.to_datetime(:context=>:past)).unit('d').to(self)
957
+ (DateTime.now - time_point).unit('d').convert_to(self)
962
958
  else
963
- raise ArgumentError, "Must specify a Time, DateTime, or String"
959
+ raise ArgumentError, "Must specify a Time, Date, or DateTime"
964
960
  end
965
961
  end
966
962
 
967
963
  # 'min'.until(time)
968
- def until(time_point = ::Time.now)
964
+ def until(time_point)
969
965
  case time_point
970
966
  when Time
971
- (time_point - Time.now).unit('s').to(self)
967
+ (time_point - Time.now).unit('s').convert_to(self)
972
968
  when DateTime, Date
973
- (time_point - DateTime.now).unit('d').to(self)
974
- when String
975
- (time_point.to_datetime(:context=>:future) - DateTime.now).unit('d').to(self)
969
+ (time_point - DateTime.now).unit('d').convert_to(self)
976
970
  else
977
- raise ArgumentError, "Must specify a Time, DateTime, or String"
971
+ raise ArgumentError, "Must specify a Time, Date, or DateTime"
978
972
  end
979
973
  end
980
974
 
981
975
  # '5 min'.from(time)
982
- def from(time_point = ::Time.now)
983
- raise ArgumentError, "Must specify a Time" unless time_point
984
- if String === time_point
985
- time_point.time + self rescue time_point.datetime + self
986
- else
976
+ def from(time_point)
977
+ case time_point
978
+ when Time, DateTime, Date
987
979
  time_point + self rescue time_point.to_datetime + self
980
+ else
981
+ raise ArgumentError, "Must specify a Time, Date, or DateTime"
988
982
  end
989
983
  end
990
984
  alias :after :from
@@ -1240,6 +1234,10 @@ class Unit < Numeric
1240
1234
  self
1241
1235
  end
1242
1236
 
1237
+ def self.base_units
1238
+ @@BASE_UNITS.map {|u| Unit.new(u)}
1239
+ end
1240
+
1243
1241
  private
1244
1242
 
1245
1243
  # parse a string consisting of a number and a unit string
@@ -81,6 +81,9 @@ UNIT_DEFINITIONS = {
81
81
  '<tablespoon>'=> [%w{tbs tablespoon tablespoons}, 1.47867648e-5, :volume, %w{<meter> <meter> <meter>}],
82
82
  '<teaspoon>'=> [%w{tsp teaspoon teaspoons}, 4.92892161e-6, :volume, %w{<meter> <meter> <meter>}],
83
83
 
84
+ #volumetric flow
85
+ '<cfm>' => [%w{cfm CFM CFPM}, (18435447/39062500000), :volumetric_flow, %w{<meter> <meter> <meter>}, %w{<second>}],
86
+
84
87
  #speed
85
88
  '<kph>' => [%w{kph}, 0.277777778, :speed, %w{<meter>}, %w{<second>}],
86
89
  '<mph>' => [%w{mph}, 0.44704, :speed, %w{<meter>}, %w{<second>}],
@@ -89,16 +92,17 @@ UNIT_DEFINITIONS = {
89
92
 
90
93
  #acceleration
91
94
  '<gee>' => [%w{gee}, 9.80655, :acceleration, %w{<meter>}, %w{<second> <second>}],
95
+
92
96
 
93
97
  #temperature_difference
94
98
  '<kelvin>' => [%w{degK kelvin}, 1, :temperature, %w{<kelvin>}],
95
99
  '<celsius>' => [%w{degC celsius celsius centigrade}, 1, :temperature, %w{<kelvin>}],
96
100
  '<fahrenheit>' => [%w{degF fahrenheit}, Rational(1,1.8), :temperature, %w{<kelvin>}],
97
101
  '<rankine>' => [%w{degR rankine}, Rational(1,1.8), :temperature, %w{<kelvin>}],
98
- '<temp-K>' => [%w{tempK}, 1, :temperature, %w{<temp-K>}],
99
- '<temp-C>' => [%w{tempC}, 1, :temperature, %w{<temp-K>}],
100
- '<temp-F>' => [%w{tempF}, Rational(1,1.8), :temperature, %w{<temp-K>}],
101
- '<temp-R>' => [%w{tempR}, Rational(1,1.8), :temperature, %w{<temp-K>}],
102
+ '<tempK>' => [%w{tempK}, 1, :temperature, %w{<tempK>}],
103
+ '<tempC>' => [%w{tempC}, 1, :temperature, %w{<tempK>}],
104
+ '<tempF>' => [%w{tempF}, Rational(1,1.8), :temperature, %w{<tempK>}],
105
+ '<tempR>' => [%w{tempR}, Rational(1,1.8), :temperature, %w{<tempK>}],
102
106
 
103
107
  #time
104
108
  '<second>'=> [%w{s sec second seconds}, 1, :time, %w{<second>}],
@@ -139,7 +143,7 @@ UNIT_DEFINITIONS = {
139
143
  '<unit>' => [%w{U enzUnit}, 16.667e-16, :activity, %w{<mole>}, %w{<second>}],
140
144
 
141
145
  #capacitance
142
- '<farad>' => [%w{F farad Farad}, 1, :capacitance, %w{<farad>}],
146
+ '<farad>' => [%w{F farad Farad}, 1, :capacitance, %w{<second> <second> <second> <second> <ampere> <ampere>}, %w{<kilogram> <meter> <meter>}],
143
147
 
144
148
  #charge
145
149
  '<coulomb>' => [%w{C coulomb Coulomb}, 1, :charge, %w{<ampere> <second>}],
data/ruby-units.gemspec CHANGED
@@ -4,13 +4,13 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{ruby-units}
8
- s.version = "1.3.1"
7
+ s.name = "ruby-units"
8
+ s.version = "1.3.2.a"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kevin Olbrich, Ph.D."]
12
- s.date = %q{2011-06-23}
13
- s.description = %q{Provides classes and methods to perform unit math and conversions}
12
+ s.date = "2011-10-17"
13
+ s.description = "Provides classes and methods to perform unit math and conversions"
14
14
  s.email = ["kevin.olbrich+ruby_units@gmail.com"]
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "RakeFile",
27
27
  "TODO",
28
28
  "VERSION",
29
+ "autotest/discover.rb",
29
30
  "lib/ruby-units.rb",
30
31
  "lib/ruby_units.rb",
31
32
  "lib/ruby_units/array.rb",
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
36
37
  "lib/ruby_units/numeric.rb",
37
38
  "lib/ruby_units/object.rb",
38
39
  "lib/ruby_units/string.rb",
40
+ "lib/ruby_units/string/extra.rb",
39
41
  "lib/ruby_units/time.rb",
40
42
  "lib/ruby_units/unit.rb",
41
43
  "lib/ruby_units/unit_definitions.rb",
@@ -47,6 +49,7 @@ Gem::Specification.new do |s|
47
49
  "spec/ruby-units/math_spec.rb",
48
50
  "spec/ruby-units/numeric_spec.rb",
49
51
  "spec/ruby-units/object_spec.rb",
52
+ "spec/ruby-units/string/extra_spec.rb",
50
53
  "spec/ruby-units/string_spec.rb",
51
54
  "spec/ruby-units/time_spec.rb",
52
55
  "spec/ruby-units/unit_spec.rb",
@@ -54,10 +57,11 @@ Gem::Specification.new do |s|
54
57
  "test/test_cache.rb",
55
58
  "test/test_ruby-units.rb"
56
59
  ]
57
- s.homepage = %q{https://github.com/olbrich/ruby-units}
60
+ s.homepage = "https://github.com/olbrich/ruby-units"
61
+ s.post_install_message = "====================\nDeprecation Warning\n====================\n\nSeveral convenience methods that ruby-units added to the string class have\nbeen deprecated in this release. These methods include String#to, String#from, String#ago, String#before and others.\nIf your code relies on these functions, they can be added back by adding this line to your code.\n\nrequire 'ruby-units/string/extras'\n# note that these methods do not play well with Rails, which is one of the reasons they are being removed.\n\nThe extra functions mostly work the same, but will no longer properly handle cases when they are called with strings..\n\n'min'.from(\"4-1-2011\") # => Exception\n\nPass in a Date, Time, or DateTime object to get the expected result.\n\nThey will probably go away completely in an upcoming release, so it would be a good idea to refactor your code\nto avoid using them. They will also throw deprecation warnings when they are used.\n"
58
62
  s.require_paths = ["lib"]
59
- s.rubygems_version = %q{1.7.2}
60
- s.summary = %q{A class that performs unit conversions and unit math}
63
+ s.rubygems_version = "1.8.10"
64
+ s.summary = "A class that performs unit conversions and unit math"
61
65
 
62
66
  if s.respond_to? :specification_version then
63
67
  s.specification_version = 3
@@ -67,17 +71,26 @@ Gem::Specification.new do |s|
67
71
  s.add_development_dependency(%q<rcov>, [">= 0"])
68
72
  s.add_development_dependency(%q<jeweler>, [">= 0"])
69
73
  s.add_development_dependency(%q<rspec>, ["~> 2.5"])
74
+ s.add_development_dependency(%q<autotest>, [">= 0"])
75
+ s.add_development_dependency(%q<autotest-growl>, [">= 0"])
76
+ s.add_development_dependency(%q<autotest-fsevent>, [">= 0"])
70
77
  else
71
78
  s.add_dependency(%q<bundler>, ["~> 1.0"])
72
79
  s.add_dependency(%q<rcov>, [">= 0"])
73
80
  s.add_dependency(%q<jeweler>, [">= 0"])
74
81
  s.add_dependency(%q<rspec>, ["~> 2.5"])
82
+ s.add_dependency(%q<autotest>, [">= 0"])
83
+ s.add_dependency(%q<autotest-growl>, [">= 0"])
84
+ s.add_dependency(%q<autotest-fsevent>, [">= 0"])
75
85
  end
76
86
  else
77
87
  s.add_dependency(%q<bundler>, ["~> 1.0"])
78
88
  s.add_dependency(%q<rcov>, [">= 0"])
79
89
  s.add_dependency(%q<jeweler>, [">= 0"])
80
90
  s.add_dependency(%q<rspec>, ["~> 2.5"])
91
+ s.add_dependency(%q<autotest>, [">= 0"])
92
+ s.add_dependency(%q<autotest-growl>, [">= 0"])
93
+ s.add_dependency(%q<autotest-fsevent>, [">= 0"])
81
94
  end
82
95
  end
83
96
 
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../../lib/ruby_units/string/extra'
3
+ describe String do
4
+ context "Time syntax sugar" do
5
+ before(:each) do
6
+ Time.stub(:now).and_return(Time.at(1303656390))
7
+ Date.stub(:today).and_return(Date.new(2011,4,1))
8
+ DateTime.stub(:now).and_return(DateTime.new(2011,4,1,0,0,0))
9
+ end
10
+
11
+ specify { "5 min".ago.should be_instance_of Time }
12
+
13
+ specify { "5 min".from(Time.now).should be_instance_of Time }
14
+ specify { "5 min".from_now.should be_instance_of Time }
15
+
16
+ specify { "5 min".after(Time.parse('12:00')).should be_instance_of Time }
17
+
18
+ specify { "5 min".before.should be_instance_of Time}
19
+ specify { "5 min".before(Time.now).should be_instance_of Time}
20
+ specify { "5 min".before_now.should be_instance_of Time}
21
+ specify { "5 min".before(Time.parse('12:00')).should be_instance_of Time}
22
+
23
+ specify { "min".since.should be_instance_of Unit}
24
+ specify { "min".since(Time.parse("12:00")).should be_instance_of Unit}
25
+ specify { "min".since(Time.now - 60).should == Unit("1 min")}
26
+ specify { "days".since(Date.today - 3).should == Unit("3 d")}
27
+ specify { expect {"days".since(1000) }.to raise_error(ArgumentError, "Must specify a Time, Date, or DateTime")}
28
+
29
+ specify { "min".until.should be_instance_of Unit}
30
+ specify { "min".until(Time.parse("12:00")).should be_instance_of Unit}
31
+ specify { "min".until(Time.now + 60).should == Unit("1 min")}
32
+ specify { "days".until(Date.today + 3).should == Unit("3 d")}
33
+ specify { expect {"days".until(1000) }.to raise_error(ArgumentError, "Must specify a Time, Date, or DateTime")}
34
+
35
+ specify { "today".to_date.should be_instance_of Date }
36
+ specify { "2011-4-1".to_date.should be_instance_of Date }
37
+
38
+ specify { "now".to_datetime.should be_instance_of DateTime }
39
+ specify { "now".to_time.should be_instance_of Time }
40
+
41
+ specify { "10001-01-01 12:00".to_time.should be_instance_of Time }
42
+ specify { "2001-01-01 12:00".to_time.should be_instance_of Time }
43
+
44
+ end
45
+ end