class ActiveLdap::Schema::Syntaxes::GeneralizedTime
def normalize_value(value)
def normalize_value(value) if value.is_a?(Time) normalized_value = value.strftime("%Y%m%d%H%M%S") if value.gmt? normalized_value + "Z" else # for timezones with non-zero minutes, such as IST which is +0530, # divmod(3600) will give wrong value of 1800 offset = value.gmtoff / 60 # in minutes normalized_value + ("%+03d%02d" % offset.divmod(60)) end else value end end
def type_cast(value)
def type_cast(value) return value if value.nil? or value.is_a?(Time) match_data = FORMAT.match(value) if match_data required_components = match_data.to_a[1, 5] return value if required_components.any?(&:nil?) year, month, day, hour, minute = required_components.collect(&:to_i) second = match_data[-3].to_i fraction = match_data[-2] fraction = fraction.to_f if fraction time_zone = match_data[-1] arguments = [ value, year, month, day, hour, minute, second, fraction, time_zone, Time.now, ] if Time.method(:make_time).arity == 11 arguments[2, 0] = nil end begin Time.send(:make_time, *arguments) rescue ArgumentError raise if year >= 1700 out_of_range_messages = ["argument out of range", "time out of range"] raise unless out_of_range_messages.include?($!.message) Time.at(0) rescue RangeError raise if year >= 1700 raise if $!.message != "bignum too big to convert into `long'" Time.at(0) end else value end end
def validate_normalized_value(value, original_value)
def validate_normalized_value(value, original_value) match_data = FORMAT.match(value) if match_data date_data = match_data.to_a[1..-1] missing_components = [] required_components = %w(year month day hour minute) required_components.each_with_index do |component, i| missing_components << component unless date_data[i] end if missing_components.empty? nil else params = [original_value.inspect, missing_components.join(", ")] _("%s has missing components: %s") % params end else _("%s is invalid time format") % original_value.inspect end end