Class: DataMapper::Property::ZonedTime
- Inherits:
-
Time
- Object
- Time
- DataMapper::Property::ZonedTime
show all
- Includes:
- Zone::Types
- Defined in:
- lib/dm-zone-types/zoned_time.rb
Instance Method Summary
collapse
storage_zone, storage_zone=
Instance Method Details
#dump(value) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/dm-zone-types/zoned_time.rb', line 18
def dump(value)
return nil unless value
zone = DataMapper::Zone::Types.storage_zone
if value.respond_to?(:in_time_zone)
time_with_zone_to_primitive value.in_time_zone(zone)
elsif ::Range === value
if value.first.respond_to?(:in_time_zone) && value.last.respond_to?(:in_time_zone)
((time_with_zone_to_primitive(value.first.in_time_zone(zone)))..(time_with_zone_to_primitive(value.last.in_time_zone(zone))))
else
value
end
else
value
end
end
|
#load(value) ⇒ Object
14
15
16
|
# File 'lib/dm-zone-types/zoned_time.rb', line 14
def load(value)
value.nil? ? nil : value.in_time_zone(::Time.zone)
end
|
#typecast(value) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/dm-zone-types/zoned_time.rb', line 34
def typecast(value)
case value
when ::String
::Time.zone.parse(value)
when ::Date
value.to_time.in_time_zone
else
value.respond_to?(:in_time_zone) ? value.in_time_zone : value
end
end
|
#valid?(value, negated = false) ⇒ Boolean
9
10
11
12
|
# File 'lib/dm-zone-types/zoned_time.rb', line 9
def valid?(value, negated = false)
response = value.kind_of?(::Time) || value.nil? || value.kind_of?(::Range)
negated ? !response : response
end
|