greenwich 0.0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +9 -1
- data/.rvmrc +1 -1
- data/Gemfile +3 -1
- data/README.md +46 -41
- data/Rakefile +1 -0
- data/greenwich.gemspec +8 -4
- data/lib/greenwich.rb +7 -5
- data/lib/greenwich/conversion.rb +82 -0
- data/lib/greenwich/time_zone.rb +7 -0
- data/lib/greenwich/utilities.rb +23 -11
- data/lib/greenwich/version.rb +1 -1
- data/spec/greenwich/conversion_spec.rb +313 -0
- data/spec/greenwich/utilities_spec.rb +143 -49
- data/spec/spec_helper.rb +0 -6
- data/spec/support/focused.rb +7 -0
- data/spec/support/pending.rb +4 -0
- metadata +153 -62
- data/lib/greenwich/rails.rb +0 -85
- data/lib/greenwich/time_with_zone.rb +0 -30
@@ -1,84 +1,178 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Greenwich::Utilities do
|
4
|
-
describe
|
5
|
-
|
4
|
+
describe '.get_time_zone_field' do
|
5
|
+
subject { Greenwich::Utilities.get_time_zone_field(name, columns) }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
let(:name) { 'foo_at' }
|
8
|
+
|
9
|
+
context 'when columns includes a field-specific time zone field' do
|
10
|
+
let(:columns) { %w(foo bar foo_at_time_zone) }
|
11
|
+
|
12
|
+
it 'is the field-specific time zone field' do
|
13
|
+
subject.should eql 'foo_at_time_zone'
|
11
14
|
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when columns does not include a field-specific time zone field' do
|
18
|
+
context 'but does include the general time zone field' do
|
19
|
+
let(:columns) { %w(foo bar time_zone) }
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
it 'is the general time zone field' do
|
22
|
+
subject.should eql 'time_zone'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'and does not include the general time zone field' do
|
27
|
+
let(:columns) { %w(foo bar) }
|
28
|
+
|
29
|
+
it 'is nil' do
|
30
|
+
subject.should be_nil
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
34
|
+
end
|
18
35
|
|
19
|
-
|
20
|
-
|
36
|
+
describe '.get_time_zone' do
|
37
|
+
subject { Greenwich::Utilities.get_time_zone model, 'time_zone' }
|
21
38
|
|
22
|
-
|
23
|
-
|
24
|
-
|
39
|
+
context 'when the object does not have a time zone' do
|
40
|
+
context 'because it does not exist' do
|
41
|
+
let(:model) { stub :time_zone => nil }
|
25
42
|
|
26
|
-
|
27
|
-
|
43
|
+
it 'is nil' do
|
44
|
+
subject.should be_nil
|
45
|
+
end
|
28
46
|
end
|
29
47
|
|
30
|
-
|
31
|
-
|
32
|
-
time_with_zone = ActiveSupport::TimeWithZone.new(nil, alaskan_time_zone, @time)
|
48
|
+
context 'because it cannot be found' do
|
49
|
+
let(:model) { Object.new.stub(:time_zone).and_raise NoMethodError }
|
33
50
|
|
34
|
-
|
35
|
-
|
51
|
+
it 'is nil' do
|
52
|
+
subject.should be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'because it is not valid' do
|
57
|
+
let(:model) { stub :time_zone => "Look at me! I'm an invalid time zone!" }
|
58
|
+
|
59
|
+
it 'is nil' do
|
60
|
+
subject.should be_nil
|
61
|
+
end
|
36
62
|
end
|
37
63
|
end
|
38
64
|
|
39
|
-
context
|
40
|
-
it
|
41
|
-
|
65
|
+
context 'when the object does have a time zone' do
|
66
|
+
context 'because it is a time zone' do
|
67
|
+
let(:model) { stub :time_zone => ActiveSupport::TimeZone.new('Alaska') }
|
42
68
|
|
43
|
-
|
44
|
-
|
69
|
+
it 'is the proper time zone object' do
|
70
|
+
subject.should eql ActiveSupport::TimeZone.new('Alaska')
|
71
|
+
end
|
45
72
|
end
|
46
73
|
|
47
|
-
it
|
48
|
-
|
74
|
+
context 'because it is a valid time zone string' do
|
75
|
+
let(:model) { stub :time_zone => 'Alaska' }
|
49
76
|
|
50
|
-
|
51
|
-
|
77
|
+
it 'is the proper time zone object' do
|
78
|
+
subject.should eql ActiveSupport::TimeZone.new('Alaska')
|
79
|
+
end
|
52
80
|
end
|
53
81
|
end
|
54
82
|
end
|
55
83
|
|
56
|
-
describe
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
84
|
+
describe '.coerce_to_time_zone' do
|
85
|
+
subject { Greenwich::Utilities.coerce_to_time_zone(value) }
|
86
|
+
|
87
|
+
context 'when the value is nil' do
|
88
|
+
let(:value) { nil }
|
89
|
+
|
90
|
+
it 'is nil' do
|
91
|
+
subject.should be_nil
|
61
92
|
end
|
62
93
|
end
|
63
94
|
|
64
|
-
context
|
65
|
-
|
95
|
+
context 'when the value is blank' do
|
96
|
+
let(:value) { '' }
|
97
|
+
|
98
|
+
it 'is nil' do
|
99
|
+
subject.should be_nil
|
100
|
+
end
|
101
|
+
end
|
66
102
|
|
67
|
-
|
68
|
-
|
69
|
-
alaskan_time_zone = ActiveSupport::TimeZone.new('Alaska')
|
70
|
-
time_with_zone = ActiveSupport::TimeWithZone.new(nil, alaskan_time_zone, @time)
|
103
|
+
context 'when the value is not the name of a valid time zone' do
|
104
|
+
let(:value) { 'foo' }
|
71
105
|
|
72
|
-
|
73
|
-
|
74
|
-
|
106
|
+
it 'is nil' do
|
107
|
+
subject.should be_nil
|
108
|
+
end
|
109
|
+
end
|
75
110
|
|
76
|
-
|
77
|
-
|
111
|
+
context 'when the value is the name of a valid time zone' do
|
112
|
+
let(:value) { 'Alaska' }
|
78
113
|
|
79
|
-
|
80
|
-
|
81
|
-
|
114
|
+
it 'is the corresponding TimeZone' do
|
115
|
+
subject.should eql ActiveSupport::TimeZone.new('Alaska')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when the value is a time zone' do
|
120
|
+
let(:value) { ActiveSupport::TimeZone.new('Alaska') }
|
121
|
+
|
122
|
+
it 'is the time zone' do
|
123
|
+
subject.should eql value
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '.coerce_to_time_without_zone' do
|
129
|
+
subject { Greenwich::Utilities.coerce_to_time_without_zone value }
|
130
|
+
|
131
|
+
context 'when nil is passed in' do
|
132
|
+
let(:value) { nil }
|
133
|
+
|
134
|
+
it 'is nil' do
|
135
|
+
subject.should be_nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'when something which cannot be converted to a time is passed in' do
|
140
|
+
let(:value) { 5 }
|
141
|
+
|
142
|
+
it 'is nil' do
|
143
|
+
subject.should be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when something which cannot be properly converted to a time is passed in' do
|
148
|
+
let(:value) { 'foo' }
|
149
|
+
|
150
|
+
it 'is nil' do
|
151
|
+
subject.should be_nil
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when a string that does not contain a UTC offset is passed in' do
|
156
|
+
let(:value) { '2012-01-02 12:59:01' }
|
157
|
+
|
158
|
+
it 'is the UTC representation of that time' do
|
159
|
+
subject.should eql Time.utc(2012, 1, 2, 12, 59, 1)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when a string that does contain a UTC offset is passed in' do
|
164
|
+
let(:value) { '2012-01-02 12:59:01 -0800' }
|
165
|
+
|
166
|
+
it 'is the UTC representation of that time ignoring any time zone offset information' do
|
167
|
+
subject.should eql Time.utc(2012, 1, 2, 12, 59, 1)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'when a UTC time is passed in' do
|
172
|
+
let(:value) { Time.utc(2012, 1, 2, 12, 59, 1) }
|
173
|
+
|
174
|
+
it 'is the UTC representation of that time ignoring any time zone offset information' do
|
175
|
+
subject.should eql Time.utc(2012, 1, 2, 12, 59, 1)
|
82
176
|
end
|
83
177
|
end
|
84
178
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
# Configure RSpec to run focused specs, and also respect the alias 'fit' for focused specs
|
3
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
4
|
+
config.filter_run :focused => true
|
5
|
+
config.alias_example_to :fit, :focused => true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
end
|
metadata
CHANGED
@@ -1,74 +1,155 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: greenwich
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.5
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- thekompanee
|
7
|
+
authors:
|
9
8
|
- jfelchner
|
9
|
+
- m5rk
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
dependencies:
|
17
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2012-08-24 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
18
16
|
name: activerecord
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :runtime
|
19
24
|
prerelease: false
|
20
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: activesupport
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
21
34
|
none: false
|
22
|
-
requirements:
|
35
|
+
requirements:
|
23
36
|
- - ~>
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version:
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '3.0'
|
26
39
|
type: :runtime
|
27
|
-
version_requirements: *id001
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: bundler
|
30
40
|
prerelease: false
|
31
|
-
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: tzinfo
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
32
50
|
none: false
|
33
|
-
requirements:
|
51
|
+
requirements:
|
34
52
|
- - ~>
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version:
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.3'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: bundler
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '1.0'
|
37
71
|
type: :development
|
38
|
-
version_requirements: *id002
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: rspec
|
41
72
|
prerelease: false
|
42
|
-
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rspec
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
43
82
|
none: false
|
44
|
-
requirements:
|
83
|
+
requirements:
|
45
84
|
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version:
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '2.6'
|
48
87
|
type: :development
|
49
|
-
|
50
|
-
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '2.6'
|
95
|
+
- !ruby/object:Gem::Dependency
|
51
96
|
name: yard
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.7'
|
103
|
+
type: :development
|
52
104
|
prerelease: false
|
53
|
-
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
106
|
none: false
|
55
|
-
requirements:
|
107
|
+
requirements:
|
56
108
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version:
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '1.3'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '1.3'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: pry
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
59
135
|
type: :development
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
description: Store all of your times in the database as UTC but want to give your
|
144
|
+
users the ability to choose a custom time zone for each instance of a DateTime field?
|
145
|
+
email:
|
146
|
+
- jeff+greenwich@chirrpy.com
|
64
147
|
executables: []
|
65
|
-
|
66
148
|
extensions: []
|
67
|
-
|
68
|
-
extra_rdoc_files:
|
149
|
+
extra_rdoc_files:
|
69
150
|
- README.md
|
70
151
|
- LICENSE
|
71
|
-
files:
|
152
|
+
files:
|
72
153
|
- .gitignore
|
73
154
|
- .rspec
|
74
155
|
- .rvmrc
|
@@ -78,40 +159,50 @@ files:
|
|
78
159
|
- Rakefile
|
79
160
|
- greenwich.gemspec
|
80
161
|
- lib/greenwich.rb
|
81
|
-
- lib/greenwich/
|
82
|
-
- lib/greenwich/
|
162
|
+
- lib/greenwich/conversion.rb
|
163
|
+
- lib/greenwich/time_zone.rb
|
83
164
|
- lib/greenwich/utilities.rb
|
84
165
|
- lib/greenwich/version.rb
|
166
|
+
- spec/greenwich/conversion_spec.rb
|
85
167
|
- spec/greenwich/utilities_spec.rb
|
86
168
|
- spec/spec_helper.rb
|
87
|
-
|
88
|
-
|
169
|
+
- spec/support/focused.rb
|
170
|
+
- spec/support/pending.rb
|
171
|
+
homepage: http://github.com/chirrpy/greenwich
|
89
172
|
licenses: []
|
90
|
-
|
91
173
|
post_install_message:
|
92
|
-
rdoc_options:
|
174
|
+
rdoc_options:
|
93
175
|
- --charset = UTF-8
|
94
|
-
require_paths:
|
176
|
+
require_paths:
|
95
177
|
- lib
|
96
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
179
|
none: false
|
98
|
-
requirements:
|
99
|
-
- -
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version:
|
102
|
-
|
180
|
+
requirements:
|
181
|
+
- - ! '>='
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
hash: -1444067313011442519
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
188
|
none: false
|
104
|
-
requirements:
|
105
|
-
- -
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
version:
|
189
|
+
requirements:
|
190
|
+
- - ! '>='
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
hash: -1444067313011442519
|
108
196
|
requirements: []
|
109
|
-
|
110
197
|
rubyforge_project: greenwich
|
111
|
-
rubygems_version: 1.
|
198
|
+
rubygems_version: 1.8.24
|
112
199
|
signing_key:
|
113
200
|
specification_version: 3
|
114
201
|
summary: Allowing users to select dates with custom time zones since 2011.
|
115
|
-
test_files:
|
202
|
+
test_files:
|
203
|
+
- spec/greenwich/conversion_spec.rb
|
116
204
|
- spec/greenwich/utilities_spec.rb
|
117
205
|
- spec/spec_helper.rb
|
206
|
+
- spec/support/focused.rb
|
207
|
+
- spec/support/pending.rb
|
208
|
+
has_rdoc:
|