date_time_precision 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 28cf9dcb22c71507eea053a3dc86447797156bb1
4
- data.tar.gz: f5c6c99396d465523361a2da976a545e0727eb79
5
- SHA512:
6
- metadata.gz: 9e03bcaca16094a878d0fac4a45b1b8d8c7d7e124360672b96a02ab73f58a4c5b236fa1ca959ac19f8ea042ef4fdb126593753a28b870f3b09267b0b7039b196
7
- data.tar.gz: 18e685aa7f91fb58b405f4905c5a4e4251ef4569edd343d6fd716dddbea53099bf70a1ce0fe896cfcfba68f0b7e79c4a4bb7ec9a77f8e87a9ace426c1323fbe0
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfd81b7cf64c7f1cde510e2b5a8224758bb9bdf7
4
+ data.tar.gz: bd625c14c4ba483ddf55210ebdc2785b0618c2fe
5
+ SHA512:
6
+ metadata.gz: 0447b421ed938b6d15662d9800f8475c25e6879afd67f488ab03d7b57a2f1f7bc17be88823417c675bb026fb58923c691573bd51e034a346c2751fe0ac677b86
7
+ data.tar.gz: a97c3006ba3a3f22e165025eb2cde9ed9b4358fb8cb2003003cb3d14b07197f858206f99e8b756fb0914137b9e6246379f6be32cbfc1c33db46c6ac4affb23f9
@@ -7,6 +7,7 @@ rvm:
7
7
  - 2.1.0
8
8
  - 2.1.1
9
9
  - 2.1.2
10
+ - 2.1.3
10
11
  - jruby-18mode
11
12
  - jruby-19mode
12
13
  - rbx-2
@@ -28,6 +29,8 @@ matrix:
28
29
  gemfile: gemfiles/activesupport2.gemfile
29
30
  - rvm: 2.1.2
30
31
  gemfile: gemfiles/activesupport2.gemfile
32
+ - rvm: 2.1.3
33
+ gemfile: gemfiles/activesupport2.gemfile
31
34
  - rvm: jruby-19mode
32
35
  gemfile: gemfiles/activesupport2.gemfile
33
36
  - rvm: rbx-2
@@ -0,0 +1,11 @@
1
+ appraise "activesupport2" do
2
+ gem 'activesupport', '~> 2.3', :require => false
3
+ end
4
+
5
+ appraise "activesupport3" do
6
+ gem 'activesupport', '~> 3.2', :require => false
7
+ end
8
+
9
+ appraise "activesupport4" do
10
+ gem 'activesupport', '~> 4', :require => false
11
+ end
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ if RUBY_VERSION < '1.9.3'
6
6
  gem 'activesupport', '~> 3.2'
7
7
  end
8
8
 
9
- gem 'pry'
9
+ #gem 'pry'
data/README.md CHANGED
@@ -112,7 +112,7 @@ Time.iso8601("2000-05").precision
112
112
 
113
113
  ## Ruby Compatibility
114
114
 
115
- Tested in MRI 1.8.7/1.9.2/1.9.3/2.0.0/2.1.0, REE, JRuby 1.8/1.9, and Rubinius 1.8/1.9.
115
+ Tested in MRI 1.8.7/1.9.2/1.9.3/2.0.0/2.1.x, REE, JRuby 1.8/1.9, and Rubinius 1.8/1.9.
116
116
 
117
117
  Note that starting in MRI 1.9.3, the core Date/Time classes were rewritten in C, making it difficult to
118
118
  override internal functionality. Some functions are now implemented internally and are not exposed.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env rake
2
+ require "rubygems"
3
+ require "bundler/setup"
2
4
  require "bundler/gem_tasks"
3
5
 
4
6
  Dir['gem_tasks/**/*.rake'].each { |rake| load rake }
5
7
 
6
- task :default => [:spec, 'spec:format', 'spec:active_support', 'spec:compatibility']
8
+ task :default => [:spec, 'spec:format', 'spec:active_support', 'spec:compatibility']
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.add_development_dependency 'rake'
20
20
  gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'appraisal'
21
22
 
22
23
  gem.add_development_dependency 'activesupport'
23
24
  gem.add_development_dependency 'json'
@@ -1,10 +1,7 @@
1
- source "https://rubygems.org"
1
+ # This file was generated by Appraisal
2
2
 
3
- gem 'rake'
4
- gem 'rspec'
3
+ source "https://rubygems.org"
5
4
 
6
- gem 'activesupport', '~> 2.3', :require => false
5
+ gem "activesupport", "~> 2.3", :require => false
7
6
 
8
- gem 'json'
9
- gem 'virtus', '0.5.4'
10
- gem 'coercible', '0.0.1'
7
+ gemspec :path => "../"
@@ -1,10 +1,7 @@
1
- source "https://rubygems.org"
1
+ # This file was generated by Appraisal
2
2
 
3
- gem 'rake'
4
- gem 'rspec'
3
+ source "https://rubygems.org"
5
4
 
6
- gem 'activesupport', '~> 3.2', :require => false
5
+ gem "activesupport", "~> 3.2", :require => false
7
6
 
8
- gem 'json'
9
- gem 'virtus', '0.5.4'
10
- gem 'coercible', '0.0.1'
7
+ gemspec :path => "../"
@@ -1,10 +1,7 @@
1
- source "https://rubygems.org"
1
+ # This file was generated by Appraisal
2
2
 
3
- gem 'rake'
4
- gem 'rspec'
3
+ source "https://rubygems.org"
5
4
 
6
- gem 'activesupport', '~> 4', :require => false
5
+ gem "activesupport", "~> 4", :require => false
7
6
 
8
- gem 'json'
9
- gem 'virtus', '0.5.4'
10
- gem 'coercible', '0.0.1'
7
+ gemspec :path => "../"
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/date/conversions'
2
+ require 'active_support/core_ext/time/conversions'
2
3
 
3
4
  Date::DATE_FORMATS[:long] = lambda do |date|
4
5
  case
@@ -1,3 +1,3 @@
1
1
  module DateTimePrecision
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -11,62 +11,62 @@ describe DateTimePrecision, 'Conversions' do
11
11
  context 'when converting from Date to Time or DateTime' do
12
12
  it 'maintains precision' do
13
13
  d = Date.new(2005, 1)
14
- d.precision.should == DateTimePrecision::MONTH
15
- d.to_date.precision.should == DateTimePrecision::MONTH
16
- d.to_datetime.precision.should == DateTimePrecision::MONTH
14
+ expect(d.precision).to eq(DateTimePrecision::MONTH)
15
+ expect(d.to_date.precision).to eq(DateTimePrecision::MONTH)
16
+ expect(d.to_datetime.precision).to eq(DateTimePrecision::MONTH)
17
17
  end
18
18
  end
19
19
 
20
20
  it 'loses precision when converting from DateTime or Time to Date' do
21
21
  t = Time::parse('2000-1-1 00:00:00 EST') # => Fri Dec 31 21:00:00 -0800 1999
22
- t.precision.should == DateTimePrecision::SEC
23
- t.to_datetime.precision.should == DateTimePrecision::SEC
24
- t.to_date.precision.should == DateTimePrecision::DAY
22
+ expect(t.precision).to eq(DateTimePrecision::SEC)
23
+ expect(t.to_datetime.precision).to eq(DateTimePrecision::SEC)
24
+ expect(t.to_date.precision).to eq(DateTimePrecision::DAY)
25
25
  end
26
26
 
27
27
  it 'converts a date to a hash' do
28
28
  date = Date.new(1999, 10)
29
- date.as_json.should == date.to_h
29
+ expect(date.as_json).to eq(date.to_h)
30
30
  end
31
31
 
32
32
  it 'retains precision when converting to and from JSON' do
33
33
  date = Date.new(1999, 10)
34
- date.precision.should == DateTimePrecision::MONTH
34
+ expect(date.precision).to eq(DateTimePrecision::MONTH)
35
35
  json = ActiveSupport::JSON.encode(date)
36
36
 
37
37
  date_from_json = ActiveSupport::JSON.decode(json).to_date
38
- date_from_json.precision.should == date.precision
38
+ expect(date_from_json.precision).to eq(date.precision)
39
39
  end
40
40
 
41
41
  context 'when formatting as a string' do
42
42
  require 'date_time_precision/format/string'
43
43
 
44
44
  it 'takes precision into account for the :long format' do
45
- Date.new(2000).to_s(:long).should == "2000"
46
- Date.new(2000, 8).to_s(:long).should == "August 2000"
47
- Date.new(2000, 3, 9).to_s(:long).should == "March 9, 2000"
48
- Date.new(nil, 5, 13).to_s(:long).should == "May 13"
49
- Date.new(nil, 6).to_s(:long).should == "June"
45
+ expect(Date.new(2000).to_s(:long)).to eq("2000")
46
+ expect(Date.new(2000, 8).to_s(:long)).to eq("August 2000")
47
+ expect(Date.new(2000, 3, 9).to_s(:long)).to eq("March 9, 2000")
48
+ expect(Date.new(nil, 5, 13).to_s(:long)).to eq("May 13")
49
+ expect(Date.new(nil, 6).to_s(:long)).to eq("June")
50
50
 
51
- DateTime.new(1800).to_s(:long).should == "1800"
52
- DateTime.new(1990, 8).to_s(:long).should == "August 1990"
53
- DateTime.new(-50, 3, 9).to_s(:long).should == "March 09, -0050"
54
- DateTime.new(2004, 7, 8, 10).to_s(:long).should == "July 08, 2004"
55
- DateTime.new(2004, 7, 8, 10, 5).to_s(:long).should == "July 08, 2004 10:05"
56
- DateTime.new(nil, 5, 13).to_s(:long).should == "May 13"
57
- DateTime.new(nil, 6).to_s(:long).should == "June"
51
+ expect(DateTime.new(1800).to_s(:long)).to eq("1800")
52
+ expect(DateTime.new(1990, 8).to_s(:long)).to eq("August 1990")
53
+ expect(DateTime.new(-50, 3, 9).to_s(:long)).to eq("March 09, -0050")
54
+ expect(DateTime.new(2004, 7, 8, 10).to_s(:long)).to eq("July 08, 2004")
55
+ expect(DateTime.new(2004, 7, 8, 10, 5).to_s(:long)).to eq("July 08, 2004 10:05")
56
+ expect(DateTime.new(nil, 5, 13).to_s(:long)).to eq("May 13")
57
+ expect(DateTime.new(nil, 6).to_s(:long)).to eq("June")
58
58
 
59
- Time.mktime(1800).to_s(:long).should == "1800"
60
- Time.mktime(1990, 8).to_s(:long).should == "August 1990"
59
+ expect(Time.mktime(1800).to_s(:long)).to eq("1800")
60
+ expect(Time.mktime(1990, 8).to_s(:long)).to eq("August 1990")
61
61
 
62
62
  # Every Ruby seems to have a different idea about how to format this exactly
63
- Time.mktime(-50, 3, 9).to_s(:long).should match /^March 09, 0*\-0*50$/
63
+ expect(Time.mktime(-50, 3, 9).to_s(:long)).to match /^March 09, 0*\-0*50$/
64
64
 
65
- Time.mktime(2004, 7, 8, 10).to_s(:long).should == "July 08, 2004"
66
- Time.mktime(2004, 7, 8, 10, 5).to_s(:long).should == "July 08, 2004 10:05"
65
+ expect(Time.mktime(2004, 7, 8, 10).to_s(:long)).to eq("July 08, 2004")
66
+ expect(Time.mktime(2004, 7, 8, 10, 5).to_s(:long)).to eq("July 08, 2004 10:05")
67
67
 
68
- Time.mktime(nil, 5, 13).to_s(:long).should == "May 13"
69
- Time.mktime(nil, 6).to_s(:long).should == "June"
68
+ expect(Time.mktime(nil, 5, 13).to_s(:long)).to eq("May 13")
69
+ expect(Time.mktime(nil, 6).to_s(:long)).to eq("June")
70
70
  end
71
71
  end
72
72
  end
@@ -32,29 +32,69 @@ describe DateTimePrecision do
32
32
  context 'when coercing a hash to a Date' do
33
33
  subject { model.date }
34
34
 
35
- it { should be_a Date }
36
- its(:year) { should == 1990 }
37
- its(:precision) { should == DateTimePrecision::YEAR }
35
+ it { is_expected.to be_a Date }
36
+
37
+ describe '#year' do
38
+ subject { super().year }
39
+ it { is_expected.to eq(1990) }
40
+ end
41
+
42
+ describe '#precision' do
43
+ subject { super().precision }
44
+ it { is_expected.to eq(DateTimePrecision::YEAR) }
45
+ end
38
46
  end
39
47
 
40
48
  context 'when coercing a hash to a DateTime' do
41
49
  subject { model.datetime }
42
50
 
43
- it { should be_a DateTime }
44
- its(:year) { should == 1800 }
45
- its(:month) { should == 2 }
46
- its(:precision) { should == DateTimePrecision::MONTH }
51
+ it { is_expected.to be_a DateTime }
52
+
53
+ describe '#year' do
54
+ subject { super().year }
55
+ it { is_expected.to eq(1800) }
56
+ end
57
+
58
+ describe '#month' do
59
+ subject { super().month }
60
+ it { is_expected.to eq(2) }
61
+ end
62
+
63
+ describe '#precision' do
64
+ subject { super().precision }
65
+ it { is_expected.to eq(DateTimePrecision::MONTH) }
66
+ end
47
67
  end
48
68
 
49
69
  context 'when coercing a hash to a Time' do
50
70
  subject { model.time }
51
71
 
52
- it { should be_a Time }
53
- its(:year) { should == 1950 }
54
- its(:month) { should == 5 }
55
- its(:day) { should == 19 }
56
- its(:hour) { should == 5 }
57
- its(:precision) { should == DateTimePrecision::HOUR }
72
+ it { is_expected.to be_a Time }
73
+
74
+ describe '#year' do
75
+ subject { super().year }
76
+ it { is_expected.to eq(1950) }
77
+ end
78
+
79
+ describe '#month' do
80
+ subject { super().month }
81
+ it { is_expected.to eq(5) }
82
+ end
83
+
84
+ describe '#day' do
85
+ subject { super().day }
86
+ it { is_expected.to eq(19) }
87
+ end
88
+
89
+ describe '#hour' do
90
+ subject { super().hour }
91
+ it { is_expected.to eq(5) }
92
+ end
93
+
94
+ describe '#precision' do
95
+ subject { super().precision }
96
+ it { is_expected.to eq(DateTimePrecision::HOUR) }
97
+ end
58
98
  end
59
99
  end
60
100
 
@@ -66,29 +106,69 @@ describe DateTimePrecision do
66
106
  context 'when coercing a hash to a Date' do
67
107
  subject { coercer.to_date(date_hash) }
68
108
 
69
- it { should be_a Date }
70
- its(:year) { should == 1990 }
71
- its(:precision) { should == DateTimePrecision::YEAR }
109
+ it { is_expected.to be_a Date }
110
+
111
+ describe '#year' do
112
+ subject { super().year }
113
+ it { is_expected.to eq(1990) }
114
+ end
115
+
116
+ describe '#precision' do
117
+ subject { super().precision }
118
+ it { is_expected.to eq(DateTimePrecision::YEAR) }
119
+ end
72
120
  end
73
121
 
74
122
  context 'when coercing a hash to a DateTime' do
75
123
  subject { coercer.to_datetime(datetime_hash) }
76
124
 
77
- it { should be_a DateTime }
78
- its(:year) { should == 1800 }
79
- its(:month) { should == 2 }
80
- its(:precision) { should == DateTimePrecision::MONTH }
125
+ it { is_expected.to be_a DateTime }
126
+
127
+ describe '#year' do
128
+ subject { super().year }
129
+ it { is_expected.to eq(1800) }
130
+ end
131
+
132
+ describe '#month' do
133
+ subject { super().month }
134
+ it { is_expected.to eq(2) }
135
+ end
136
+
137
+ describe '#precision' do
138
+ subject { super().precision }
139
+ it { is_expected.to eq(DateTimePrecision::MONTH) }
140
+ end
81
141
  end
82
142
 
83
143
  context 'when coercing a hash to a Time' do
84
144
  subject { coercer.to_time(time_hash) }
85
145
 
86
- it { should be_a Time }
87
- its(:year) { should == 1950 }
88
- its(:month) { should == 5 }
89
- its(:day) { should == 19 }
90
- its(:hour) { should == 5 }
91
- its(:precision) { should == DateTimePrecision::HOUR }
146
+ it { is_expected.to be_a Time }
147
+
148
+ describe '#year' do
149
+ subject { super().year }
150
+ it { is_expected.to eq(1950) }
151
+ end
152
+
153
+ describe '#month' do
154
+ subject { super().month }
155
+ it { is_expected.to eq(5) }
156
+ end
157
+
158
+ describe '#day' do
159
+ subject { super().day }
160
+ it { is_expected.to eq(19) }
161
+ end
162
+
163
+ describe '#hour' do
164
+ subject { super().hour }
165
+ it { is_expected.to eq(5) }
166
+ end
167
+
168
+ describe '#precision' do
169
+ subject { super().precision }
170
+ it { is_expected.to eq(DateTimePrecision::HOUR) }
171
+ end
92
172
  end
93
173
  end
94
174
  end
@@ -5,166 +5,166 @@ describe DateTimePrecision do
5
5
  context 'Constructors' do
6
6
  it 'has no precision for unspecified date' do
7
7
  d = Date.new
8
- d.precision.should == DateTimePrecision::NONE
9
- d.year?.should be_false
8
+ expect(d.precision).to eq(DateTimePrecision::NONE)
9
+ expect(d.year?).to be_falsey
10
10
 
11
11
  dt = DateTime.new
12
- dt.precision.should == DateTimePrecision::NONE
13
- dt.year?.should be_false
12
+ expect(dt.precision).to eq(DateTimePrecision::NONE)
13
+ expect(dt.year?).to be_falsey
14
14
  end
15
15
 
16
16
  it 'has no precision for nil values' do
17
- nil.precision.should == DateTimePrecision::NONE
17
+ expect(nil.precision).to eq(DateTimePrecision::NONE)
18
18
  end
19
19
 
20
20
  it 'has year precision when only year is supplied' do
21
21
  d = Date.new(1982)
22
- d.precision.should == DateTimePrecision::YEAR
23
- d.year?.should be_true
24
- d.month?.should be_false
25
- d.day?.should be_false
22
+ expect(d.precision).to eq(DateTimePrecision::YEAR)
23
+ expect(d.year?).to be_truthy
24
+ expect(d.month?).to be_falsey
25
+ expect(d.day?).to be_falsey
26
26
  end
27
27
 
28
28
  it 'has month precision when year and month are supplied' do
29
29
  d = Date.new(1982, 11)
30
- d.precision.should == DateTimePrecision::MONTH
31
- d.year?.should be_true
32
- d.month?.should be_true
33
- d.day?.should be_false
30
+ expect(d.precision).to eq(DateTimePrecision::MONTH)
31
+ expect(d.year?).to be_truthy
32
+ expect(d.month?).to be_truthy
33
+ expect(d.day?).to be_falsey
34
34
  end
35
35
 
36
36
  it 'has day precision when year, month, and day are passed in' do
37
37
  dt = DateTime.new(1987,10,19)
38
- dt.precision.should == DateTimePrecision::DAY
39
- dt.year?.should be_true
40
- dt.month?.should be_true
41
- dt.day?.should be_true
42
- dt.hour?.should be_false
38
+ expect(dt.precision).to eq(DateTimePrecision::DAY)
39
+ expect(dt.year?).to be_truthy
40
+ expect(dt.month?).to be_truthy
41
+ expect(dt.day?).to be_truthy
42
+ expect(dt.hour?).to be_falsey
43
43
  end
44
44
 
45
45
  it 'has hour precision' do
46
46
  dt = DateTime.new(1970, 1, 2, 3)
47
- dt.precision.should == DateTimePrecision::HOUR
48
- dt.year?.should be_true
49
- dt.month?.should be_true
50
- dt.day?.should be_true
51
- dt.hour?.should be_true
52
- dt.min?.should be_false
47
+ expect(dt.precision).to eq(DateTimePrecision::HOUR)
48
+ expect(dt.year?).to be_truthy
49
+ expect(dt.month?).to be_truthy
50
+ expect(dt.day?).to be_truthy
51
+ expect(dt.hour?).to be_truthy
52
+ expect(dt.min?).to be_falsey
53
53
  end
54
54
 
55
55
  it 'tracks which attributes were explicitly set separately from precision' do
56
56
  [Date.new(nil, 11, 12), DateTime.new(nil, 10, 11, nil), Time.mktime(nil, 12, 13, nil, 14)].each do |d|
57
- d.year?.should be_false
58
- d.month?.should be_true
59
- d.day?.should be_true
60
- d.hour?.should be_false
61
- d.min?.should be_true if d.is_a? Time
62
- d.precision.should == DateTimePrecision::NONE
57
+ expect(d.year?).to be_falsey
58
+ expect(d.month?).to be_truthy
59
+ expect(d.day?).to be_truthy
60
+ expect(d.hour?).to be_falsey
61
+ expect(d.min?).to be_truthy if d.is_a? Time
62
+ expect(d.precision).to eq(DateTimePrecision::NONE)
63
63
  end
64
64
  end
65
65
 
66
66
  it 'has max precision for fully specified dates/times' do
67
67
  # Time.new is an alias for Time.now
68
68
  [Time.new, Time.now, DateTime.now, Date.today].each do |t|
69
- t.precision.should == t.class::MAX_PRECISION
69
+ expect(t.precision).to eq(t.class::MAX_PRECISION)
70
70
  end
71
71
  end
72
72
 
73
73
  it 'accepts nil values in the constructor' do
74
- Date.new(nil).precision.should == DateTimePrecision::NONE
75
- Date.new(2000, nil).precision.should == DateTimePrecision::YEAR
76
- DateTime.new(2000, 1, nil).precision.should == DateTimePrecision::MONTH
77
- Time.mktime(2000, 1, 1, nil, nil).precision.should == DateTimePrecision::DAY
74
+ expect(Date.new(nil).precision).to eq(DateTimePrecision::NONE)
75
+ expect(Date.new(2000, nil).precision).to eq(DateTimePrecision::YEAR)
76
+ expect(DateTime.new(2000, 1, nil).precision).to eq(DateTimePrecision::MONTH)
77
+ expect(Time.mktime(2000, 1, 1, nil, nil).precision).to eq(DateTimePrecision::DAY)
78
78
  end
79
79
  end
80
80
 
81
81
  context 'Time Zones' do
82
82
  it 'should retain precision when switching to UTC' do
83
- Time.mktime(2000).utc.precision.should == DateTimePrecision::YEAR
84
- Time.mktime(2000).gmtime.precision.should == DateTimePrecision::YEAR
83
+ expect(Time.mktime(2000).utc.precision).to eq(DateTimePrecision::YEAR)
84
+ expect(Time.mktime(2000).gmtime.precision).to eq(DateTimePrecision::YEAR)
85
85
  end
86
86
 
87
87
  it 'should track precision when creating a date, time, or datetime in UTC' do
88
- Time.utc(1945, 10).precision.should == DateTimePrecision::MONTH
89
- Time.gm(1945, 10).precision.should == DateTimePrecision::MONTH
88
+ expect(Time.utc(1945, 10).precision).to eq(DateTimePrecision::MONTH)
89
+ expect(Time.gm(1945, 10).precision).to eq(DateTimePrecision::MONTH)
90
90
 
91
- Date.utc(1945, 10).precision.should == DateTimePrecision::MONTH
92
- DateTime.utc(1945, 10).precision.should == DateTimePrecision::MONTH
91
+ expect(Date.utc(1945, 10).precision).to eq(DateTimePrecision::MONTH)
92
+ expect(DateTime.utc(1945, 10).precision).to eq(DateTimePrecision::MONTH)
93
93
  end
94
94
 
95
95
  it 'should track precision when creating a time in the local timezone' do
96
- Time.local(2004, 5, 6).precision.should == DateTimePrecision::DAY
96
+ expect(Time.local(2004, 5, 6).precision).to eq(DateTimePrecision::DAY)
97
97
  end
98
98
  end
99
99
 
100
100
  context 'Parsing' do
101
101
  it 'should have second/frac precision when parsing a timestamp' do
102
102
  t = Time::parse('2000-2-3 00:00:00 UTC')
103
- t.precision.should == DateTimePrecision::SEC
104
- t.year.should == 2000
105
- t.month.should == 2
106
- t.day.should == 3
103
+ expect(t.precision).to eq(DateTimePrecision::SEC)
104
+ expect(t.year).to eq(2000)
105
+ expect(t.month).to eq(2)
106
+ expect(t.day).to eq(3)
107
107
  end
108
108
 
109
109
  it 'should have minute precision when seconds are not in the timestamp' do
110
110
  dt = DateTime::parse('2000-1-1 00:00 EST') # => Sat, 01 Jan 2000 00:00:00 -0500
111
- dt.precision.should == DateTimePrecision::MIN
112
- dt.year.should == 2000
113
- dt.day.should == 1
111
+ expect(dt.precision).to eq(DateTimePrecision::MIN)
112
+ expect(dt.year).to eq(2000)
113
+ expect(dt.day).to eq(1)
114
114
  end
115
115
 
116
116
  it 'should have day precision wehn parsing into a Date object' do
117
117
  d = Date::parse('2000-1-1 00:00:00 EST') # => Sat, 01 Jan 2000
118
- d.precision.should == DateTimePrecision::DAY
118
+ expect(d.precision).to eq(DateTimePrecision::DAY)
119
119
  end
120
120
 
121
121
  it 'should have month precision when day is not in the parsed string' do
122
122
  t = Time::parse('January 2000 UTC').utc # => Sat Jan 01 00:00:00 -0800 2000
123
- t.precision.should == DateTimePrecision::MONTH
124
- t.year.should == 2000
125
- t.month.should == 1
123
+ expect(t.precision).to eq(DateTimePrecision::MONTH)
124
+ expect(t.year).to eq(2000)
125
+ expect(t.month).to eq(1)
126
126
  end
127
127
  end
128
128
 
129
129
  context 'strptime' do
130
130
  it 'should have day precision when day is specified in date string' do
131
131
  d = Date.strptime('02/09/1968', '%m/%d/%Y')
132
- d.precision.should == DateTimePrecision::DAY
132
+ expect(d.precision).to eq(DateTimePrecision::DAY)
133
133
  end
134
134
 
135
135
  it 'should have minute precision when extracting down to the minute' do
136
136
  dt = DateTime.strptime('2011-02-03 15:14:52','%Y-%m-%d %H:%M')
137
- dt.precision.should == DateTimePrecision::MIN
137
+ expect(dt.precision).to eq(DateTimePrecision::MIN)
138
138
  end
139
139
 
140
140
  it 'should have second precision when extracting down to the second' do
141
141
  t = DateTime.strptime('2011-02-03 15:14:52','%Y-%m-%d %H:%M:%S')
142
- t.precision.should == DateTimePrecision::SEC
142
+ expect(t.precision).to eq(DateTimePrecision::SEC)
143
143
  end
144
144
  end
145
145
 
146
146
  context 'Addition' do
147
147
  it 'should default to max precision when adding or subtracting' do
148
148
  d = Date.new
149
- d.precision.should == DateTimePrecision::NONE
149
+ expect(d.precision).to eq(DateTimePrecision::NONE)
150
150
  d += 3
151
- d.precision.should == Date::MAX_PRECISION
151
+ expect(d.precision).to eq(Date::MAX_PRECISION)
152
152
  d -= 2
153
- d.precision.should == Date::MAX_PRECISION
153
+ expect(d.precision).to eq(Date::MAX_PRECISION)
154
154
 
155
155
  dt = DateTime.new
156
- dt.precision.should == DateTimePrecision::NONE
156
+ expect(dt.precision).to eq(DateTimePrecision::NONE)
157
157
  dt += 3
158
- dt.precision.should == DateTime::MAX_PRECISION
158
+ expect(dt.precision).to eq(DateTime::MAX_PRECISION)
159
159
  dt -= 2
160
- dt.precision.should == DateTime::MAX_PRECISION
160
+ expect(dt.precision).to eq(DateTime::MAX_PRECISION)
161
161
 
162
162
  t = Time::parse('January 2000 UTC').utc
163
- t.precision.should == DateTimePrecision::MONTH
163
+ expect(t.precision).to eq(DateTimePrecision::MONTH)
164
164
  t += 10
165
- t.precision.should == Time::MAX_PRECISION
165
+ expect(t.precision).to eq(Time::MAX_PRECISION)
166
166
  t -= 8
167
- t.precision.should == Time::MAX_PRECISION
167
+ expect(t.precision).to eq(Time::MAX_PRECISION)
168
168
  end
169
169
  end
170
170
 
@@ -172,8 +172,8 @@ describe DateTimePrecision do
172
172
  it 'should match when differing only in day precision' do
173
173
  d1 = Date.new(2001,3,2)
174
174
  d2 = Date.new(2001,3)
175
- d1.partial_match?(d2).should be_true
176
- d2.partial_match?(d1).should be_true
175
+ expect(d1.partial_match?(d2)).to be_truthy
176
+ expect(d2.partial_match?(d1)).to be_truthy
177
177
  end
178
178
  end
179
179
 
@@ -28,40 +28,40 @@ describe DateTimePrecision do
28
28
 
29
29
  [:iso8601, :xmlschema].each do |format_method|
30
30
  it 'converts a date to and from ISO 8601' do
31
- date.send(format_method).should == "1989-03-11"
31
+ expect(date.send(format_method)).to eq("1989-03-11")
32
32
 
33
33
  @table.take(3).each do |args, format_string|
34
- Date.new(*args).send(format_method).should == format_string
34
+ expect(Date.new(*args).send(format_method)).to eq(format_string)
35
35
 
36
36
  d = Date.send(format_method, format_string)
37
- d.should == Date.new(*args)
38
- d.precision.should == args.length
37
+ expect(d).to eq(Date.new(*args))
38
+ expect(d.precision).to eq(args.length)
39
39
  end
40
40
  end
41
41
 
42
42
  it 'converts a datetime to and from ISO 8601' do
43
- datetime.send(format_method).should == "1989-03-11T08:30:15Z"
43
+ expect(datetime.send(format_method)).to eq("1989-03-11T08:30:15Z")
44
44
 
45
45
  @table.each do |args, format_string|
46
- DateTime.new(*args).send(format_method).should == format_string
46
+ expect(DateTime.new(*args).send(format_method)).to eq(format_string)
47
47
 
48
48
  d = DateTime.send(format_method, format_string)
49
49
  constructor = args.length > 3 ? :utc : :local
50
- d.should == DateTime.send(constructor, *args)
51
- d.precision.should == args.length
50
+ expect(d).to eq(DateTime.send(constructor, *args))
51
+ expect(d.precision).to eq(args.length)
52
52
  end
53
53
  end
54
54
 
55
55
  it 'converts a time to ISO 8601' do
56
- Time.mktime(1900).send(format_method).should == "1900"
56
+ expect(Time.mktime(1900).send(format_method)).to eq("1900")
57
57
 
58
58
  @table.each do |args, format_string|
59
- Time.utc(*args).send(format_method).should == format_string
59
+ expect(Time.utc(*args).send(format_method)).to eq(format_string)
60
60
 
61
61
  t = Time.send(format_method, format_string)
62
62
  constructor = args.length > 3 ? :utc : :local
63
- t.should == Time.send(constructor, *args)
64
- t.precision.should == args.length
63
+ expect(t).to eq(Time.send(constructor, *args))
64
+ expect(t.precision).to eq(args.length)
65
65
  end
66
66
  end
67
67
  end
@@ -97,19 +97,19 @@ describe DateTimePrecision do
97
97
 
98
98
  context 'Converting to hash' do
99
99
  it 'should convert Date to a hash' do
100
- date.to_h.should == date_hash
100
+ expect(date.to_h).to eq(date_hash)
101
101
  end
102
102
 
103
103
  it 'should convert DateTime to a hash' do
104
- datetime.to_h.should == datetime_hash
104
+ expect(datetime.to_h).to eq(datetime_hash)
105
105
  end
106
106
 
107
107
  it 'should convert Time to a hash' do
108
- time.to_h.should == time_hash
108
+ expect(time.to_h).to eq(time_hash)
109
109
  end
110
110
 
111
111
  it 'should skip year if not included' do
112
- Date.new(nil, 8, 10).to_h.should == {:mon => 8, :day => 10}
112
+ expect(Date.new(nil, 8, 10).to_h).to eq({:mon => 8, :day => 10})
113
113
  end
114
114
  end
115
115
 
@@ -131,22 +131,22 @@ describe DateTimePrecision do
131
131
  end
132
132
 
133
133
  it 'should convert Date to a short hash' do
134
- date.to_h(:short).should == short_date_hash
134
+ expect(date.to_h(:short)).to eq(short_date_hash)
135
135
  end
136
136
 
137
137
  it 'should convert Date to a long hash' do
138
- date.to_h(:long).should == long_date_hash
138
+ expect(date.to_h(:long)).to eq(long_date_hash)
139
139
  end
140
140
 
141
141
  it 'should convert DateTime to a long hash' do
142
- datetime.to_h(:long).should == {
142
+ expect(datetime.to_h(:long)).to eq({
143
143
  :year => 1989,
144
144
  :month => 3,
145
145
  :day => 11,
146
146
  :hour => 8,
147
147
  :minute => 30,
148
148
  :second => 15
149
- }
149
+ })
150
150
  end
151
151
 
152
152
  it 'should convert Time to a short hash' do
@@ -161,75 +161,75 @@ describe DateTimePrecision do
161
161
 
162
162
  hash.merge!(:us => 1) if DateTimePrecision::MICROSECONDS_SUPPORTED
163
163
 
164
- time.to_h(:short).should == hash
164
+ expect(time.to_h(:short)).to eq(hash)
165
165
  end
166
166
 
167
167
  it 'should convert Time to a custom hash' do
168
- Hash::DATE_FORMATS[:custom] = [:year, :mon, :d, :h, :min, :s]
168
+ ::Hash::DATE_FORMATS[:custom] = [:year, :mon, :d, :h, :min, :s]
169
169
 
170
- time.to_h(:custom).should == {
170
+ expect(time.to_h(:custom)).to eq({
171
171
  :year => 1989,
172
172
  :mon => 3,
173
173
  :d => 11,
174
174
  :h => 8,
175
175
  :min => 30,
176
176
  :s => 15,
177
- }
177
+ })
178
178
  end
179
179
 
180
180
  it 'should convert to the default hash format' do
181
- Hash::DATE_FORMATS[:default] = Hash::DATE_FORMATS[:short]
182
- date.to_h(:short).should == short_date_hash
183
- Hash::DATE_FORMATS[:default] = Hash::DATE_FORMATS[:ruby]
181
+ ::Hash::DATE_FORMATS[:default] = ::Hash::DATE_FORMATS[:short]
182
+ expect(date.to_h(:short)).to eq(short_date_hash)
183
+ ::Hash::DATE_FORMATS[:default] = ::Hash::DATE_FORMATS[:ruby]
184
184
  end
185
185
 
186
186
  it 'should only include fields that were set' do
187
- Date.new(nil, 3, 8).to_h.should == {:mon => 3, :day => 8}
188
- DateTime.new(nil, 5, 6, nil, 7).to_h.should == {:mon => 5, :day => 6, :min => 7}
189
- Time.mktime(nil, 1, nil, 9, nil, 10).to_h.should == {:mon => 1, :hour => 9, :sec => 10}
187
+ expect(Date.new(nil, 3, 8).to_h).to eq({:mon => 3, :day => 8})
188
+ expect(DateTime.new(nil, 5, 6, nil, 7).to_h).to eq({:mon => 5, :day => 6, :min => 7})
189
+ expect(Time.mktime(nil, 1, nil, 9, nil, 10).to_h).to eq({:mon => 1, :hour => 9, :sec => 10})
190
190
  end
191
191
  end
192
192
 
193
193
  context 'Converting from hash' do
194
194
  it 'converts a hash to a Date' do
195
- date_hash.to_date.should == date
195
+ expect(date_hash.to_date).to eq(date)
196
196
  end
197
197
 
198
198
  it 'converts a hash to a DateTime' do
199
- datetime_hash.to_datetime.should == datetime
199
+ expect(datetime_hash.to_datetime).to eq(datetime)
200
200
  end
201
201
 
202
202
  it 'converts a hash to a Time' do
203
- time_hash.to_time.should == time
203
+ expect(time_hash.to_time).to eq(time)
204
204
  end
205
205
 
206
206
  it 'accepts flexible keys' do
207
- {
207
+ expect({
208
208
  :y => 1989,
209
209
  :m => 3,
210
210
  :d => 11
211
- }.to_date.should == date
211
+ }.to_date).to eq(date)
212
212
 
213
- {
213
+ expect({
214
214
  :year => 1989,
215
215
  :month => 3,
216
216
  :day => 11
217
- }.to_date.should == date
217
+ }.to_date).to eq(date)
218
218
  end
219
219
 
220
220
  [:date, :datetime, :time].each do |klass|
221
221
  it "accepts month and day without year when converting to a #{klass}" do
222
222
  date = { :month => 5, :day => 18, :min => 48 }.send("to_#{klass}")
223
- date.year?.should be_false
224
- date.month?.should be_true
225
- date.month.should == 5
226
- date.day?.should be_true
227
- date.day.should == 18
228
- date.hour?.should be_false
223
+ expect(date.year?).to be_falsey
224
+ expect(date.month?).to be_truthy
225
+ expect(date.month).to eq(5)
226
+ expect(date.day?).to be_truthy
227
+ expect(date.day).to eq(18)
228
+ expect(date.hour?).to be_falsey
229
229
 
230
230
  unless klass == :date
231
- date.min?.should be_true
232
- date.min.should == 48
231
+ expect(date.min?).to be_truthy
232
+ expect(date.min).to eq(48)
233
233
  end
234
234
  end
235
235
  end
@@ -241,20 +241,20 @@ describe DateTimePrecision do
241
241
  require 'json'
242
242
 
243
243
  it 'should convert a date to a JSON hash' do
244
- date.as_json.should == date.to_h
245
- date.to_json.should == date.to_h.to_json
244
+ expect(date.as_json).to eq(date.to_h)
245
+ expect(date.to_json).to eq(date.to_h.to_json)
246
246
  end
247
247
 
248
248
  it 'should convert a datetime to a JSON hash' do
249
- datetime.as_json.should == datetime.to_h
250
- datetime.to_json.should == datetime.to_h.to_json
249
+ expect(datetime.as_json).to eq(datetime.to_h)
250
+ expect(datetime.to_json).to eq(datetime.to_h.to_json)
251
251
  end
252
252
 
253
253
  it 'should convert a time to a JSON hash' do
254
- time.as_json.should == time.to_h
255
- time.to_json.should == time.to_h.to_json
254
+ expect(time.as_json).to eq(time.to_h)
255
+ expect(time.to_json).to eq(time.to_h.to_json)
256
256
  end
257
257
  end
258
258
 
259
259
  end
260
- end
260
+ end
metadata CHANGED
@@ -1,83 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: date_time_precision
3
- version: !ruby/object:Gem::Version
4
- version: 0.7.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.2
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - David Butler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-05-28 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
- requirements:
17
- - &id002
18
- - ">="
19
- - !ruby/object:Gem::Version
20
- version: "0"
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rake
22
- requirement: *id001
23
- prerelease: false
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
24
20
  type: :development
25
- - !ruby/object:Gem::Dependency
26
- version_requirements: &id003 !ruby/object:Gem::Requirement
27
- requirements:
28
- - *id002
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
29
28
  name: rspec
30
- requirement: *id003
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
31
35
  prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: appraisal
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
32
48
  type: :development
33
- - !ruby/object:Gem::Dependency
34
- version_requirements: &id004 !ruby/object:Gem::Requirement
35
- requirements:
36
- - *id002
37
- name: activesupport
38
- requirement: *id004
39
49
  prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
40
62
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- version_requirements: &id005 !ruby/object:Gem::Requirement
43
- requirements:
44
- - *id002
45
- name: json
46
- requirement: *id005
47
63
  prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
48
76
  type: :development
49
- - !ruby/object:Gem::Dependency
50
- version_requirements: &id006 !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "="
53
- - !ruby/object:Gem::Version
54
- version: 0.5.4
55
- name: virtus
56
- requirement: *id006
57
77
  prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: virtus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.5.4
58
90
  type: :development
59
- - !ruby/object:Gem::Dependency
60
- version_requirements: &id007 !ruby/object:Gem::Requirement
61
- requirements:
62
- - - "="
63
- - !ruby/object:Gem::Version
64
- version: 0.0.1
65
- name: coercible
66
- requirement: *id007
67
91
  prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.5.4
97
+ - !ruby/object:Gem::Dependency
98
+ name: coercible
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.0.1
68
104
  type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.1
69
111
  description: Patches Date, Time, and DateTime ruby classes to keep track of precision
70
- email:
112
+ email:
71
113
  - dwbutler@ucla.edu
72
114
  executables: []
73
-
74
115
  extensions: []
75
-
76
116
  extra_rdoc_files: []
77
-
78
- files:
79
- - .gitignore
80
- - .travis.yml
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Appraisals
81
121
  - Gemfile
82
122
  - LICENSE
83
123
  - README
@@ -118,29 +158,30 @@ files:
118
158
  - spec/format_spec.rb
119
159
  - spec/spec_helper.rb
120
160
  homepage: http://github.com/Spokeo/date_time_precision
121
- licenses:
161
+ licenses:
122
162
  - MIT
123
163
  metadata: {}
124
-
125
164
  post_install_message:
126
165
  rdoc_options: []
127
-
128
- require_paths:
166
+ require_paths:
129
167
  - lib
130
- required_ruby_version: !ruby/object:Gem::Requirement
131
- requirements:
132
- - *id002
133
- required_rubygems_version: !ruby/object:Gem::Requirement
134
- requirements:
135
- - *id002
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
136
178
  requirements: []
137
-
138
179
  rubyforge_project:
139
180
  rubygems_version: 2.2.2
140
181
  signing_key:
141
182
  specification_version: 4
142
183
  summary: Patches Date, Time, and DateTime ruby classes to keep track of precision
143
- test_files:
184
+ test_files:
144
185
  - spec/active_support_spec.rb
145
186
  - spec/compatibility_spec.rb
146
187
  - spec/date_time_precision_spec.rb