Treequel::

TimeExtensions

module

Extensions to the Time class to add LDAP (RFC4517) Generalized Time syntax

Public Instance Methods

anchor
ldap_generalized( fraction_digits=0 )

Return self as a String formatted as specified in RFC4517 (LDAP Generalized Time).

# File lib/treequel/monkeypatches.rb, line 84
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
anchor
ldap_utc()

Returns self as a String formatted as specified in RFC4517 (UTC Time)

# File lib/treequel/monkeypatches.rb, line 117
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