date sorting module

S

Sam

Hello
I just came from cpan, after doing some searches and before I get a module,
wanted to ask if any one out there knows of a module that takes an array of
dates and sort them regardless of the date formate.

thanks
 
A

Andreas Kahari

Hello
I just came from cpan, after doing some searches and before I get a module,
wanted to ask if any one out there knows of a module that takes an array of
dates and sort them regardless of the date formate.

If the dates doesn't follow any pattern, how could you sort it?
Compare for example the US date format with som eof the European
ones: Does one sort 9/7/2002 before or after 7/10/2002 if one
doesn't know what format they are on?
 
T

Tad McClellan

Sam said:
I just came from cpan, after doing some searches and before I get a module,
wanted to ask if any one out there knows of a module that takes an array of
dates and sort them regardless of the date formate.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can't.


How can you distinguish between these two formats for instance:

09-07-2003 # MM-DD-YYY - September 7
and
09-07-2003 # DD-MM-YYY - July 9

??
 
M

Mothra

Hi Sam,

Sam said:
Hello
I just came from cpan, after doing some searches and before I get a module,
wanted to ask if any one out there knows of a module that takes an array of
dates and sort them regardless of the date formate.

This might give you some ideas

use strict;
use warnings;
use DateTime;
my @new_dates;

my @dates =("Sat, 19 Jul 2003 15:53:45 -0500","1996-02-03","08-Feb-1998
14:15:29 GMT");


foreach my $new_date (@dates) {
push(@new_dates, DateTime::Format::Mytest->parse_datetime($new_date) );
}

print map {$_->datetime(), "\n"} sort @new_dates;



package DateTime::Format::Mytest;

use DateTime::Format::HTTP;
use DateTime::Format::Mail;


use DateTime::Format::Builder (
parsers => { parse_datetime => [
sub { eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) } },
sub { eval { DateTime::Format::Mail->parse_datetime( $_[1] ) } },
] }
);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top