greenwich 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/greenwich/rails.rb +7 -11
- data/lib/greenwich/utilities.rb +12 -0
- data/lib/greenwich/version.rb +1 -1
- metadata +10 -10
data/lib/greenwich/rails.rb
CHANGED
@@ -26,7 +26,7 @@ module Greenwich #:nodoc:
|
|
26
26
|
ActiveSupport::TimeWithZone.new(nil, time_zone, time)
|
27
27
|
},
|
28
28
|
:converter => Proc.new { |value|
|
29
|
-
value[1] =
|
29
|
+
value[1] = Greenwich::Utilities.get_time_zone_from(value[1])
|
30
30
|
value[0] = value[0].to_time
|
31
31
|
|
32
32
|
ActiveSupport::TimeWithZone.new(nil, value[1], value[0])
|
@@ -34,13 +34,10 @@ module Greenwich #:nodoc:
|
|
34
34
|
|
35
35
|
define_method "#{time_field}=" do |time|
|
36
36
|
instance_eval do
|
37
|
-
|
37
|
+
write_attribute(time_field, time.to_s)
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
else
|
42
|
-
self.send("#{name}=".to_sym, [time, time_zone])
|
43
|
-
end
|
39
|
+
time_zone = read_attribute(time_zone)
|
40
|
+
self.send("#{name}=".to_sym, [time, time_zone]) if time && time_zone
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
@@ -56,15 +53,14 @@ module Greenwich #:nodoc:
|
|
56
53
|
ActiveSupport::TimeZone.new(time_zone_name) unless time_zone_name.nil?
|
57
54
|
end
|
58
55
|
|
59
|
-
define_method "#{name}=" do |
|
56
|
+
define_method "#{name}=" do |time_zone_string|
|
60
57
|
instance_eval do
|
61
|
-
time_zone =
|
62
|
-
time_zone = time_zone.name if time_zone.respond_to? :name
|
58
|
+
time_zone = Greenwich::Utilities.get_time_zone_from(time_zone_string).try(:name)
|
63
59
|
write_attribute(name, time_zone)
|
64
60
|
|
65
61
|
options[:for].each do |composed_field, time_field|
|
66
62
|
time = read_attribute(time_field)
|
67
|
-
self.send("#{composed_field}=".to_sym, [time, time_zone])
|
63
|
+
self.send("#{composed_field}=".to_sym, [time, time_zone]) if time && time_zone
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
data/lib/greenwich/utilities.rb
CHANGED
@@ -12,6 +12,18 @@ module Greenwich
|
|
12
12
|
get_target_column(target_columns, columns)
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.get_time_zone_from(value)
|
16
|
+
return nil if [nil, ''].include? value
|
17
|
+
|
18
|
+
begin
|
19
|
+
value = ActiveSupport::TimeZone.new(value) unless value.is_a? ActiveSupport::TimeZone
|
20
|
+
rescue ArgumentError
|
21
|
+
raise ArgumentError, "'#{value}' cannot be converted into a TimeZone."
|
22
|
+
end
|
23
|
+
|
24
|
+
value
|
25
|
+
end
|
26
|
+
|
15
27
|
private
|
16
28
|
def self.get_target_column(target_columns, all_columns)
|
17
29
|
target_columns.each {|col| return col if all_columns.include?(col) }
|
data/lib/greenwich/version.rb
CHANGED
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: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,12 +10,12 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-31 00:00:00.000000000 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
18
|
-
requirement: &
|
18
|
+
requirement: &2172743720 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '3.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *2172743720
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
|
-
requirement: &
|
29
|
+
requirement: &2172743220 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '1.0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *2172743220
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &2172742760 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: '2.6'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *2172742760
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: yard
|
51
|
-
requirement: &
|
51
|
+
requirement: &2172742300 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ~>
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version: '0.7'
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *2172742300
|
60
60
|
description: Store all of your times in the database as UTC but want to give your
|
61
61
|
users the ability to choose a custom time zone for each instance of a DateTime field?
|
62
62
|
email:
|