Module: Treequel::DateExtensions
- Included in:
- Date
- Defined in:
- lib/treequel/monkeypatches.rb
Overview
Extensions to the Date class to add LDAP (RFC4517) Generalized Time syntax
Instance Method Summary collapse
-
#ldap_generalized(fraction_digits = 0) ⇒ Object
Return
selfas a String formatted as specified in RFC4517 (LDAP Generalized Time). -
#ldap_utc ⇒ Object
Returns
selfas a String formatted as specified in RFC4517 (UTC Time).
Instance Method Details
#ldap_generalized(fraction_digits = 0) ⇒ Object
Return self as a String formatted as specified in RFC4517 (LDAP Generalized Time).
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/treequel/monkeypatches.rb', line 151 def ldap_generalized( fraction_digits=0 ) fractional_seconds = if fraction_digits == 0 '' else '.' + ('0' * fraction_digits) end off = Time.now.utc_offset sign = off < 0 ? '-' : '+' tz = "%s%02d%02d" % [ sign, *(off.abs / 60).divmod(60) ] return "%02d%02d%02d%02d%02d%02d%s%s" % [ self.year, self.mon, self.day, 0, 0, 1, fractional_seconds, tz ] end |
#ldap_utc ⇒ Object
Returns self as a String formatted as specified in RFC4517 (UTC Time)
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/treequel/monkeypatches.rb', line 178 def ldap_utc off = Time.now.utc_offset sign = off < 0 ? '-' : '+' tz = "%s%02d%02d" % [ sign, *(off.abs / 60).divmod(60) ] return "%02d%02d%02d%02d%02d%02d%s" % [ self.year.divmod(100).last, self.mon, self.day, 0, 0, 1, tz ] end |