NAME

Date::Transform - Efficiently transform between date formats.

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 excelllent Date::Manip it a superlative 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 transformations, e.g. going from YYYY-mm-dd to mm/dd/YYYY. While Date::Manip's UnixDate function can do this, its flexibility means slower operation.

When the input format is specified, the transformation can be greatly enhanced. Date::Transform provides this by creating a custom algorithm maximized for the specific transformation.

While a considerable initialization is required to derive the transformations, the transformations themselves show a 300-500% performance increase over Date::Manip.

METHODS

new

 new( $input_format, $output_format )

 Creates a new Date::Manip::Transform object.

 * $input_format is treated as a regular expression for matching the date to be transformed.  Thus
   '%b %d, %Y'  would succesfully transform the string, 'I came to California on Oct 15, 1992'.

 * See 'Supported Formats' for details on the supported format types.

 * All formats must be proceeded by '%'.

transform

transform( $date )

Returns a scalar of the supplied date in the format specified by the at object creation.

SUPPORTED FORMATS

a	weekday abbreviation                  Sun to Sat
A	Day of the Week                       Monday
b	Month abbreviation                    Jan to Dec
B	Month of the Year                     January ... December
c	Compound time format                  e.g. Fri Apr 28 17:23:15 1995
d	Day of the Month,                     e.g. 15
H	Hour of the day                       00-23
I	Hour of the day                       01 to 12
j	Day of the year                       0-365
m	month of year                         01 to 12
M	Minute                                00 to 59
p	AM or PM                              AM or PM
S	Second                                00 to 59
U	Week of year, Sunday as first day     01 to 53
w	Day of week                           1 (Monday) to 7 (Sunday)
W	Week of year, Monday as first day     01 to 53
x	Compound format                       e.g. 04/28/95
X	Time                                  e.g. 03:30:01 AM
Y	Year                                  e.g. 2002
Z	Time Zone                             e.g. Pacific Daylight Time

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.

AUTHOR

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

SEE ALSO

perl, Date::Manip, Switch, Posix::strftime

COPYRIGHT

Copyright (c) 2003 Christopher T. Brown.