added switching to euro date formats instead of US

This commit is contained in:
Adam Meehan
2008-07-20 08:38:34 +10:00
parent 5f55fad076
commit 70ba75a4ae
3 changed files with 47 additions and 3 deletions

View File

@@ -1,4 +1,3 @@
# TODO add support switching US to euro date formats
module ValidatesTimeliness
# A date and time format regular expression generator. Allows you to
@@ -230,8 +229,8 @@ module ValidatesTimeliness
# Adds new formats. Must specify format type and can specify a :before
# option to nominate which format the new formats should be inserted in
# front on to take higher precedence. Error is raise if format already
# exists or if :before format is not found.
# front on to take higher precedence.
# Error is raise if format already exists or if :before format is not found.
def add_formats(type, *add_formats)
formats = self.send("#{type}_formats")
options = {}
@@ -248,6 +247,17 @@ module ValidatesTimeliness
compile_format_expressions
end
# Removes formats where the 1 or 2 digit month comes first, to eliminate
# formats which are ambiguous with the European style of day then month.
# The mmm token is ignored as its not ambigous.
def remove_us_formats
us_format_regexp = /\Am{1,2}[^m]/
date_formats.reject! { |format| us_format_regexp =~ format }
datetime_formats.reject! { |format| us_format_regexp =~ format }
compile_format_expressions
end
def full_hour(hour, meridian)
hour = hour.to_i
return hour if meridian.nil?