[ABE.pm] time processing
Ted Fiedler
fiedlert at gmail.com
Mon Nov 19 08:58:27 PST 2007
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.
#!/usr/bin/perl
use strict;
use warnings;
use DateTime::Precise ;
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);
my $pace = $t1->strftime('%T');
$pace =~ s/^00://;
print "Pace is $pace\n";
sub usage
{
print "$0 time dist\n";
print " eg $0 01:54:18 13.1\n";
exit 1;
}
Ted
--
If you mess with a thing long enough, it'll break.
-- Schmidt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/abe-pm/attachments/20071119/916f4adb/attachment.html
More information about the ABE-pm
mailing list