package Tools; use strict; use warnings; use DateTime; #use Date::Parse qw(str2time); use Exporter qw(import); our @EXPORT = qw( howOld rUp source ); sub howOld { my ($date, $time) = split ' ', shift; my ($hh, $mm, $ss) = split ':', $time; my ($d, $m, $y) = split '/', $date; my $dob = DateTime->new( year => $y, month => $m, day => $d, hour => $hh, minute => $mm, second => $ss, ); my $now = DateTime->now; my $dur = $now->delta_md($dob); my $years = int($dur->delta_months / 12); my $months = $dur->delta_months % 12; my $days = $dur->delta_days; my @age = "$years years"; if ($days >= 1 and $months > 0) { push @age, sprintf ", %i %s ", $months, ($months >= 2 ? 'months' : 'month'); } elsif (!$days and $months > 0) { push @age, sprintf " and %i %s ", $months, ($months >= 2 ? 'months' : 'month'); } if ($days > 0) { push @age, sprintf " and %i %s", $days, ($days >= 2 ? 'days' : 'day'); } return join('', @age), ($now->epoch - $dob->epoch); } sub source { my $file = shift; my $text; unless (-f $file) { return "Error: File not found."; } open FH, $file or return "Error: $!"; $text.= $_ while ; close FH; return $text; }