mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +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
|
||||
end
|
||||
|
||||
# TODO rails 2.0 time casting better with timezone
|
||||
def define_write_method_for_time_zone_conversion(attr_name)
|
||||
method_body = <<-EOV
|
||||
def #{attr_name}=(time)
|
||||
@ -34,7 +33,7 @@ module ValidatesTimeliness
|
||||
time = time.in_time_zone
|
||||
elsif time && time.acts_like?(:time)
|
||||
# Rails 2.0.x compatibility
|
||||
time = @@default_timezone == :utc ? time.to_time : time.to_time
|
||||
time = @@default_timezone == :utc ? time.utc : time.localtime
|
||||
end
|
||||
write_attribute(:#{attr_name}, time)
|
||||
end
|
||||
|
||||
@ -35,12 +35,15 @@ describe ValidatesTimeliness::AttributeMethods do
|
||||
if ActiveRecord::VERSION::STRING < '2.1'
|
||||
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.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
|
||||
|
||||
unless ActiveRecord::VERSION::STRING < '2.1'
|
||||
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.zone == Time.zone
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user