[Omaha.pm] Simplifying Time?

Sterling Hanenkamp sterling at hanenkamp.com
Thu Mar 20 10:52:57 PDT 2014


If you use DateTime instead of Class::Date, there's the DateTime::Duration
class which will let you add durations:

my $duration = DateTime::Duration->new( seconds => 15 );
$duration->add( seconds => 73 );
$duration->add( weeks => 12 );

There are some modules to help with formatting durations too. I think the
nicest of which is this one:

https://metacpan.org/pod/DateTime::Format::Human::Duration

It's a pretty nice module.


On Thu, Mar 20, 2014 at 11:23 AM, Jay Hannah <jay at jays.net> wrote:

> On Mar 20, 2014, at 11:06 AM, Robert L. Harris <robert.l.harris at gmail.com>
> wrote:
> > It looks like the reldate is what I want, not figure out how to use it.
>  No clear examples on "convert 561 seconds to 9 minutes, 21 seconds" :)
>
> Does this help?
>
> https://github.com/jhannah/sandbox/blob/master/robertlharris/go.pl
>
>
> $ cat go.pl
> use Class::Date;
> use 5.10.0;
>
> my $reldate = new Class::Date::Rel "561s";
> say "In minutes: " . $reldate->min;
> say "In seconds: " . $reldate->sec;
>
> my $seconds_only = $reldate - (int($reldate->min) * 60 . 'm');  # subtract
> minutes away
> say "Seconds only: $seconds_only";
> printf("%d minutes %d seconds\n", int($reldate / 60), $seconds_only);
>
>
> $ perl go.pl
> In minutes: 9.35
> In seconds: 561
> Seconds only: 21
> 9 minutes 21 seconds
>
>
> j
>
>
> _______________________________________________
> Omaha-pm mailing list
> Omaha-pm at pm.org
> http://mail.pm.org/mailman/listinfo/omaha-pm
>



-- 
Andrew Sterling Hanenkamp
sterling at hanenkamp.com
785.370.4454
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20140320/27a5190f/attachment.html>


More information about the Omaha-pm mailing list