[ABE.pm] time processing

Ricardo SIGNES perl.abe at rjbs.manxome.org
Mon Nov 19 09:31:36 PST 2007


* Ted Fiedler <fiedlert at gmail.com> [2007-11-19T11:58:27]
> Im working on some programs to help me w/ running, producing graphs etc... I
> need to convert time to seconds, do some simple math, then convert back to a
> hh::mm::ss format. Im using DateTime::Precise to convert back, im just
> curious and have been unable to find a way myself if there is a better way?
> ie pure Perl. This just *seems* clunky.

Why Precise?  That seems like overkill.

> my ( $hour, $min, $sec, undef ) = split/:/, $ARGV[0];
> 
> $hour = $hour * 3600;
> $min  = $min  * 60;
> 
> my $seconds = $hour + $min + $sec;
> 
> my $distance = $ARGV[1];
> 
> print "seconds = $seconds\n";
> 
> my $t1 = DateTime::Precise->new($seconds / $distance);

Ugh!

  my $hms = DateTime::Format::Strptime->new(pattern => '%T');
  my $datetime = $hms->parse_datetime('12:23:34');

-- 
rjbs


More information about the ABE-pm mailing list