package ReturnDate; use strict; use Date::Manip; use Carp; sub new { my $self = shift; return bless \$self; } sub Late { my $self = shift; return ( Date_Cmp($_[0], $_[1]) < 0 ) ? $_[1] : $_[0]; } sub Early { my $self = shift; return ( Date_Cmp($_[0], $_[1]) < 0 ) ? $_[0] : $_[1]; } sub Earliest { my $self = shift; return &GetDate('Early', @_); } sub Latest { my $self = shift; return &GetDate('Late', @_); } sub GetDate { my $operation = shift; my @dates = @_; my $date; for my $item ( @dates ) { my $d1 = $date || $item; my $d2 = $item; $date = ( $operation =~ /^Early$/ ) ? &Early( 1, $d1, $d2) : ( $operation =~ /^Late$/ ) ? &Late( 1, $d1, $d2) : u +ndef; } return $date or confess "Could not return from GetDate"; } sub Sorted { my $self = shift; my @dates = @_; my $sorted; my %dates; for (@dates) { $dates{UnixDate($_,"%s")} = $_; } push @{$sorted}, $dates{$_} for ( sort { $a<=>$b } keys %dates ); return $sorted; } 1; =head1 NAME ReturnDate - Date::Manip subclassed. =head1 SYNOPSYS unshift @INC, '/usr/local/perl/lib'; require ReturnDate; my $dateObj = ReturnDate->new(); my $early = $dateObj->Early('01/01/2000', '01/02/2007'); my $latest = $dateObj->Latest('01/01/2000', '01/02/2007', 'June 3, + 2010'); print "Early = $early\n"; print "Late = $late\n"; =head1 DESCRIPTION Simplifies the need to programatically figure out which date in a pair is earlier or later. =head2 Methods =over 12 =item C<new> Returns a ReturnDate object =item C<Early> Given two dates, returns the earlier of the two =item C<Late> Given two dates, returns the later of the two =item C<Earliest> Given a set of dates, returns the earliest =item C<Latest> Given a set of dates, returns the latest =item C<Sorted> Returns a date sorted array reference, which will accept a list of dates such as ( 'June 1, 2000', '1/2/2003', '02/22/1999' ) =back =head1 Author Ted Fiedler <fiedlert@gmail.com> =cut

In reply to ReturnDate.pm by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.