Class: Ldaptic::Syntaxes::GeneralizedTime
- Defined in:
- lib/ldaptic/syntaxes.rb
Overview
LDAP timestamps look like YYYYmmddHHMMSS.uuuuuuZ
.
Constant Summary collapse
- PATTERN =
/\A\d{14}(?:\.\d{1,6})?Z\z/
Constants inherited from Abstract
Instance Method Summary collapse
Methods inherited from Abstract
format, #initialize, parse, #printable?
Constructor Details
This class inherits a constructor from Ldaptic::Syntaxes::Abstract
Instance Method Details
#error(string) ⇒ Object
197 198 199 |
# File 'lib/ldaptic/syntaxes.rb', line 197 def error(string) 'must be a time' unless string =~ PATTERN end |
#format(value) ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/ldaptic/syntaxes.rb', line 201 def format(value) require 'time' if value.respond_to?(:to_str) && value !~ PATTERN && !Date._parse(value).empty? super(Time.parse(value)) else super end end |
#parse(string) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ldaptic/syntaxes.rb', line 184 def parse(string) require 'time' parseable = string.sub(/(\.\d+)?(\w)$/, '\\2') Time.parse(parseable) + $1.to_f rescue ArgumentError begin require 'date' DateTime.parse(parseable) + $1.to_f rescue ArgumentError Time.now end end |