dm-zone-types 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -1
- data/lib/dm-zone-types/version.rb +1 -1
- data/lib/dm-zone-types/zoned_time.rb +17 -11
- data/test/dm-zone-types/test_zoned_time.rb +8 -4
- data/test/test_helper.rb +1 -0
- metadata +27 -13
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,6 +4,10 @@ dependencies:
|
|
4
4
|
group:
|
5
5
|
- :default
|
6
6
|
version: ">= 0"
|
7
|
+
ruby-debug:
|
8
|
+
group:
|
9
|
+
- :default
|
10
|
+
version: ">= 0"
|
7
11
|
dm-validations:
|
8
12
|
group:
|
9
13
|
- :development
|
@@ -61,6 +65,8 @@ specs:
|
|
61
65
|
version: 0.9.26
|
62
66
|
- callsite:
|
63
67
|
version: 0.0.2
|
68
|
+
- columnize:
|
69
|
+
version: 0.3.1
|
64
70
|
- data_objects:
|
65
71
|
version: 0.10.2
|
66
72
|
- extlib:
|
@@ -81,12 +87,18 @@ specs:
|
|
81
87
|
version: 0.4.1
|
82
88
|
- json:
|
83
89
|
version: 1.4.3
|
90
|
+
- linecache:
|
91
|
+
version: "0.43"
|
84
92
|
- nanotest:
|
85
93
|
version: 0.9.4.1
|
86
94
|
- nanotest_extensions:
|
87
95
|
version: 0.6.3
|
88
96
|
- rainbow:
|
89
97
|
version: "1.1"
|
98
|
+
- ruby-debug-base:
|
99
|
+
version: 0.10.3
|
100
|
+
- ruby-debug:
|
101
|
+
version: 0.10.3
|
90
102
|
- thor:
|
91
103
|
version: 0.13.7
|
92
104
|
- versionomy:
|
@@ -97,7 +109,7 @@ specs:
|
|
97
109
|
version: 0.3.22
|
98
110
|
- watchr:
|
99
111
|
version: "0.6"
|
100
|
-
hash:
|
112
|
+
hash: 0b6c03727c1a61fac9b2854abc49cfc189b6c3bc
|
101
113
|
sources:
|
102
114
|
- Rubygems:
|
103
115
|
uri: http://gemcutter.org
|
@@ -6,8 +6,9 @@ module DataMapper
|
|
6
6
|
class ZonedTime < Time
|
7
7
|
include DataMapper::Zone::Types
|
8
8
|
|
9
|
-
def valid?(value)
|
10
|
-
value.kind_of?(::Time) || value.nil?
|
9
|
+
def valid?(value, negated = false)
|
10
|
+
response = value.kind_of?(::Time) || value.nil? || value.kind_of?(::Range)
|
11
|
+
negated ? !response : response
|
11
12
|
end
|
12
13
|
|
13
14
|
def load(value)
|
@@ -16,23 +17,28 @@ module DataMapper
|
|
16
17
|
|
17
18
|
def dump(value)
|
18
19
|
return nil unless value
|
19
|
-
|
20
|
+
zone = DataMapper::Zone::Types.storage_zone
|
21
|
+
if value.respond_to?(:in_time_zone)
|
22
|
+
time_with_zone_to_primitive value.in_time_zone(zone)
|
23
|
+
elsif ::Range === value
|
24
|
+
if value.first.respond_to?(:in_time_zone) && value.last.respond_to?(:in_time_zone)
|
25
|
+
((time_with_zone_to_primitive(value.first.in_time_zone(zone)))..(time_with_zone_to_primitive(value.last.in_time_zone(zone))))
|
26
|
+
else
|
27
|
+
value
|
28
|
+
end
|
29
|
+
else
|
30
|
+
value
|
31
|
+
end
|
20
32
|
end
|
21
33
|
|
22
34
|
def typecast(value)
|
23
35
|
case value
|
24
36
|
when ::String
|
25
37
|
::Time.zone.parse(value)
|
26
|
-
when ::DateTime
|
27
|
-
value.in_time_zone
|
28
|
-
when ::Time
|
29
|
-
value.in_time_zone
|
30
38
|
when ::Date
|
31
39
|
value.to_time.in_time_zone
|
32
|
-
|
33
|
-
value.in_time_zone
|
34
|
-
when NilClass
|
35
|
-
nil
|
40
|
+
else
|
41
|
+
value.respond_to?(:in_time_zone) ? value.in_time_zone : value
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
@@ -85,11 +85,15 @@ context do
|
|
85
85
|
model.zoned_time.zone.must == t.zone
|
86
86
|
end
|
87
87
|
|
88
|
-
# should
|
88
|
+
# should let me search for models within a range
|
89
89
|
test do
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
t = Time.zone.now
|
91
|
+
[0,1,2,3,4,5].each do |d|
|
92
|
+
SpecModel.create(:zoned_time => (t - d.days))
|
93
|
+
end
|
94
|
+
|
95
|
+
results = SpecModel.all(:zoned_time => ((t - 2.days)..t))
|
96
|
+
results.size.must == 3
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end # tz's
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-zone-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Neighman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-06 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -74,9 +74,9 @@ dependencies:
|
|
74
74
|
- 0
|
75
75
|
version: "0"
|
76
76
|
requirement: *id004
|
77
|
-
name:
|
77
|
+
name: ruby-debug
|
78
78
|
prerelease: false
|
79
|
-
type: :
|
79
|
+
type: :runtime
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
@@ -88,7 +88,7 @@ dependencies:
|
|
88
88
|
- 0
|
89
89
|
version: "0"
|
90
90
|
requirement: *id005
|
91
|
-
name:
|
91
|
+
name: tumbler
|
92
92
|
prerelease: false
|
93
93
|
type: :development
|
94
94
|
- !ruby/object:Gem::Dependency
|
@@ -102,7 +102,7 @@ dependencies:
|
|
102
102
|
- 0
|
103
103
|
version: "0"
|
104
104
|
requirement: *id006
|
105
|
-
name:
|
105
|
+
name: nanotest
|
106
106
|
prerelease: false
|
107
107
|
type: :development
|
108
108
|
- !ruby/object:Gem::Dependency
|
@@ -116,7 +116,7 @@ dependencies:
|
|
116
116
|
- 0
|
117
117
|
version: "0"
|
118
118
|
requirement: *id007
|
119
|
-
name:
|
119
|
+
name: nanotest_extensions
|
120
120
|
prerelease: false
|
121
121
|
type: :development
|
122
122
|
- !ruby/object:Gem::Dependency
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
- 0
|
131
131
|
version: "0"
|
132
132
|
requirement: *id008
|
133
|
-
name:
|
133
|
+
name: watchr
|
134
134
|
prerelease: false
|
135
135
|
type: :development
|
136
136
|
- !ruby/object:Gem::Dependency
|
@@ -144,7 +144,7 @@ dependencies:
|
|
144
144
|
- 0
|
145
145
|
version: "0"
|
146
146
|
requirement: *id009
|
147
|
-
name:
|
147
|
+
name: rake
|
148
148
|
prerelease: false
|
149
149
|
type: :development
|
150
150
|
- !ruby/object:Gem::Dependency
|
@@ -158,7 +158,7 @@ dependencies:
|
|
158
158
|
- 0
|
159
159
|
version: "0"
|
160
160
|
requirement: *id010
|
161
|
-
name: dm-
|
161
|
+
name: dm-sqlite-adapter
|
162
162
|
prerelease: false
|
163
163
|
type: :development
|
164
164
|
- !ruby/object:Gem::Dependency
|
@@ -172,7 +172,7 @@ dependencies:
|
|
172
172
|
- 0
|
173
173
|
version: "0"
|
174
174
|
requirement: *id011
|
175
|
-
name:
|
175
|
+
name: dm-migrations
|
176
176
|
prerelease: false
|
177
177
|
type: :development
|
178
178
|
- !ruby/object:Gem::Dependency
|
@@ -186,6 +186,20 @@ dependencies:
|
|
186
186
|
- 0
|
187
187
|
version: "0"
|
188
188
|
requirement: *id012
|
189
|
+
name: i18n
|
190
|
+
prerelease: false
|
191
|
+
type: :development
|
192
|
+
- !ruby/object:Gem::Dependency
|
193
|
+
version_requirements: &id013 !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
hash: 3
|
199
|
+
segments:
|
200
|
+
- 0
|
201
|
+
version: "0"
|
202
|
+
requirement: *id013
|
189
203
|
name: dm-validations
|
190
204
|
prerelease: false
|
191
205
|
type: :development
|