greenwich 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/.rspec +1 -0
- data/Gemfile.lock +68 -0
- data/Guardfile +15 -0
- data/greenwich.gemspec +7 -5
- data/lib/greenwich/conversion.rb +7 -0
- data/lib/greenwich/version.rb +1 -1
- data/spec/{greenwich/conversion_spec.rb → conversion_spec.rb} +43 -2
- data/spec/{greenwich/utilities_spec.rb → utilities_spec.rb} +0 -0
- metadata +55 -27
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
greenwich (2.0.0)
|
5
|
+
activerecord (~> 3.0)
|
6
|
+
activesupport (~> 3.0)
|
7
|
+
tzinfo (~> 0.3)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (3.2.8)
|
13
|
+
activesupport (= 3.2.8)
|
14
|
+
builder (~> 3.0.0)
|
15
|
+
activerecord (3.2.8)
|
16
|
+
activemodel (= 3.2.8)
|
17
|
+
activesupport (= 3.2.8)
|
18
|
+
arel (~> 3.0.2)
|
19
|
+
tzinfo (~> 0.3.29)
|
20
|
+
activesupport (3.2.8)
|
21
|
+
i18n (~> 0.6)
|
22
|
+
multi_json (~> 1.0)
|
23
|
+
arel (3.0.2)
|
24
|
+
awesome_print (1.1.0)
|
25
|
+
builder (3.0.0)
|
26
|
+
diff-lcs (1.1.3)
|
27
|
+
fuubar (1.1.0)
|
28
|
+
rspec (~> 2.0)
|
29
|
+
rspec-instafail (~> 0.2.0)
|
30
|
+
ruby-progressbar (~> 1.0.0)
|
31
|
+
guard (1.4.0)
|
32
|
+
listen (>= 0.4.2)
|
33
|
+
thor (>= 0.14.6)
|
34
|
+
guard-rspec (2.0.0)
|
35
|
+
guard (>= 1.1)
|
36
|
+
rspec (~> 2.11)
|
37
|
+
i18n (0.6.0)
|
38
|
+
listen (0.5.3)
|
39
|
+
multi_json (1.3.6)
|
40
|
+
rake (0.9.2.2)
|
41
|
+
rb-fsevent (0.9.2)
|
42
|
+
rspec (2.11.0)
|
43
|
+
rspec-core (~> 2.11.0)
|
44
|
+
rspec-expectations (~> 2.11.0)
|
45
|
+
rspec-mocks (~> 2.11.0)
|
46
|
+
rspec-core (2.11.1)
|
47
|
+
rspec-expectations (2.11.3)
|
48
|
+
diff-lcs (~> 1.1.3)
|
49
|
+
rspec-instafail (0.2.4)
|
50
|
+
rspec-mocks (2.11.3)
|
51
|
+
ruby-progressbar (1.0.2)
|
52
|
+
sqlite3 (1.3.6)
|
53
|
+
thor (0.16.0)
|
54
|
+
tzinfo (0.3.33)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
awesome_print (~> 1.1.0)
|
61
|
+
fuubar (~> 1.0)
|
62
|
+
greenwich!
|
63
|
+
guard (~> 1.4.0)
|
64
|
+
guard-rspec (~> 2.0.0)
|
65
|
+
rake
|
66
|
+
rb-fsevent (~> 0.9.1)
|
67
|
+
rspec (~> 2.11)
|
68
|
+
sqlite3 (~> 1.3)
|
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
notification :tmux,
|
2
|
+
:success => 'colour22',
|
3
|
+
:failed => 'colour52',
|
4
|
+
:display_message => true
|
5
|
+
|
6
|
+
guard 'rspec',
|
7
|
+
all_on_start: true,
|
8
|
+
all_after_pass: true,
|
9
|
+
cli: '--format Fuubar',
|
10
|
+
notification: true do
|
11
|
+
|
12
|
+
watch(%r{^(spec\/.+_spec\.rb)$}) { |m| m[1] }
|
13
|
+
watch(%r{^lib/greenwich\.rb$}) { |m| "spec/greenwich_spec.rb" }
|
14
|
+
watch(%r{^lib/greenwich/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
15
|
+
end
|
data/greenwich.gemspec
CHANGED
@@ -32,9 +32,11 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_dependency('activesupport', '~> 3.0')
|
33
33
|
s.add_dependency('tzinfo', '~> 0.3')
|
34
34
|
|
35
|
-
s.add_development_dependency
|
36
|
-
s.add_development_dependency
|
37
|
-
s.add_development_dependency
|
38
|
-
s.add_development_dependency
|
39
|
-
s.add_development_dependency
|
35
|
+
s.add_development_dependency 'rspec', '~> 2.11'
|
36
|
+
s.add_development_dependency 'fuubar', '~> 1.0'
|
37
|
+
s.add_development_dependency 'guard', '~> 1.4.0'
|
38
|
+
s.add_development_dependency 'guard-rspec', '~> 2.0.0'
|
39
|
+
s.add_development_dependency 'rb-fsevent', '~> 0.9.1'
|
40
|
+
s.add_development_dependency 'awesome_print', '~> 1.1.0'
|
41
|
+
s.add_development_dependency 'sqlite3', '~> 1.3'
|
40
42
|
end
|
data/lib/greenwich/conversion.rb
CHANGED
@@ -5,6 +5,7 @@ module Greenwich
|
|
5
5
|
module ClassMethods
|
6
6
|
def time_with_time_zone(utc_time_field, options = {})
|
7
7
|
time_field = utc_time_field.to_s.gsub /_utc$/, ''
|
8
|
+
date_field = time_field.gsub(/_at\Z/, '_on')
|
8
9
|
time_zone_field = options[:time_zone] || "#{time_field}_time_zone"
|
9
10
|
|
10
11
|
class_eval do
|
@@ -35,6 +36,12 @@ module Greenwich
|
|
35
36
|
write_attribute(utc_time_field, time)
|
36
37
|
end
|
37
38
|
|
39
|
+
define_method date_field do
|
40
|
+
return nil unless send(:"#{time_field}").respond_to? :to_date
|
41
|
+
|
42
|
+
send(:"#{time_field}").to_date
|
43
|
+
end
|
44
|
+
|
38
45
|
time_zone time_zone_field.to_sym, :for => utc_time_field.to_sym
|
39
46
|
end
|
40
47
|
|
data/lib/greenwich/version.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pry'
|
3
2
|
|
4
3
|
root = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
|
5
4
|
db_root = File.join(root, 'db')
|
6
5
|
|
7
6
|
Dir.mkdir(db_root) unless File.exists?(db_root)
|
8
7
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3',
|
9
|
-
:database => "#{db_root}/conversion.
|
8
|
+
:database => "#{db_root}/conversion.sqlite")
|
10
9
|
|
11
10
|
ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS 'model_with_time_zones'")
|
12
11
|
ActiveRecord::Base.connection.create_table(:model_with_time_zones) do |t|
|
@@ -43,6 +42,48 @@ describe Greenwich::Conversion do
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
45
|
+
describe '#date_field' do
|
46
|
+
let(:model) { ModelWithTimeZone.new }
|
47
|
+
let(:alaskan_time_zone) { ActiveSupport::TimeZone.new('Alaska') }
|
48
|
+
let(:raw_time_field) { model.send(:read_attribute, :started_at_utc) }
|
49
|
+
|
50
|
+
context 'when the time field is set' do
|
51
|
+
before { model.started_at_utc = Time.utc(2012, 1, 2, 2, 59, 1) }
|
52
|
+
|
53
|
+
context 'and the time zone is set' do
|
54
|
+
before { model.time_zone = alaskan_time_zone }
|
55
|
+
|
56
|
+
it 'is the proper date' do
|
57
|
+
model.started_on.should eql Date.new(2012, 1, 1)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'and the time zone is not set' do
|
62
|
+
it 'uses the default time zone to calculate the date' do
|
63
|
+
model.started_on.should eql Date.new(2012, 1, 2)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when the time field is not set' do
|
69
|
+
before { model.started_at_utc = nil }
|
70
|
+
|
71
|
+
context 'and the time zone is set' do
|
72
|
+
before { model.time_zone = alaskan_time_zone }
|
73
|
+
|
74
|
+
it 'is nil' do
|
75
|
+
model.started_on.should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'and the time zone is not set' do
|
80
|
+
it 'is nil' do
|
81
|
+
model.started_on.should be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
46
87
|
describe '#time_field_utc=' do
|
47
88
|
let(:model) { ModelWithTimeZone.new }
|
48
89
|
let(:alaskan_time_zone) { ActiveSupport::TimeZone.new('Alaska') }
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greenwich
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -61,7 +61,23 @@ dependencies:
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0.3'
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.11'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.11'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: fuubar
|
65
81
|
requirement: !ruby/object:Gem::Requirement
|
66
82
|
none: false
|
67
83
|
requirements:
|
@@ -77,13 +93,13 @@ dependencies:
|
|
77
93
|
- !ruby/object:Gem::Version
|
78
94
|
version: '1.0'
|
79
95
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
96
|
+
name: guard
|
81
97
|
requirement: !ruby/object:Gem::Requirement
|
82
98
|
none: false
|
83
99
|
requirements:
|
84
100
|
- - ~>
|
85
101
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
102
|
+
version: 1.4.0
|
87
103
|
type: :development
|
88
104
|
prerelease: false
|
89
105
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -91,15 +107,15 @@ dependencies:
|
|
91
107
|
requirements:
|
92
108
|
- - ~>
|
93
109
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
110
|
+
version: 1.4.0
|
95
111
|
- !ruby/object:Gem::Dependency
|
96
|
-
name:
|
112
|
+
name: guard-rspec
|
97
113
|
requirement: !ruby/object:Gem::Requirement
|
98
114
|
none: false
|
99
115
|
requirements:
|
100
116
|
- - ~>
|
101
117
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
118
|
+
version: 2.0.0
|
103
119
|
type: :development
|
104
120
|
prerelease: false
|
105
121
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -107,15 +123,15 @@ dependencies:
|
|
107
123
|
requirements:
|
108
124
|
- - ~>
|
109
125
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
126
|
+
version: 2.0.0
|
111
127
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
128
|
+
name: rb-fsevent
|
113
129
|
requirement: !ruby/object:Gem::Requirement
|
114
130
|
none: false
|
115
131
|
requirements:
|
116
132
|
- - ~>
|
117
133
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
134
|
+
version: 0.9.1
|
119
135
|
type: :development
|
120
136
|
prerelease: false
|
121
137
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -123,23 +139,39 @@ dependencies:
|
|
123
139
|
requirements:
|
124
140
|
- - ~>
|
125
141
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
142
|
+
version: 0.9.1
|
127
143
|
- !ruby/object:Gem::Dependency
|
128
|
-
name:
|
144
|
+
name: awesome_print
|
129
145
|
requirement: !ruby/object:Gem::Requirement
|
130
146
|
none: false
|
131
147
|
requirements:
|
132
|
-
- -
|
148
|
+
- - ~>
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.1.0
|
151
|
+
type: :development
|
152
|
+
prerelease: false
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ~>
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 1.1.0
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: sqlite3
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
133
165
|
- !ruby/object:Gem::Version
|
134
|
-
version: '
|
166
|
+
version: '1.3'
|
135
167
|
type: :development
|
136
168
|
prerelease: false
|
137
169
|
version_requirements: !ruby/object:Gem::Requirement
|
138
170
|
none: false
|
139
171
|
requirements:
|
140
|
-
- -
|
172
|
+
- - ~>
|
141
173
|
- !ruby/object:Gem::Version
|
142
|
-
version: '
|
174
|
+
version: '1.3'
|
143
175
|
description: Store all of your times in the database as UTC but want to give your
|
144
176
|
users the ability to choose a custom time zone for each instance of a DateTime field?
|
145
177
|
email:
|
@@ -154,6 +186,8 @@ files:
|
|
154
186
|
- .rspec
|
155
187
|
- .rvmrc
|
156
188
|
- Gemfile
|
189
|
+
- Gemfile.lock
|
190
|
+
- Guardfile
|
157
191
|
- LICENSE
|
158
192
|
- README.md
|
159
193
|
- Rakefile
|
@@ -163,11 +197,11 @@ files:
|
|
163
197
|
- lib/greenwich/time_zone.rb
|
164
198
|
- lib/greenwich/utilities.rb
|
165
199
|
- lib/greenwich/version.rb
|
166
|
-
- spec/
|
167
|
-
- spec/greenwich/utilities_spec.rb
|
200
|
+
- spec/conversion_spec.rb
|
168
201
|
- spec/spec_helper.rb
|
169
202
|
- spec/support/focused.rb
|
170
203
|
- spec/support/pending.rb
|
204
|
+
- spec/utilities_spec.rb
|
171
205
|
homepage: http://github.com/chirrpy/greenwich
|
172
206
|
licenses: []
|
173
207
|
post_install_message:
|
@@ -181,18 +215,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
215
|
- - ! '>='
|
182
216
|
- !ruby/object:Gem::Version
|
183
217
|
version: '0'
|
184
|
-
segments:
|
185
|
-
- 0
|
186
|
-
hash: -1444067313011442519
|
187
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
219
|
none: false
|
189
220
|
requirements:
|
190
221
|
- - ! '>='
|
191
222
|
- !ruby/object:Gem::Version
|
192
223
|
version: '0'
|
193
|
-
segments:
|
194
|
-
- 0
|
195
|
-
hash: -1444067313011442519
|
196
224
|
requirements: []
|
197
225
|
rubyforge_project: greenwich
|
198
226
|
rubygems_version: 1.8.24
|
@@ -200,9 +228,9 @@ signing_key:
|
|
200
228
|
specification_version: 3
|
201
229
|
summary: Allowing users to select dates with custom time zones since 2011.
|
202
230
|
test_files:
|
203
|
-
- spec/
|
204
|
-
- spec/greenwich/utilities_spec.rb
|
231
|
+
- spec/conversion_spec.rb
|
205
232
|
- spec/spec_helper.rb
|
206
233
|
- spec/support/focused.rb
|
207
234
|
- spec/support/pending.rb
|
235
|
+
- spec/utilities_spec.rb
|
208
236
|
has_rdoc:
|