mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
fixed up AR 2.0.x timezone support
This commit is contained in:
parent
9eddf9c130
commit
3cf6e64747
@ -26,7 +26,6 @@ module ValidatesTimeliness
|
|||||||
evaluate_attribute_method attr_name, method_body
|
evaluate_attribute_method attr_name, method_body
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO rails 2.0 time casting better with timezone
|
|
||||||
def define_write_method_for_time_zone_conversion(attr_name)
|
def define_write_method_for_time_zone_conversion(attr_name)
|
||||||
method_body = <<-EOV
|
method_body = <<-EOV
|
||||||
def #{attr_name}=(time)
|
def #{attr_name}=(time)
|
||||||
@ -34,7 +33,7 @@ module ValidatesTimeliness
|
|||||||
time = time.in_time_zone
|
time = time.in_time_zone
|
||||||
elsif time && time.acts_like?(:time)
|
elsif time && time.acts_like?(:time)
|
||||||
# Rails 2.0.x compatibility
|
# Rails 2.0.x compatibility
|
||||||
time = @@default_timezone == :utc ? time.to_time : time.to_time
|
time = @@default_timezone == :utc ? time.utc : time.localtime
|
||||||
end
|
end
|
||||||
write_attribute(:#{attr_name}, time)
|
write_attribute(:#{attr_name}, time)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,14 +33,17 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if ActiveRecord::VERSION::STRING < '2.1'
|
if ActiveRecord::VERSION::STRING < '2.1'
|
||||||
it "should return stored time string as Time with correct timezone" do
|
it "should return stored time string as Time with correct timezone" do
|
||||||
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
||||||
@person.birth_date_and_time.zone == Time.new.zone
|
@person.birth_date_and_time.zone == 'EST'
|
||||||
|
ActiveRecord::Base.default_timezone = :utc
|
||||||
|
@person.birth_date_and_time.zone == 'UTC'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless ActiveRecord::VERSION::STRING < '2.1'
|
unless ActiveRecord::VERSION::STRING < '2.1'
|
||||||
it "should return stored time string as Time with correct timezone" do
|
it "should return stored time string as Time with correct timezone" do
|
||||||
|
Time.zone = TimeZone['Sydney'] # no I'm not from Sydney but there is no Melbourne timezone!
|
||||||
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
@person.birth_date_and_time = "1980-12-25 01:02:03"
|
||||||
@person.birth_date_and_time.zone == Time.zone
|
@person.birth_date_and_time.zone == Time.zone
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user