Hello Monks,
I want to store times (hours, minutes, seconds, fractions of a second) in an object. Time::Piece and Time::Seconds make a good beginning. They offer some arithmetic operations and have overloaded >, <, ... .
The following code uses Time::Seconds and Time::Piece to construct the sum of "16:51" and "34:48" in the format (min:sec).
#!/usr/bin/perl use strict; use warnings; use Time::Piece; use Time::Seconds; my $t1 = Time::Piece->strptime("16:51", "%M:%S"); my $t2 = Time::Piece->strptime("34:48", "%M:%S"); $t1 += $t2->min*60 + $t2->sec; print $t1->strftime("%M:%S");
But there are two reasons why they are not sufficient for what I want to do.
Here the summary: I would like to have a parse function (time string e.g. "16:51,14" to time object). It should be possible to apply arithmetic operations and comparisons of time objects and the time object should at least store hours, minutes, seconds and fractions of a second. And of course I want to be able to print the time object (something like strftime).
Is there already a module in CPAN which can do this? I did not find any. What would you suggest how to solve that? I don't want to reinvent everything. If possible I want to use an available module.
I'm very interested in your answers.
Thank you and Greetings
Dirk
In reply to Time calculations by Dirk80
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |