Module: Treequel::TimeExtensions
- Included in:
- Time
- Defined in:
- lib/treequel/monkeypatches.rb
Overview
Extensions to the Time 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).
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/treequel/monkeypatches.rb', line 85 def ldap_generalized( fraction_digits=0 ) fractional_seconds = if fraction_digits == 0 '' elsif fraction_digits <= 6 '.' + sprintf('%06d', self.usec)[0, fraction_digits] else '.' + sprintf('%06d', self.usec) + '0' * (fraction_digits - 6) end tz = if self.utc? 'Z' else off = self.utc_offset sign = off < 0 ? '-' : '+' "%s%02d%02d" % [ sign, *(off.abs / 60).divmod(60) ] end return "%02d%02d%02d%02d%02d%02d%s%s" % [ self.year, self.mon, self.day, self.hour, self.min, self.sec, fractional_seconds, tz ] end |
#ldap_utc ⇒ Object
Returns self as a String formatted as specified in RFC4517 (UTC Time)
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/treequel/monkeypatches.rb', line 118 def ldap_utc tz = if self.utc? 'Z' else off = self.utc_offset sign = off < 0 ? '-' : '+' "%s%02d%02d" % [ sign, *(off.abs / 60).divmod(60) ] end return "%02d%02d%02d%02d%02d%02d%s" % [ self.year.divmod(100).last, self.mon, self.day, self.hour, self.min, self.sec, tz ] end |