DateTime::Format::LDAP - Parse and format LDAP datetime strings (Generalized Time)
version 0.002
use DateTime::Format::LDAP; my $dt = DateTime::Format::LDAP->parse_datetime( '20030117032900Z' ); # 20030117032900Z DateTime::Format::LDAP->format_datetime($dt);
This module understands the LDAP datetime formats, as defined in RFC 4517: Generalized Time. It can be used to parse these formats in order to create the appropriate objects. As this is a subset of GeneralizedTime from X.680 ASN.1 (namely, it does not allow local/floating) time, there is an option to allow this as well.
This class offers the following methods.
new(%options)
Options are boolean offset if you want offset time zones (-0500) instead of UTC (Z) for format_datetime, and asn1 if you want to be able to parse local/floating times. These can be combined:
offset
-0500
Z
format_datetime
asn1
my $dtf_ldap = DateTime::Format::LDAP->new(offset => 1, asn1 => 1);
Default is false for both.
parse_datetime($string)
Given an LDAP datetime string, this method will return a new DateTime object.
DateTime
If given an improperly formatted string, this method may die.
format_datetime($datetime)
Given a DateTime object, this methods returns an LDAP datetime string.
The LDAP spec requires that datetimes be formatted either as UTC (with a Z suffix) or with an offset (-0500), stating that the Z form SHOULD be used. This method will by default format using a Z suffix. Optionally, you can also pass a HASH to have it use an offset instead: {offset => 1}. If the DateTime object is a floating time, this method will die.
HASH
{offset => 1}
For example, this code:
my $dt = DateTime->new( year => 1900, hour => 15, time_zone => '-0100' ); print $ldap->format_datetime($dt);
will print the string "19000101160000Z". To use an offset:
print $ldap->format_datetime($dt, {offset => 1});
will print the string "19000101150000-0100".
Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details.
Ashley Willis <ashley+perl@gitable.org>
This module used DateTime::Format::ICal by Dave Rolsky and Flavio Soibelmann Glock as a starting point.
DateTime::Format::ICal
Copyright (c) 2014 Ashley Willis. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
datetime@perl.org mailing list
http://datetime.perl.org/
To install DateTime::Format::LDAP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTime::Format::LDAP
CPAN shell
perl -MCPAN -e shell install DateTime::Format::LDAP
For more information on module installation, please visit the detailed CPAN module installation guide.