Date::Transform - Efficiently transform dates.

- NAME
- SYNOPSIS
- DESCRIPTION
- METHODS
- SUPPORTED FORMATS
- NOTES
- EXPORT
- TODO
- AUTHOR
- COPYRIGHT
- SEE ALSO

# NAME

Date::Transform - Efficiently transform dates.

# SYNOPSIS

      use Date::Transform;

      $input_format         = '%x';        # e.g. 01/01/2001
      $output_format        = '%b %d, %Y'; # e.g. January 1, 2001

      $dt = new Date::Transform(
                    $input_format,
                    $output_format
      )

      $input_1   = '04/15/2001';
      $input_2   = '10/31/2001';

      $output_1  = $dt->transform($input_1); # Apr 15, 2001
      $output_2  = $dt->transform($input_2); # Oct 31, 2001

# DESCRIPTION

Sullivan Beck's Date::Manip is an excellent module for performing operations involving dates. However, because of its extraordinary flexibility, it is slow when much date parsing is needed.

I found that more than 95% of my operations using dates required repeated operations of going from YYYY-mm-dd to mm/dd/YYYY. This occurs often when changing an array or column of dates from one format to another. While Date::Manip `UnixDate` function can do this, its flexibility nature causes it to be slower than often needed.

When the input format is specified beforehand, parsing of the input date becomes much easier and the speed of the transformation can be greatly enhanced. Date::Transform provides this by writing a custom algorithm maximized to the specific operation. While a considerable initialization is required to creation the transformation code, the resultant transformation are typically 300-500% faster than `UnixDate`.

# METHODS

new( $input_format, $output_format )
  Creates a new Date::Manip::Transform object and initializes the `transform` function.

  `$input_format` is treated as a regular expression for matching. Thus,

  new('%b %d, %Y', '%Y-%m-%d') matches and transforms:

      'I came to California on Oct 15, 1992' ==> 'I came to California on 1992-10-15.

  See SUPPORTED FORMATS for details on the supported format types.

  All formats must be proceeded by `%`.

transform( $date )
  Transforms supplied `$date` value in the $input_format to the `$output_format` as specified when the Date::Transform object was created.

# SUPPORTED FORMATS

     %[A a B b c d H I J M m p S U w W x X Y Z]

Please see UnixDate in the Date::Manip manpage or Posix.

# NOTES

I would be happy to have this incorporated directly into Sullivan Beck's Date::Manip module.

# EXPORT

None by default.

# TODO

      + Speed transformation where a rearrangement of numbers is the only thing necessary
      + Implement a default using user parameters or localtime()
      + Multiple language support.
      + Incoporate %l format.
      + Allow specification of whether the date is to be replaced or simple extracted and transformed.
      + Specify Date Constants

# AUTHOR

Christopher Brown, chris.brown@cal.berkeley.edu

# COPYRIGHT

Copyright (c) 2003 Christopher T. Brown.

# SEE ALSO

perl, the Date::Manip manpage, Switch, Posix