Class::Date

  • Thread starter Alexandre Jaquet
  • Start date
A

Alexandre Jaquet

Hi again, I can't understand why when I do the following code :

sub getTime {

my $date = new Class::Date ();
$Class::Date::DATE_FORMAT="%H%M%S%X%Y";
warn "date hour test ->".now;
$date = now;
return $date;
}

I got the following output :
date hour test ->12033612:03:362005

I'm trying to get 12:03:362005

My second question is why when I calculate the difference between two
dates I only got the difference :

sub differenceBetweenHour {
my $time_start = shift || '';
my $time_end = shift || '';
$Class::Date::DATE_FORMAT="%H%M%S%X%Y";
my $result = $time_end - $time_start;
warn "test minus $result";
return $result;

}

I got : test minus 1 (it doesn't calculte difference between miilisecond)

thx
 
B

Brian McCauley

Alexandre said:
Hi again, I can't understand why when I do the following code :

sub getTime {

my $date = new Class::Date ();
$Class::Date::DATE_FORMAT="%H%M%S%X%Y";
warn "date hour test ->".now;
$date = now;
return $date;
}

I got the following output :
date hour test ->12033612:03:362005

That's what to asked for. Hours, minutes, seconds, then the full time
again.
I'm trying to get 12:03:362005

Then remove from your DATE_FORMAT the extra leading guff that generates
the '120336'.
My second question is why when I calculate the difference between two
dates I only got the difference :

sub differenceBetweenHour {
my $time_start = shift || '';
my $time_end = shift || '';
$Class::Date::DATE_FORMAT="%H%M%S%X%Y";
my $result = $time_end - $time_start;
warn "test minus $result";
return $result;

}

I got : test minus 1 (it doesn't calculte difference between miilisecond)

Please produce a minmal but complete script to illustrate your point.

What do you think is the purpose of the || '' in the above code? If
you don't think it has any purpose (I don't think it has any) then
remove it. Remember always write less code unless this would make your
code less readable.

Note: if you manipulate globals inside subroutines then you should
usually use local(). Not that I can understand why you manipulate
$Class::Date::DATE_FORMAT at all since nothing in that subroutine
involves the stringification of Class::Data objects.
 

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
474,169
Messages
2,570,919
Members
47,458
Latest member
Chris#

Latest Threads

Top