mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3e235a8a1 | ||
|
|
71583805c8 | ||
|
|
2ee971623c | ||
|
|
817e49940c | ||
|
|
a76fc112e7 | ||
|
|
575ff85346 | ||
|
|
7ed76b5161 | ||
|
|
65ed8a657e |
@@ -1,3 +1,9 @@
|
|||||||
|
= 1.1.5 [2009-01-21]
|
||||||
|
- Fixed regex for 'yy' format token which wasn't greedy enough for date formats ending with year when a datetime string parsed as date with a 4 digit year
|
||||||
|
|
||||||
|
= 1.1.4 [2009-01-13]
|
||||||
|
- Make months names respect i18n in Formats
|
||||||
|
|
||||||
= 1.1.3 [2009-01-13]
|
= 1.1.3 [2009-01-13]
|
||||||
- Fixed bug where time and date attributes still being parsed on read using Rails default parser [reported by Brad (pvjq)]
|
- Fixed bug where time and date attributes still being parsed on read using Rails default parser [reported by Brad (pvjq)]
|
||||||
|
|
||||||
|
|||||||
2
Rakefile
2
Rakefile
@@ -5,7 +5,7 @@ require 'date'
|
|||||||
require 'spec/rake/spectask'
|
require 'spec/rake/spectask'
|
||||||
|
|
||||||
GEM = "validates_timeliness"
|
GEM = "validates_timeliness"
|
||||||
GEM_VERSION = "1.1.3"
|
GEM_VERSION = "1.1.5"
|
||||||
AUTHOR = "Adam Meehan"
|
AUTHOR = "Adam Meehan"
|
||||||
EMAIL = "adam.meehan@gmail.com"
|
EMAIL = "adam.meehan@gmail.com"
|
||||||
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
|
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
|
||||||
|
|||||||
1
TODO
1
TODO
@@ -1,5 +1,4 @@
|
|||||||
- :format option
|
- :format option
|
||||||
- :with_date and :with_time options
|
- :with_date and :with_time options
|
||||||
- valid formats could come from locale file
|
- valid formats could come from locale file
|
||||||
- formats to use month and day names from i18n
|
|
||||||
- add replace_formats instead add_formats :before
|
- add replace_formats instead add_formats :before
|
||||||
|
|||||||
@@ -53,11 +53,10 @@ 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.default_timezone = ::ActiveRecord::Base.default_timezone
|
self.default_timezone = ::ActiveRecord::Base.default_timezone
|
||||||
|
self.send("setup_for_rails_#{major}_#{minor}")
|
||||||
rescue
|
rescue
|
||||||
puts "Rails version #{Rails::VERSION::STRING} not explicitly supported by validates_timeliness plugin. You may encounter some problems."
|
puts "Rails version #{major}.#{minor}.x not explicitly supported by validates_timeliness plugin. You may encounter some problems."
|
||||||
resume
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ module ValidatesTimeliness
|
|||||||
def define_write_method_for_dates_and_times(attr_name, type, time_zone_aware)
|
def define_write_method_for_dates_and_times(attr_name, type, time_zone_aware)
|
||||||
method_body = <<-EOV
|
method_body = <<-EOV
|
||||||
def #{attr_name}=(value)
|
def #{attr_name}=(value)
|
||||||
write_date_time_attribute('#{attr_name}', value, #{type.inspect}, #{time_zone_aware})
|
write_date_time_attribute('#{attr_name}', value, #{type.inspect}, #{time_zone_aware})
|
||||||
end
|
end
|
||||||
EOV
|
EOV
|
||||||
evaluate_attribute_method attr_name, method_body, "#{attr_name}="
|
evaluate_attribute_method attr_name, method_body, "#{attr_name}="
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
require 'date'
|
||||||
|
|
||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
|
|
||||||
# A date and time format regular expression generator. Allows you to
|
# A date and time format regular expression generator. Allows you to
|
||||||
@@ -113,7 +115,7 @@ module ValidatesTimeliness
|
|||||||
{ 'mm' => [ /m{2}/, '(\d{2})', :month ] },
|
{ 'mm' => [ /m{2}/, '(\d{2})', :month ] },
|
||||||
{ 'm' => [ /(\A|[^ap])m{1}/, '(\d{1,2})', :month ] },
|
{ 'm' => [ /(\A|[^ap])m{1}/, '(\d{1,2})', :month ] },
|
||||||
{ 'yyyy' => [ /y{4,}/, '(\d{4})', :year ] },
|
{ 'yyyy' => [ /y{4,}/, '(\d{4})', :year ] },
|
||||||
{ 'yy' => [ /y{2,}/, '(\d{2}|\d{4})', :year ] },
|
{ 'yy' => [ /y{2,}/, '(\d{4}|\d{2})', :year ] },
|
||||||
{ 'hh' => [ /h{2,}/, '(\d{2})', :hour ] },
|
{ 'hh' => [ /h{2,}/, '(\d{2})', :hour ] },
|
||||||
{ 'h' => [ /h{1}/, '(\d{1,2})', :hour ] },
|
{ 'h' => [ /h{1}/, '(\d{1,2})', :hour ] },
|
||||||
{ 'nn' => [ /n{2,}/, '(\d{2})', :min ] },
|
{ 'nn' => [ /n{2,}/, '(\d{2})', :min ] },
|
||||||
@@ -297,9 +299,17 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
def month_index(month)
|
def month_index(month)
|
||||||
return month.to_i if month.to_i.nonzero?
|
return month.to_i if month.to_i.nonzero?
|
||||||
Date::ABBR_MONTHNAMES.index(month.capitalize) || Date::MONTHNAMES.index(month.capitalize)
|
abbr_month_names.index(month.capitalize) || month_names.index(month.capitalize)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def month_names
|
||||||
|
defined?(I18n) ? I18n.t('date.month_names') : Date::MONTHNAMES
|
||||||
|
end
|
||||||
|
|
||||||
|
def abbr_month_names
|
||||||
|
defined?(I18n) ? I18n.t('date.abbr_month_names') : Date::ABBR_MONTHNAMES
|
||||||
|
end
|
||||||
|
|
||||||
def microseconds(usec)
|
def microseconds(usec)
|
||||||
(".#{usec}".to_f * 1_000_000).to_i
|
(".#{usec}".to_f * 1_000_000).to_i
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -157,11 +157,16 @@ describe ValidatesTimeliness::Formats do
|
|||||||
time_array = formats.parse('2000-02-01', :datetime, false)
|
time_array = formats.parse('2000-02-01', :datetime, false)
|
||||||
time_array.should == [2000,2,1,0,0,0,0]
|
time_array.should == [2000,2,1,0,0,0,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should ignore time when extracting date and strict is false" do
|
it "should ignore time when extracting date and strict is false" do
|
||||||
time_array = formats.parse('2000-02-01 12:12', :date, false)
|
time_array = formats.parse('2000-02-01 12:12', :date, false)
|
||||||
time_array.should == [2000,2,1,0,0,0,0]
|
time_array.should == [2000,2,1,0,0,0,0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should ignore time when extracting date from format with trailing year and strict is false" do
|
||||||
|
time_array = formats.parse('01-02-2000 12:12', :date, false)
|
||||||
|
time_array.should == [2000,2,1,0,0,0,0]
|
||||||
|
end
|
||||||
|
|
||||||
it "should ignore date when extracting time and strict is false" do
|
it "should ignore date when extracting time and strict is false" do
|
||||||
time_array = formats.parse('2000-02-01 12:12', :time, false)
|
time_array = formats.parse('2000-02-01 12:12', :time, false)
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{validates_timeliness}
|
s.name = %q{validates_timeliness}
|
||||||
s.version = "1.1.3"
|
s.version = "1.1.5"
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Adam Meehan"]
|
s.authors = ["Adam Meehan"]
|
||||||
s.autorequire = %q{validates_timeliness}
|
s.autorequire = %q{validates_timeliness}
|
||||||
s.date = %q{2009-01-13}
|
s.date = %q{2009-01-21}
|
||||||
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||||
s.email = %q{adam.meehan@gmail.com}
|
s.email = %q{adam.meehan@gmail.com}
|
||||||
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
||||||
|
|||||||
Reference in New Issue
Block a user