lib/timeliness/definitions.rb in timeliness-0.3.7 vs lib/timeliness/definitions.rb in timeliness-0.3.8
- old
+ new
@@ -76,11 +76,13 @@
'ddd, dd mmm yyyy hh:nn:ss zo', # RFC 822
'ddd mmm d hh:nn:ss zo yyyy', # Ruby time string
'yyyy-mm-ddThh:nn:ssZ', # ISO 8601 without zone offset
'yyyy-mm-ddThh:nn:sszo', # ISO 8601 with zone offset
'yyyy-mm-ddThh:nn:ss.u', # ISO 8601 with usec
- 'yyyy-mm-ddThh:nn:ss.uzo' # ISO 8601 with usec and offset
+ 'yyyy-mm-ddThh:nn:ss.uzo', # ISO 8601 with usec and offset
+ 'yyyy-mm-dd hh:nn:ss zo', # Ruby time string in later versions
+ 'yyyy-mm-dd hh:nn:ss tz', # Ruby time string for UTC in later versions
]
# All tokens available for format construction. The token array is made of
# regexp and key for format component mapping, if any.
#
@@ -143,10 +145,12 @@
'EDT' => 'EST5EDT',
'MDT' => 'MST7MDT'
}
US_FORMAT_REGEXP = /\Am{1,2}[^m]/
+ FormatNotFound = Class.new(StandardError)
+ DuplicateFormat = Class.new(StandardError)
class << self
attr_accessor :time_formats, :date_formats, :datetime_formats, :format_tokens, :format_components, :timezone_mapping
attr_reader :date_format_set, :time_format_set, :datetime_format_set
@@ -158,14 +162,14 @@
#
def add_formats(type, *add_formats)
formats = send("#{type}_formats")
options = add_formats.last.is_a?(Hash) ? add_formats.pop : {}
before = options[:before]
- raise "Format for :before option #{format} was not found." if before && !formats.include?(before)
+ raise FormatNotFound, "Format for :before option #{before.inspect} was not found." if before && !formats.include?(before)
add_formats.each do |format|
- raise "Format #{format} is already included in #{type} formats" if formats.include?(format)
+ raise DuplicateFormat, "Format #{format.inspect} is already included in #{type.inspect} formats" if formats.include?(format)
index = before ? formats.index(before) : -1
formats.insert(index, format)
end
compile_formats
@@ -174,10 +178,10 @@
# Delete formats of specified type. Error raised if format not found.
#
def remove_formats(type, *remove_formats)
remove_formats.each do |format|
unless send("#{type}_formats").delete(format)
- raise "Format #{format} not found in #{type} formats"
+ raise FormatNotFound, "Format #{format.inspect} not found in #{type.inspect} formats"
end
end
compile_formats
end