timeliness 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ = 0.3.7 - 2012-10-03
2
+ * Change to a hot switch between US and Euro formats without a compile.
3
+ * Fix date parsing with bad month name defaulting to 1 if year and day present.
4
+ * Fix date parsing with nil month.
5
+
1
6
  = 0.3.6 - 2012-03-29
2
7
  * Fix bug with month_index using Integer method and leading zeroes treated as octal.
3
8
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require 'rake/rdoctask'
4
+ require 'rdoc/task'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
7
  desc "Run specs"
@@ -24,20 +24,11 @@ module Timeliness
24
24
  # - :current
25
25
  # - 'Zone name'
26
26
  #
27
- @default_timezone = :local
27
+ self.default_timezone = :local
28
28
 
29
29
  # Set the default date part for a time type values.
30
- @date_for_time_type = lambda { Time.now }
31
-
32
- def self.date_for_time_type
33
- case @date_for_time_type
34
- when Array
35
- @date_for_time_type
36
- when Proc
37
- v = @date_for_time_type.call
38
- [v.year, v.month, v.day]
39
- end
40
- end
30
+ #
31
+ self.date_for_time_type = lambda { Time.now }
41
32
 
42
33
  # Set the threshold value for a two digit year to be considered last century
43
34
  #
@@ -47,7 +38,7 @@ module Timeliness
47
38
  # year = '29' is considered 2029
48
39
  # year = '30' is considered 1930
49
40
  #
50
- @ambiguous_year_threshold = 30
41
+ self.ambiguous_year_threshold = 30
51
42
  end
52
43
 
53
44
  Timeliness::Definitions.compile_formats
@@ -130,6 +130,7 @@ module Timeliness
130
130
 
131
131
  # Mapping some common timezone abbreviations which are not mapped or
132
132
  # mapped inconsistenly in ActiveSupport (TzInfo).
133
+ #
133
134
  @timezone_mapping = {
134
135
  'AEST' => 'Australia/Sydney',
135
136
  'AEDT' => 'Australia/Sydney',
@@ -184,22 +185,28 @@ module Timeliness
184
185
  # Removes US date formats so that ambiguous dates are parsed as European format
185
186
  #
186
187
  def use_euro_formats
187
- @date_format_set = FormatSet.compile(date_formats.select { |format| US_FORMAT_REGEXP !~ format })
188
- @datetime_format_set = FormatSet.compile(datetime_formats.select { |format| US_FORMAT_REGEXP !~ format })
188
+ @date_format_set = @euro_date_format_set
189
+ @datetime_format_set = @euro_datetime_format_set
189
190
  end
190
191
 
191
192
  # Restores default to parse ambiguous dates as US format
192
193
  #
193
194
  def use_us_formats
194
- @date_format_set = FormatSet.compile(date_formats)
195
- @datetime_format_set = FormatSet.compile(datetime_formats)
195
+ @date_format_set = @us_date_format_set
196
+ @datetime_format_set = @us_datetime_format_set
196
197
  end
197
198
 
198
199
  def compile_formats
199
- @sorted_token_keys = nil
200
- @time_format_set = FormatSet.compile(time_formats)
201
- @date_format_set = FormatSet.compile(date_formats)
202
- @datetime_format_set = FormatSet.compile(datetime_formats)
200
+ @sorted_token_keys = nil
201
+ @time_format_set = FormatSet.compile(time_formats)
202
+
203
+ @us_date_format_set = FormatSet.compile(date_formats)
204
+ @us_datetime_format_set = FormatSet.compile(datetime_formats)
205
+ @euro_date_format_set = FormatSet.compile(date_formats.select { |format| US_FORMAT_REGEXP !~ format })
206
+ @euro_datetime_format_set = FormatSet.compile(datetime_formats.select { |format| US_FORMAT_REGEXP !~ format })
207
+
208
+ @date_format_set = @us_date_format_set
209
+ @datetime_format_set = @us_datetime_format_set
203
210
  end
204
211
 
205
212
  def sorted_token_keys
@@ -208,6 +215,7 @@ module Timeliness
208
215
 
209
216
  # Returns format for type and other possible matching format set based on type
210
217
  # and value length. Gives minor speed-up by checking string length.
218
+ #
211
219
  def format_sets(type, string)
212
220
  case type
213
221
  when :date
@@ -41,7 +41,7 @@ module Timeliness
41
41
  end
42
42
 
43
43
  def single_format(format_string)
44
- @formats_hash[format_string] || Format.new(format_string).compile!
44
+ @formats_hash.fetch(format_string) { Format.new(format_string).compile! }
45
45
  end
46
46
  end
47
47
  end
@@ -67,7 +67,7 @@ module Timeliness
67
67
  when nil
68
68
  dummy_date = current_date(options)
69
69
  values[0] ||= dummy_date[0]
70
- values[1] ||= dummy_date[1]
70
+ values[1] ||= dummy_date[1] unless values.values_at(0,2).all?
71
71
  values[2] ||= dummy_date[2]
72
72
  end
73
73
  end
@@ -78,7 +78,7 @@ module Timeliness
78
78
  elsif options[:zone]
79
79
  current_time_in_zone(options[:zone])
80
80
  else
81
- Timeliness.date_for_time_type
81
+ evaluate_date_for_time_type
82
82
  end
83
83
  now.is_a?(Array) ? now[0..2] : [now.year, now.month, now.day]
84
84
  end
@@ -139,7 +139,17 @@ module Timeliness
139
139
  # Enforce strict date part validity which the Time class does not.
140
140
  # Only does full date check if month and day are possibly invalid.
141
141
  def fast_date_valid_with_fallback(year, month, day)
142
- month < 13 && (day < 29 || Date.valid_civil?(year, month, day))
142
+ month && month < 13 && (day < 29 || Date.valid_civil?(year, month, day))
143
+ end
144
+
145
+ def evaluate_date_for_time_type
146
+ case Timeliness.date_for_time_type
147
+ when Array
148
+ Timeliness.date_for_time_type
149
+ when Proc
150
+ v = Timeliness.date_for_time_type.call
151
+ [v.year, v.month, v.day]
152
+ end
143
153
  end
144
154
 
145
155
  end
@@ -1,3 +1,3 @@
1
1
  module Timeliness
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  end
@@ -5,29 +5,29 @@ describe Timeliness::CoreExt, 'String' do
5
5
 
6
6
  describe "#to_time" do
7
7
  it 'should convert valid string to Time object in default zone' do
8
- "2005-02-27 23:50".to_time.should == Time.utc(2005, 2, 27, 23, 50)
8
+ "2005-02-27 23:50".to_time.should eq Time.utc(2005, 2, 27, 23, 50)
9
9
  end
10
10
 
11
11
  it 'should convert ISO 8601 string to Time object' do
12
- "2005-02-27T23:50:19.275038".to_time.should == Time.utc(2005, 2, 27, 23, 50, 19, 275038)
12
+ "2005-02-27T23:50:19.275038".to_time.should eq Time.utc(2005, 2, 27, 23, 50, 19, 275038)
13
13
  end
14
14
 
15
15
  context "with :local" do
16
16
  it 'should convert valid string to local time' do
17
- "2005-02-27 23:50".to_time(:local).should == Time.local(2005, 2, 27, 23, 50)
17
+ "2005-02-27 23:50".to_time(:local).should eq Time.local(2005, 2, 27, 23, 50)
18
18
  end
19
19
 
20
20
  it 'should convert ISO 8601 string to local time' do
21
- "2005-02-27T23:50:19.275038".to_time(:local).should == Time.local(2005, 2, 27, 23, 50, 19, 275038)
21
+ "2005-02-27T23:50:19.275038".to_time(:local).should eq Time.local(2005, 2, 27, 23, 50, 19, 275038)
22
22
  end
23
23
  end
24
24
 
25
25
  it 'should convert valid future string to Time object' do
26
- "2039-02-27 23:50".to_time(:local).should == Time.local_time(2039, 2, 27, 23, 50)
26
+ "2039-02-27 23:50".to_time(:local).should eq Time.local_time(2039, 2, 27, 23, 50)
27
27
  end
28
28
 
29
29
  it 'should convert valid future string to Time object' do
30
- "2039-02-27 23:50".to_time.should == DateTime.civil(2039, 2, 27, 23, 50)
30
+ "2039-02-27 23:50".to_time.should eq DateTime.civil(2039, 2, 27, 23, 50)
31
31
  end
32
32
 
33
33
  it 'should convert empty string to nil' do
@@ -37,21 +37,21 @@ describe Timeliness::CoreExt, 'String' do
37
37
 
38
38
  describe "#to_datetime" do
39
39
  it 'should convert valid string to DateTime object' do
40
- "2039-02-27 23:50".to_datetime.should == DateTime.civil(2039, 2, 27, 23, 50)
40
+ "2039-02-27 23:50".to_datetime.should eq DateTime.civil(2039, 2, 27, 23, 50)
41
41
  end
42
42
 
43
43
  it 'should convert to DateTime object with UTC offset' do
44
- "2039-02-27 23:50".to_datetime.offset.should == 0
44
+ "2039-02-27 23:50".to_datetime.offset.should eq 0
45
45
  end
46
46
 
47
47
  it 'should convert ISO 8601 string to DateTime object' do
48
48
  datetime = DateTime.civil(2039, 2, 27, 23, 50, 19 + Rational(275038, 1000000), "-04:00")
49
- "2039-02-27T23:50:19.275038-04:00".to_datetime.should == datetime
49
+ "2039-02-27T23:50:19.275038-04:00".to_datetime.should eq datetime
50
50
  end
51
51
 
52
52
  it 'should use Rubys default start value' do
53
53
  # Taken from ActiveSupport unit tests. Not sure on the implication.
54
- "2039-02-27 23:50".to_datetime.start.should == ::Date::ITALY
54
+ "2039-02-27 23:50".to_datetime.start.should eq ::Date::ITALY
55
55
  end
56
56
 
57
57
  it 'should convert empty string to nil' do
@@ -61,7 +61,7 @@ describe Timeliness::CoreExt, 'String' do
61
61
 
62
62
  describe "#to_date" do
63
63
  it 'should convert string to Date object' do
64
- "2005-02-27".to_date.should == Date.new(2005, 2, 27)
64
+ "2005-02-27".to_date.should eq Date.new(2005, 2, 27)
65
65
  end
66
66
 
67
67
  it 'should convert empty string to nil' do
@@ -19,18 +19,18 @@ describe Timeliness::Definitions do
19
19
  end
20
20
 
21
21
  it "should raise error if format exists" do
22
- expect { definitions.add_formats(:time, "hh:nn:ss") }.should raise_error
22
+ expect { definitions.add_formats(:time, "hh:nn:ss") }.to raise_error
23
23
  end
24
24
 
25
25
  context "with :before option" do
26
26
  it "should add new format with higher precedence" do
27
27
  definitions.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
28
28
  time_array = parser._parse('59:23:58', :time)
29
- time_array.should == [nil,nil,nil,23,58,59,nil,nil]
29
+ time_array.should eq [nil,nil,nil,23,58,59,nil,nil]
30
30
  end
31
31
 
32
32
  it "should raise error if :before format does not exist" do
33
- expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.should raise_error
33
+ expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.to raise_error
34
34
  end
35
35
  end
36
36
 
@@ -63,7 +63,7 @@ describe Timeliness::Definitions do
63
63
  end
64
64
 
65
65
  it "should raise error if format does not exist" do
66
- expect { definitions.remove_formats(:time, "ss:hh:nn") }.should raise_error()
66
+ expect { definitions.remove_formats(:time, "ss:hh:nn") }.to raise_error()
67
67
  end
68
68
 
69
69
  after do
@@ -74,21 +74,33 @@ describe Timeliness::Definitions do
74
74
 
75
75
  context "use_euro_formats" do
76
76
  it "should allow ambiguous date to be parsed as European format" do
77
- parser._parse('01/02/2000', :date).should == [2000,1,2,nil,nil,nil,nil,nil]
77
+ parser._parse('01/02/2000', :date).should eq [2000,1,2,nil,nil,nil,nil,nil]
78
+ definitions.use_euro_formats
79
+ parser._parse('01/02/2000', :date).should eq [2000,2,1,nil,nil,nil,nil,nil]
80
+ end
81
+
82
+ it "should not parse formats on switch to euro after initial compile" do
83
+ definitions.compile_formats
84
+ Timeliness::FormatSet.should_not_receive(:compile)
78
85
  definitions.use_euro_formats
79
- parser._parse('01/02/2000', :date).should == [2000,2,1,nil,nil,nil,nil,nil]
80
86
  end
81
87
  end
82
88
 
83
- context "use_use_formats" do
89
+ context "use_us_formats" do
84
90
  before do
85
91
  definitions.use_euro_formats
86
92
  end
87
93
 
88
94
  it "should allow ambiguous date to be parsed as European format" do
89
- parser._parse('01/02/2000', :date).should == [2000,2,1,nil,nil,nil,nil,nil]
95
+ parser._parse('01/02/2000', :date).should eq [2000,2,1,nil,nil,nil,nil,nil]
96
+ definitions.use_us_formats
97
+ parser._parse('01/02/2000', :date).should eq [2000,1,2,nil,nil,nil,nil,nil]
98
+ end
99
+
100
+ it "should not parse formats on switch to euro after initial compile" do
101
+ definitions.compile_formats
102
+ Timeliness::FormatSet.should_not_receive(:compile)
90
103
  definitions.use_us_formats
91
- parser._parse('01/02/2000', :date).should == [2000,1,2,nil,nil,nil,nil,nil]
92
104
  end
93
105
  end
94
106
  end
@@ -5,60 +5,60 @@ describe Timeliness::Format do
5
5
  it 'should compile valid string format' do
6
6
  expect {
7
7
  Timeliness::Format.new('yyyy-mm-dd hh:nn:ss.u zo').compile!
8
- }.should_not raise_error
8
+ }.to_not raise_error
9
9
  end
10
10
 
11
11
  it 'should return self' do
12
12
  format = Timeliness::Format.new('yyyy-mm-dd hh:nn:ss.u zo')
13
- format.compile!.should == format
13
+ format.compile!.should eq format
14
14
  end
15
15
 
16
16
  it 'should raise compilation error for bad format' do
17
17
  expect {
18
18
  Timeliness::Format.new('|--[)').compile!
19
- }.should raise_error(Timeliness::CompilationError)
19
+ }.to raise_error(Timeliness::CompilationError)
20
20
  end
21
21
  end
22
22
 
23
23
  describe "#process" do
24
24
  it "should define method which outputs date array with values in correct order" do
25
- format_for('yyyy-mm-dd').process('2000', '1', '2').should == [2000,1,2,nil,nil,nil,nil,nil]
25
+ format_for('yyyy-mm-dd').process('2000', '1', '2').should eq [2000,1,2,nil,nil,nil,nil,nil]
26
26
  end
27
27
 
28
28
  it "should define method which outputs date array from format with different order" do
29
- format_for('dd/mm/yyyy').process('2', '1', '2000').should == [2000,1,2,nil,nil,nil,nil,nil]
29
+ format_for('dd/mm/yyyy').process('2', '1', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
30
30
  end
31
31
 
32
32
  it "should define method which outputs date array with zeros when month and day are '0'" do
33
- format_for('m/d/yy').process('0', '0', '0000').should == [0,0,0,nil,nil,nil,nil,nil]
33
+ format_for('m/d/yy').process('0', '0', '0000').should eq [0,0,0,nil,nil,nil,nil,nil]
34
34
  end
35
35
 
36
36
  it "should define method which outputs date array with zeros when month and day are '00'" do
37
- format_for('m/d/yy').process('00', '00', '0000').should == [0,0,0,nil,nil,nil,nil,nil]
37
+ format_for('m/d/yy').process('00', '00', '0000').should eq [0,0,0,nil,nil,nil,nil,nil]
38
38
  end
39
39
 
40
40
  it "should define method which outputs time array" do
41
- format_for('hh:nn:ss').process('01', '02', '03').should == [nil,nil,nil,1,2,3,nil,nil]
41
+ format_for('hh:nn:ss').process('01', '02', '03').should eq [nil,nil,nil,1,2,3,nil,nil]
42
42
  end
43
43
 
44
44
  it "should define method which outputs time array with meridian 'pm' adjusted hour" do
45
- format_for('hh:nn:ss ampm').process('01', '02', '03', 'pm').should == [nil,nil,nil,13,2,3,nil,nil]
45
+ format_for('hh:nn:ss ampm').process('01', '02', '03', 'pm').should eq [nil,nil,nil,13,2,3,nil,nil]
46
46
  end
47
47
 
48
48
  it "should define method which outputs time array with meridian 'am' unadjusted hour" do
49
- format_for('hh:nn:ss ampm').process('01', '02', '03', 'am').should == [nil,nil,nil,1,2,3,nil,nil]
49
+ format_for('hh:nn:ss ampm').process('01', '02', '03', 'am').should eq [nil,nil,nil,1,2,3,nil,nil]
50
50
  end
51
51
 
52
52
  it "should define method which outputs time array with microseconds" do
53
- format_for('hh:nn:ss.u').process('01', '02', '03', '99').should == [nil,nil,nil,1,2,3,990000,nil]
53
+ format_for('hh:nn:ss.u').process('01', '02', '03', '99').should eq [nil,nil,nil,1,2,3,990000,nil]
54
54
  end
55
55
 
56
56
  it "should define method which outputs datetime array with zone offset" do
57
- format_for('yyyy-mm-dd hh:nn:ss.u zo').process('2001', '02', '03', '04', '05', '06', '99', '+10:00').should == [2001,2,3,4,5,6,990000,36000]
57
+ format_for('yyyy-mm-dd hh:nn:ss.u zo').process('2001', '02', '03', '04', '05', '06', '99', '+10:00').should eq [2001,2,3,4,5,6,990000,36000]
58
58
  end
59
59
 
60
60
  it "should define method which outputs datetime array with timezone string" do
61
- format_for('yyyy-mm-dd hh:nn:ss.u tz').process('2001', '02', '03', '04', '05', '06', '99', 'EST').should == [2001,2,3,4,5,6,990000,'EST']
61
+ format_for('yyyy-mm-dd hh:nn:ss.u tz').process('2001', '02', '03', '04', '05', '06', '99', 'EST').should eq [2001,2,3,4,5,6,990000,'EST']
62
62
  end
63
63
 
64
64
  context "with long month" do
@@ -72,11 +72,11 @@ describe Timeliness::Format do
72
72
  end
73
73
 
74
74
  it 'should parse abbreviated month for current locale to correct value' do
75
- format.process('2', 'Ene', '2000').should == [2000,1,2,nil,nil,nil,nil,nil]
75
+ format.process('2', 'Ene', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
76
76
  end
77
77
 
78
78
  it 'should parse full month for current locale to correct value' do
79
- format.process('2', 'Enero', '2000').should == [2000,1,2,nil,nil,nil,nil,nil]
79
+ format.process('2', 'Enero', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
80
80
  end
81
81
 
82
82
  after(:all) do
@@ -91,11 +91,11 @@ describe Timeliness::Format do
91
91
  end
92
92
 
93
93
  it 'should parse abbreviated month to correct value' do
94
- format.process('2', 'Jan', '2000').should == [2000,1,2,nil,nil,nil,nil,nil]
94
+ format.process('2', 'Jan', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
95
95
  end
96
96
 
97
97
  it 'should parse full month to correct value' do
98
- format.process('2', 'January', '2000').should == [2000,1,2,nil,nil,nil,nil,nil]
98
+ format.process('2', 'January', '2000').should eq [2000,1,2,nil,nil,nil,nil,nil]
99
99
  end
100
100
  end
101
101
  end
@@ -20,7 +20,7 @@ describe Timeliness::Parser do
20
20
 
21
21
  it "should return return same value if value not a string" do
22
22
  value = Time.now
23
- parse(value).should == value
23
+ parse(value).should eq value
24
24
  end
25
25
 
26
26
  it "should return time object for valid date string" do
@@ -39,6 +39,10 @@ describe Timeliness::Parser do
39
39
  should_not_parse("00/01/2000")
40
40
  end
41
41
 
42
+ it "should return nil for invalid date month string" do
43
+ should_not_parse("1 Foo 2000")
44
+ end
45
+
42
46
  it "should return time object for valid time string" do
43
47
  parse("12:13:14").should be_kind_of(Time)
44
48
  end
@@ -59,14 +63,14 @@ describe Timeliness::Parser do
59
63
  context "when current timezone is earler than string zone" do
60
64
  it 'should return value shifted by positive offset in default timezone' do
61
65
  value = parse("2000-06-01T12:00:00+02:00")
62
- value.should == Time.local(2000,6,1,20,0,0)
63
- value.utc_offset.should == 10.hours
66
+ value.should eq Time.local(2000,6,1,20,0,0)
67
+ value.utc_offset.should eq 10.hours
64
68
  end
65
69
 
66
70
  it 'should return value shifted by negative offset in default timezone' do
67
71
  value = parse("2000-06-01T12:00:00-01:00")
68
- value.should == Time.local(2000,6,1,23,0,0)
69
- value.utc_offset.should == 10.hours
72
+ value.should eq Time.local(2000,6,1,23,0,0)
73
+ value.utc_offset.should eq 10.hours
70
74
  end
71
75
  end
72
76
 
@@ -78,14 +82,14 @@ describe Timeliness::Parser do
78
82
 
79
83
  it 'should return value shifted by positive offset in default timezone' do
80
84
  value = parse("2000-06-01T12:00:00+02:00")
81
- value.should == Time.zone.local(2000,6,1,3,0,0)
82
- value.utc_offset.should == -7.hours
85
+ value.should eq Time.zone.local(2000,6,1,3,0,0)
86
+ value.utc_offset.should eq -7.hours
83
87
  end
84
88
 
85
89
  it 'should return value shifted by negative offset in default timezone' do
86
90
  value = parse("2000-06-01T12:00:00-01:00")
87
- value.should == Time.zone.local(2000,6,1,6,0,0)
88
- value.utc_offset.should == -7.hours
91
+ value.should eq Time.zone.local(2000,6,1,6,0,0)
92
+ value.utc_offset.should eq -7.hours
89
93
  end
90
94
 
91
95
  after(:all) do
@@ -103,23 +107,23 @@ describe Timeliness::Parser do
103
107
  it 'should return value using string zone adjusted to default :local timezone' do
104
108
  Timeliness.default_timezone = :local
105
109
  value = parse("Thu, 01 Jun 2000 03:00:00 MST")
106
- value.should == Time.local(2000,6,1,20,0,0)
107
- value.utc_offset.should == 10.hours
110
+ value.should eq Time.local(2000,6,1,20,0,0)
111
+ value.utc_offset.should eq 10.hours
108
112
  end
109
113
 
110
114
  it 'should return value using string zone adjusted to default :current timezone' do
111
115
  Timeliness.default_timezone = :current
112
116
  Time.zone = 'Adelaide'
113
117
  value = parse("Thu, 01 Jun 2000 03:00:00 MST")
114
- value.should == Time.zone.local(2000,6,1,19,30,0)
115
- value.utc_offset.should == 9.5.hours
118
+ value.should eq Time.zone.local(2000,6,1,19,30,0)
119
+ value.utc_offset.should eq 9.5.hours
116
120
  end
117
121
 
118
122
  it 'should return value using string zone adjusted to :zone option string timezone' do
119
123
  Timeliness.default_timezone = :local
120
124
  value = parse("Thu, 01 Jun 2000 03:00:00 MST", :zone => 'Perth')
121
- value.should == Time.use_zone('Perth') { Time.zone.local(2000,6,1,18,0,0) }
122
- value.utc_offset.should == 8.hours
125
+ value.should eq Time.use_zone('Perth') { Time.zone.local(2000,6,1,18,0,0) }
126
+ value.utc_offset.should eq 8.hours
123
127
  end
124
128
 
125
129
  after do
@@ -129,7 +133,7 @@ describe Timeliness::Parser do
129
133
 
130
134
  context "with :datetime type" do
131
135
  it "should return time object for valid datetime string" do
132
- parse("2000-01-01 12:13:14", :datetime).should == Time.local(2000,1,1,12,13,14)
136
+ parse("2000-01-01 12:13:14", :datetime).should eq Time.local(2000,1,1,12,13,14)
133
137
  end
134
138
 
135
139
  it "should return nil for invalid date string" do
@@ -139,11 +143,11 @@ describe Timeliness::Parser do
139
143
 
140
144
  context "with :date type" do
141
145
  it "should return time object for valid date string" do
142
- parse("2000-01-01", :date).should == Time.local(2000,1,1)
146
+ parse("2000-01-01", :date).should eq Time.local(2000,1,1)
143
147
  end
144
148
 
145
149
  it "should ignore time in datetime string" do
146
- parse('2000-02-01 12:13', :date).should == Time.local(2000,2,1)
150
+ parse('2000-02-01 12:13', :date).should eq Time.local(2000,2,1)
147
151
  end
148
152
 
149
153
  it "should return nil for invalid date string" do
@@ -153,11 +157,11 @@ describe Timeliness::Parser do
153
157
 
154
158
  context "with :time type" do
155
159
  it "should return time object with a dummy date values" do
156
- parse('12:13', :time).should == Time.local(2010,1,1,12,13)
160
+ parse('12:13', :time).should eq Time.local(2010,1,1,12,13)
157
161
  end
158
162
 
159
163
  it "should ignore date in datetime string" do
160
- parse('2010-02-01 12:13', :time).should == Time.local(2010,1,1,12,13)
164
+ parse('2010-02-01 12:13', :time).should eq Time.local(2010,1,1,12,13)
161
165
  end
162
166
 
163
167
  it "should raise error if time hour is out of range for AM meridian" do
@@ -168,14 +172,14 @@ describe Timeliness::Parser do
168
172
  context "with :now option" do
169
173
  it 'should use date parts if string does not specify' do
170
174
  time = parse("12:13:14", :now => Time.local(2010,1,1))
171
- time.should == Time.local(2010,1,1,12,13,14)
175
+ time.should eq Time.local(2010,1,1,12,13,14)
172
176
  end
173
177
  end
174
178
 
175
179
  context "with time value argument" do
176
180
  it 'should use argument as :now option value' do
177
181
  time = parse("12:13:14", Time.local(2010,1,1))
178
- time.should == Time.local(2010,1,1,12,13,14)
182
+ time.should eq Time.local(2010,1,1,12,13,14)
179
183
  end
180
184
  end
181
185
 
@@ -183,7 +187,7 @@ describe Timeliness::Parser do
183
187
  context ":utc" do
184
188
  it "should return time object in utc timezone" do
185
189
  time = parse("2000-06-01 12:13:14", :datetime, :zone => :utc)
186
- time.utc_offset.should == 0
190
+ time.utc_offset.should eq 0
187
191
  end
188
192
 
189
193
  it 'should return nil for partial invalid time component' do
@@ -194,7 +198,7 @@ describe Timeliness::Parser do
194
198
  context ":local" do
195
199
  it "should return time object in local system timezone" do
196
200
  time = parse("2000-06-01 12:13:14", :datetime, :zone => :local)
197
- time.utc_offset.should == 10.hours
201
+ time.utc_offset.should eq 10.hours
198
202
  end
199
203
 
200
204
  it 'should return nil for partial invalid time component' do
@@ -206,7 +210,7 @@ describe Timeliness::Parser do
206
210
  it "should return time object in current timezone" do
207
211
  Time.zone = 'Adelaide'
208
212
  time = parse("2000-06-01 12:13:14", :datetime, :zone => :current)
209
- time.utc_offset.should == 9.5.hours
213
+ time.utc_offset.should eq 9.5.hours
210
214
  end
211
215
 
212
216
  it 'should return nil for partial invalid time component' do
@@ -217,7 +221,7 @@ describe Timeliness::Parser do
217
221
  context "named zone" do
218
222
  it "should return time object in the timezone" do
219
223
  time = parse("2000-06-01 12:13:14", :datetime, :zone => 'London')
220
- time.utc_offset.should == 1.hour
224
+ time.utc_offset.should eq 1.hour
221
225
  end
222
226
 
223
227
  it 'should return nil for partial invalid time component' do
@@ -230,17 +234,17 @@ describe Timeliness::Parser do
230
234
  expect {
231
235
  Time.should_receive(:zone).and_raise(NoMethodError.new("undefined method `zone' for Time:Class"))
232
236
  parse("2000-06-01 12:13:14", :zone => :current)
233
- }.should raise_error(Timeliness::Parser::MissingTimezoneSupport)
237
+ }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
234
238
 
235
239
  expect {
236
240
  Time.should_receive(:current).and_raise(NoMethodError.new("undefined method `current' for Time:Class"))
237
241
  parse("12:13:14", :zone => :current)
238
- }.should raise_error(Timeliness::Parser::MissingTimezoneSupport)
242
+ }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
239
243
 
240
244
  expect {
241
245
  Time.should_receive(:use_zone).and_raise(NoMethodError.new("undefined method `use_zone' for Time:Class"))
242
246
  parse("2000-06-01 12:13:14", :zone => 'London')
243
- }.should raise_error(Timeliness::Parser::MissingTimezoneSupport)
247
+ }.to raise_error(Timeliness::Parser::MissingTimezoneSupport)
244
248
  end
245
249
  end
246
250
  end
@@ -253,12 +257,12 @@ describe Timeliness::Parser do
253
257
 
254
258
  it 'should return date array' do
255
259
  Timeliness.date_for_time_type = [2010,1,1]
256
- parse('12:13:14', :time).should == Time.local(2010,1,1,12,13,14)
260
+ parse('12:13:14', :time).should eq Time.local(2010,1,1,12,13,14)
257
261
  end
258
262
 
259
263
  it 'should return date array evaluated lambda' do
260
264
  Timeliness.date_for_time_type = lambda { Time.local(2010,2,1) }
261
- parse('12:13:14', :time).should == Time.local(2010,2,1,12,13,14)
265
+ parse('12:13:14', :time).should eq Time.local(2010,2,1,12,13,14)
262
266
  end
263
267
 
264
268
  after do
@@ -268,16 +272,16 @@ describe Timeliness::Parser do
268
272
 
269
273
  context "with :now option" do
270
274
  it 'should use date from :now' do
271
- parse('12:13:14', :time, :now => Time.local(2010, 6, 1)).should == Time.local(2010,6,1,12,13,14)
275
+ parse('12:13:14', :time, :now => Time.local(2010, 6, 1)).should eq Time.local(2010,6,1,12,13,14)
272
276
  end
273
277
  end
274
278
 
275
279
  context "with :zone option" do
276
280
  it "should use date from the specified zone" do
277
281
  time = parse("12:13:14", :time, :zone => :utc)
278
- time.year.should == 2009
279
- time.month.should == 12
280
- time.day.should == 31
282
+ time.year.should eq 2009
283
+ time.month.should eq 12
284
+ time.day.should eq 31
281
285
  end
282
286
  end
283
287
 
@@ -288,54 +292,54 @@ describe Timeliness::Parser do
288
292
  context "with no type" do
289
293
  it "should return date array from date string" do
290
294
  time_array = parser._parse('2000-02-01')
291
- time_array.should == [2000,2,1,nil,nil,nil,nil,nil]
295
+ time_array.should eq [2000,2,1,nil,nil,nil,nil,nil]
292
296
  end
293
297
 
294
298
  it "should return time array from time string" do
295
299
  time_array = parser._parse('12:13:14', :time)
296
- time_array.should == [nil,nil,nil,12,13,14,nil,nil]
300
+ time_array.should eq [nil,nil,nil,12,13,14,nil,nil]
297
301
  end
298
302
 
299
303
  it "should return datetime array from datetime string" do
300
304
  time_array = parser._parse('2000-02-01 12:13:14')
301
- time_array.should == [2000,2,1,12,13,14,nil,nil]
305
+ time_array.should eq [2000,2,1,12,13,14,nil,nil]
302
306
  end
303
307
  end
304
308
 
305
309
  context "with type" do
306
310
  it "should return date array from date string" do
307
311
  time_array = parser._parse('2000-02-01', :date)
308
- time_array.should == [2000,2,1,nil,nil,nil,nil,nil]
312
+ time_array.should eq [2000,2,1,nil,nil,nil,nil,nil]
309
313
  end
310
314
 
311
315
  it "should not return time array from time string for :date type" do
312
316
  time_array = parser._parse('12:13:14', :date)
313
- time_array.should == nil
317
+ time_array.should eq nil
314
318
  end
315
319
 
316
320
  it "should return time array from time string" do
317
321
  time_array = parser._parse('12:13:14', :time)
318
- time_array.should == [nil,nil,nil,12,13,14,nil,nil]
322
+ time_array.should eq [nil,nil,nil,12,13,14,nil,nil]
319
323
  end
320
324
 
321
325
  it "should not return date array from date string for :time type" do
322
326
  time_array = parser._parse('2000-02-01', :time)
323
- time_array.should == nil
327
+ time_array.should eq nil
324
328
  end
325
329
 
326
330
  it "should return datetime array from datetime string when type is date" do
327
331
  time_array = parser._parse('2000-02-01 12:13:14', :date)
328
- time_array.should == [2000,2,1,12,13,14,nil,nil]
332
+ time_array.should eq [2000,2,1,12,13,14,nil,nil]
329
333
  end
330
334
 
331
335
  it "should return date array from date string when type is datetime" do
332
336
  time_array = parser._parse('2000-02-01', :datetime)
333
- time_array.should == [2000,2,1,nil,nil,nil,nil,nil]
337
+ time_array.should eq [2000,2,1,nil,nil,nil,nil,nil]
334
338
  end
335
339
 
336
340
  it "should not return time array from time string when type is datetime" do
337
341
  time_array = parser._parse('12:13:14', :datetime)
338
- time_array.should == nil
342
+ time_array.should eq nil
339
343
  end
340
344
  end
341
345
 
@@ -379,7 +383,7 @@ describe Timeliness::Parser do
379
383
  context "with :format option" do
380
384
  it "should return values if string matches specified format" do
381
385
  time_array = parser._parse('2000-02-01 12:13:14', :datetime, :format => 'yyyy-mm-dd hh:nn:ss')
382
- time_array.should == [2000,2,1,12,13,14,nil,nil]
386
+ time_array.should eq [2000,2,1,12,13,14,nil,nil]
383
387
  end
384
388
 
385
389
  it "should return nil if string does not match specified format" do
@@ -391,21 +395,21 @@ describe Timeliness::Parser do
391
395
  context "date with ambiguous year" do
392
396
  it "should return year in current century if year below threshold" do
393
397
  time_array = parser._parse('01-02-29', :date)
394
- time_array.should == [2029,2,1,nil,nil,nil,nil,nil]
398
+ time_array.should eq [2029,2,1,nil,nil,nil,nil,nil]
395
399
  end
396
400
 
397
401
  it "should return year in last century if year at or above threshold" do
398
402
  time_array = parser._parse('01-02-30', :date)
399
- time_array.should == [1930,2,1,nil,nil,nil,nil,nil]
403
+ time_array.should eq [1930,2,1,nil,nil,nil,nil,nil]
400
404
  end
401
405
 
402
406
  it "should allow custom threshold" do
403
407
  default = Timeliness.ambiguous_year_threshold
404
408
  Timeliness.ambiguous_year_threshold = 40
405
409
  time_array = parser._parse('01-02-39', :date)
406
- time_array.should == [2039,2,1,nil,nil,nil,nil,nil]
410
+ time_array.should eq [2039,2,1,nil,nil,nil,nil,nil]
407
411
  time_array = parser._parse('01-02-40', :date)
408
- time_array.should == [1940,2,1,nil,nil,nil,nil,nil]
412
+ time_array.should eq [1940,2,1,nil,nil,nil,nil,nil]
409
413
  Timeliness.ambiguous_year_threshold = default
410
414
  end
411
415
  end
@@ -414,7 +418,7 @@ describe Timeliness::Parser do
414
418
  describe "make_time" do
415
419
  it "should return time object for valid time array" do
416
420
  time = parser.make_time([2010,9,8,12,13,14])
417
- time.should == Time.local(2010,9,8,12,13,14)
421
+ time.should eq Time.local(2010,9,8,12,13,14)
418
422
  end
419
423
 
420
424
  it "should return nil for invalid date in array" do
@@ -435,7 +439,7 @@ describe Timeliness::Parser do
435
439
  it "should be used if no zone value" do
436
440
  Timeliness.default_timezone = :utc
437
441
  time = parser.make_time([2000,6,1,12,0,0])
438
- time.utc_offset.should == 0
442
+ time.utc_offset.should eq 0
439
443
  end
440
444
 
441
445
  after do
@@ -447,14 +451,14 @@ describe Timeliness::Parser do
447
451
  context ":utc" do
448
452
  it "should return time object in utc timezone" do
449
453
  time = parser.make_time([2000,6,1,12,0,0], :utc)
450
- time.utc_offset.should == 0
454
+ time.utc_offset.should eq 0
451
455
  end
452
456
  end
453
457
 
454
458
  context ":local" do
455
459
  it "should return time object in local system timezone" do
456
460
  time = parser.make_time([2000,6,1,12,0,0], :local)
457
- time.utc_offset.should == 10.hours
461
+ time.utc_offset.should eq 10.hours
458
462
  end
459
463
  end
460
464
 
@@ -462,14 +466,14 @@ describe Timeliness::Parser do
462
466
  it "should return time object in current timezone" do
463
467
  Time.zone = 'Adelaide'
464
468
  time = parser.make_time([2000,6,1,12,0,0], :current)
465
- time.utc_offset.should == 9.5.hours
469
+ time.utc_offset.should eq 9.5.hours
466
470
  end
467
471
  end
468
472
 
469
473
  context "named zone" do
470
474
  it "should return time object in the timezone" do
471
475
  time = parser.make_time([2000,6,1,12,0,0], 'London')
472
- time.utc_offset.should == 1.hour
476
+ time.utc_offset.should eq 1.hour
473
477
  end
474
478
  end
475
479
  end
@@ -479,7 +483,8 @@ describe Timeliness::Parser do
479
483
 
480
484
  context "with no options" do
481
485
  it 'should return date_for_time_type values with no options' do
482
- current_date.should == Timeliness.date_for_time_type
486
+ dummy_date = Timeliness.date_for_time_type.call
487
+ current_date.should eq [ dummy_date.year, dummy_date.month, dummy_date.day ]
483
488
  end
484
489
  end
485
490
 
@@ -487,7 +492,7 @@ describe Timeliness::Parser do
487
492
  it 'should return date array from Time value' do
488
493
  time = Time.now
489
494
  date_array = [time.year, time.month, time.day]
490
- current_date(:now => time).should == date_array
495
+ current_date(:now => time).should eq date_array
491
496
  end
492
497
  end
493
498
 
@@ -495,26 +500,26 @@ describe Timeliness::Parser do
495
500
  it 'should return date array for utc zone' do
496
501
  time = Time.now.getutc
497
502
  date_array = [time.year, time.month, time.day]
498
- current_date(:zone => :utc).should == date_array
503
+ current_date(:zone => :utc).should eq date_array
499
504
  end
500
505
 
501
506
  it 'should return date array for local zone' do
502
507
  time = Time.now
503
508
  date_array = [time.year, time.month, time.day]
504
- current_date(:zone => :local).should == date_array
509
+ current_date(:zone => :local).should eq date_array
505
510
  end
506
511
 
507
512
  it 'should return date array for current zone' do
508
513
  Time.zone = 'London'
509
514
  time = Time.current
510
515
  date_array = [time.year, time.month, time.day]
511
- current_date(:zone => :current).should == date_array
516
+ current_date(:zone => :current).should eq date_array
512
517
  end
513
518
 
514
519
  it 'should return date array for named zone' do
515
520
  time = Time.use_zone('London') { Time.current }
516
521
  date_array = [time.year, time.month, time.day]
517
- current_date(:zone => 'London').should == date_array
522
+ current_date(:zone => 'London').should eq date_array
518
523
  end
519
524
  end
520
525
  end
metadata CHANGED
@@ -1,34 +1,24 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: timeliness
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.7
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 6
10
- version: 0.3.6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Adam Meehan
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-01 01:00:00 +11:00
19
- default_executable:
12
+ date: 2012-10-03 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
14
  description: Fast date/time parser with customisable formats, timezone and I18n support.
23
15
  email: adam.meehan@gmail.com
24
16
  executables: []
25
-
26
17
  extensions: []
27
-
28
- extra_rdoc_files:
18
+ extra_rdoc_files:
29
19
  - README.rdoc
30
20
  - CHANGELOG.rdoc
31
- files:
21
+ files:
32
22
  - CHANGELOG.rdoc
33
23
  - LICENSE
34
24
  - README.rdoc
@@ -50,39 +40,28 @@ files:
50
40
  - spec/timeliness/format_spec.rb
51
41
  - spec/timeliness/parser_spec.rb
52
42
  - timeliness.gemspec
53
- has_rdoc: true
54
43
  homepage: http://github.com/adzap/timeliness
55
44
  licenses: []
56
-
57
45
  post_install_message:
58
46
  rdoc_options: []
59
-
60
- require_paths:
47
+ require_paths:
61
48
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
63
50
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
56
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
80
61
  requirements: []
81
-
82
62
  rubyforge_project: timeliness
83
- rubygems_version: 1.5.2
63
+ rubygems_version: 1.8.24
84
64
  signing_key:
85
65
  specification_version: 3
86
66
  summary: Date/time parsing for the control freak.
87
67
  test_files: []
88
-