The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DateTime::Format::LDAP - Parse and format LDAP datetime strings (Generalized Time)

VERSION

version 0.002

SYNOPSIS

  use DateTime::Format::LDAP;

  my $dt = DateTime::Format::LDAP->parse_datetime( '20030117032900Z' );

  # 20030117032900Z
  DateTime::Format::LDAP->format_datetime($dt);

DESCRIPTION

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.

METHODS

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:

        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.

    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.

    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

Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details.

AUTHORS

Ashley Willis <ashley+perl@gitable.org>

This module used DateTime::Format::ICal by Dave Rolsky and Flavio Soibelmann Glock as a starting point.

COPYRIGHT

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.

SEE ALSO

datetime@perl.org mailing list

http://datetime.perl.org/