Class: ActiveLdap::Schema::Syntaxes::GeneralizedTime
- Defined in:
- lib/active_ldap/schema/syntaxes.rb
Constant Summary collapse
- FORMAT =
/\A (\d{4,4})? (\d{2,2})? (\d{2,2})? (\d{2,2})? (\d{2,2})? (\d{2,2})? ([,.]\d+)? ([+-]\d{4,4}|Z)? \z/x
Constants inherited from Base
Base::PRINTABLE_CHARACTER, Base::SYNTAXES, Base::UNPRINTABLE_CHARACTER
Instance Method Summary collapse
Methods inherited from Base
Methods included from GetTextSupport
Instance Method Details
#normalize_value(value) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/active_ldap/schema/syntaxes.rb', line 198 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 normalized_value + ("%+03d%02d" % value.gmtoff.divmod(3600)) end else value end end |
#type_cast(value) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/active_ldap/schema/syntaxes.rb', line 179 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, 6] return value if required_components.any?(&:nil?) year, month, day, hour, minute, second = required_components.collect(&:to_i) fraction = match_data[-2] fraction = fraction.to_f if fraction time_zone = match_data[-1] Time.send(:make_time, year, month, day, hour, minute, second, fraction, time_zone, Time.now) else value end end |