Treequel::

DateExtensions

module

Extensions to the Date 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 150
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
anchor
ldap_utc()

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

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