Skip to content

Instantly share code, notes, and snippets.

@gugod
Created Apr 29, 2011
Embed
What would you like to do?
Comparison of oral time duration modules
#!/usr/bin/env perl
use 5.012;
use strict;
use warnings;
use utf8;
use DateTime;
use DateTime::Format::Human::Duration;
use Time::Elapsed qw(elapsed);
use Time::Duration;
my $f = DateTime::Format::Human::Duration->new();
my $now = DateTime->now;
for my $seconds qw(0 1 59 60 61 72 3500 3600 3700 86399 86400 86519) {
my $dd = $now - $now->clone->subtract(seconds => $seconds);
local $, = "\n\t";
say "$seconds second(s):",
"Time::Duration: ". duration($seconds),
"Time::Elapsed: ". elapsed($seconds),
"DTF::Human::Duration: ". $f->format_duration( $dd );
say "";
}
0 second(s):
Time::Duration: 0 seconds
Time::Elapsed: zero seconds
DTF::Human::Duration: no time
1 second(s):
Time::Duration: 1 second
Time::Elapsed: 1 second
DTF::Human::Duration: 1 second
59 second(s):
Time::Duration: 59 seconds
Time::Elapsed: 59 seconds
DTF::Human::Duration: 59 seconds
60 second(s):
Time::Duration: 1 minute
Time::Elapsed: 1 minute
DTF::Human::Duration: 1 minute
61 second(s):
Time::Duration: 1 minute and 1 second
Time::Elapsed: 1 minute and 1 second
DTF::Human::Duration: 1 minute and 1 second
72 second(s):
Time::Duration: 1 minute and 12 seconds
Time::Elapsed: 1 minute and 12 seconds
DTF::Human::Duration: 1 minute and 12 seconds
3500 second(s):
Time::Duration: 58 minutes and 20 seconds
Time::Elapsed: 58 minutes and 20 seconds
DTF::Human::Duration: 58 minutes and 20 seconds
3600 second(s):
Time::Duration: 1 hour
Time::Elapsed: 1 hour
DTF::Human::Duration: 1 hour
3700 second(s):
Time::Duration: 1 hour and 2 minutes
Time::Elapsed: 1 hour, 1 minute and 40 seconds
DTF::Human::Duration: 1 hour, 1 minute, and 40 seconds
86399 second(s):
Time::Duration: 1 day
Time::Elapsed: 23 hours, 59 minutes and 59 seconds
DTF::Human::Duration: 23 hours, 59 minutes, and 59 seconds
86400 second(s):
Time::Duration: 1 day
Time::Elapsed: 1 day
DTF::Human::Duration: 1 day
86519 second(s):
Time::Duration: 1 day and 2 minutes
Time::Elapsed: 1 day, 1 minute and 59 seconds
DTF::Human::Duration: 1 day, 1 minute, and 59 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment