mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 23:06:42 +00:00
fix timezone issue for to_dummy_time as per normal Rails which uses AR default_timezone
This commit is contained in:
parent
dbfd9231b5
commit
bf999170d7
@ -14,10 +14,11 @@ require 'validates_timeliness/core_ext/date_time'
|
|||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
|
|
||||||
mattr_accessor :ignore_restriction_errors
|
mattr_accessor :ignore_restriction_errors
|
||||||
|
mattr_accessor :default_timezone
|
||||||
mattr_accessor :error_value_formats
|
mattr_accessor :error_value_formats
|
||||||
|
|
||||||
self.ignore_restriction_errors = false
|
self.ignore_restriction_errors = false
|
||||||
|
self.default_timezone = :utc
|
||||||
self.error_value_formats = {
|
self.error_value_formats = {
|
||||||
:time => '%H:%M:%S',
|
:time => '%H:%M:%S',
|
||||||
:date => '%Y-%m-%d',
|
:date => '%Y-%m-%d',
|
||||||
@ -61,6 +62,7 @@ module ValidatesTimeliness
|
|||||||
def setup_for_rails
|
def setup_for_rails
|
||||||
major, minor = Rails::VERSION::MAJOR, Rails::VERSION::MINOR
|
major, minor = Rails::VERSION::MAJOR, Rails::VERSION::MINOR
|
||||||
self.send("setup_for_rails_#{major}_#{minor}")
|
self.send("setup_for_rails_#{major}_#{minor}")
|
||||||
|
self.default_timezone = ::ActiveRecord::Base.default_timezone
|
||||||
rescue
|
rescue
|
||||||
raise "Rails version #{Rails::VERSION::STRING} not yet supported by validates_timeliness plugin"
|
raise "Rails version #{Rails::VERSION::STRING} not yet supported by validates_timeliness plugin"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module ValidatesTimeliness
|
|||||||
module Date
|
module Date
|
||||||
|
|
||||||
def to_dummy_time
|
def to_dummy_time
|
||||||
::Time.mktime(2000, 1, 1, 0, 0, 0)
|
::Time.send(ValidatesTimeliness.default_timezone, 2000, 1, 1, 0, 0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module ValidatesTimeliness
|
|||||||
module DateTime
|
module DateTime
|
||||||
|
|
||||||
def to_dummy_time
|
def to_dummy_time
|
||||||
::Time.mktime(2000, 1, 1, hour, min, sec)
|
::Time.send(ValidatesTimeliness.default_timezone, 2000, 1, 1, hour, min, sec)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,7 +3,7 @@ module ValidatesTimeliness
|
|||||||
module Time
|
module Time
|
||||||
|
|
||||||
def to_dummy_time
|
def to_dummy_time
|
||||||
self.class.mktime(2000, 1, 1, hour, min, sec)
|
self.class.send(ValidatesTimeliness.default_timezone, 2000, 1, 1, hour, min, sec)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,8 +5,8 @@ describe ValidatesTimeliness::CoreExtensions::Date do
|
|||||||
@a_date = Date.new(2008, 7, 1)
|
@a_date = Date.new(2008, 7, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should " do
|
it "should make a date value into a dummy time value" do
|
||||||
@a_date.to_dummy_time.should == Time.mktime(2000,1,1,0,0,0)
|
@a_date.to_dummy_time.should == Time.utc(2000,1,1,0,0,0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -15,8 +15,8 @@ describe ValidatesTimeliness::CoreExtensions::Time do
|
|||||||
@a_time = Time.mktime(2008, 7, 1, 2, 3, 4)
|
@a_time = Time.mktime(2008, 7, 1, 2, 3, 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should " do
|
it "should make a time value into a dummy time value" do
|
||||||
@a_time.to_dummy_time.should == Time.mktime(2000,1,1,2,3,4)
|
@a_time.to_dummy_time.should == Time.utc(2000,1,1,2,3,4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ describe ValidatesTimeliness::CoreExtensions::DateTime do
|
|||||||
@a_datetime = DateTime.new(2008, 7, 1, 2, 3, 4)
|
@a_datetime = DateTime.new(2008, 7, 1, 2, 3, 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should " do
|
it "should make a datetime value into a dummy time value" do
|
||||||
@a_datetime.to_dummy_time.should == Time.mktime(2000,1,1,2,3,4)
|
@a_datetime.to_dummy_time.should == Time.utc(2000,1,1,2,3,4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -29,13 +29,12 @@ require 'action_view'
|
|||||||
|
|
||||||
require 'spec/rails'
|
require 'spec/rails'
|
||||||
require 'time_travel/time_travel'
|
require 'time_travel/time_travel'
|
||||||
require 'validates_timeliness'
|
|
||||||
|
|
||||||
RAILS_VER = Rails::VERSION::STRING
|
|
||||||
|
|
||||||
puts "Using #{vendored ? 'vendored' : 'gem'} Rails version #{RAILS_VER} (ActiveRecord version #{ActiveRecord::VERSION::STRING})"
|
|
||||||
|
|
||||||
ActiveRecord::Base.default_timezone = :utc
|
ActiveRecord::Base.default_timezone = :utc
|
||||||
|
RAILS_VER = Rails::VERSION::STRING
|
||||||
|
puts "Using #{vendored ? 'vendored' : 'gem'} Rails version #{RAILS_VER} (ActiveRecord version #{ActiveRecord::VERSION::STRING})"
|
||||||
|
|
||||||
|
require 'validates_timeliness'
|
||||||
|
|
||||||
if RAILS_VER >= '2.1'
|
if RAILS_VER >= '2.1'
|
||||||
Time.zone_default = ActiveSupport::TimeZone['UTC']
|
Time.zone_default = ActiveSupport::TimeZone['UTC']
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user