Class Index [+]

Quicksearch

ActiveLdap::Schema::Syntaxes::GeneralizedTime

Constants

FORMAT

Public Instance Methods

normalize_value(value) click to toggle source
     # File lib/active_ldap/schema/syntaxes.rb, line 210
210:         def normalize_value(value)
211:           if value.is_a?(Time)
212:             normalized_value = value.strftime("%Y%m%d%H%M%S")
213:             if value.gmt?
214:               normalized_value + "Z"
215:             else
216:               normalized_value + ("%+03d%02d" % value.gmtoff.divmod(3600))
217:             end
218:           else
219:             value
220:           end
221:         end
type_cast(value) click to toggle source
     # File lib/active_ldap/schema/syntaxes.rb, line 179
179:         def type_cast(value)
180:           return value if value.nil? or value.is_a?(Time)
181:           match_data = FORMAT.match(value)
182:           if match_data
183:             required_components = match_data.to_a[1, 6]
184:             return value if required_components.any?(&:nil?)
185:             year, month, day, hour, minute, second =
186:               required_components.collect(&:to_i)
187:             fraction = match_data[2]
188:             fraction = fraction.to_f if fraction
189:             time_zone = match_data[1]
190:             begin
191:               Time.send(:make_time,
192:                         year, month, day, hour, minute, second, fraction,
193:                         time_zone, Time.now)
194:             rescue ArgumentError
195:               raise if year >= 1700
196:               out_of_range_messages = ["argument out of range",
197:                                        "time out of range"]
198:               raise unless out_of_range_messages.include?($!.message)
199:               Time.at(0)
200:             rescue RangeError
201:               raise if year >= 1700
202:               raise if $!.message != "bignum too big to convert into `long'"
203:               Time.at(0)
204:             end
205:           else
206:             value
207:           end
208:         end

Private Instance Methods

validate_normalized_value(value, original_value) click to toggle source
     # File lib/active_ldap/schema/syntaxes.rb, line 224
224:         def validate_normalized_value(value, original_value)
225:           match_data = FORMAT.match(value)
226:           if match_data
227:             year, month, day, hour, minute, second, fraction, time_zone =
228:               match_data.to_a[1..1]
229:             missing_components = []
230:             %(year month day hour minute second).each do |component|
231:               missing_components << component unless eval(component)
232:             end
233:             if missing_components.empty?
234:               nil
235:             else
236:               params = [original_value.inspect, missing_components.join(", ")]
237:               _("%s has missing components: %s") % params
238:             end
239:           else
240:             _("%s is invalid time format") % original_value.inspect
241:           end
242:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.