-
-
Save davorg/4da9ca7c679bfbf08a6c to your computer and use it in GitHub Desktop.
Work out some ages in days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use 5.010; | |
use Time::Piece; | |
use Time::Seconds; | |
use Lingua::EN::Inflexion; | |
my $birthday = shift || '1962-09-07'; | |
my $now = localtime; | |
my $then = Time::Piece->strptime($birthday, '%Y-%m-%d'); | |
say int(($now - $then)->days); | |
foreach my $r (0 .. 4) { | |
foreach my $m (qw[1 2 5]) { | |
my $day = Time::Piece->strptime($birthday, '%Y-%m-%d'); | |
my $days = $m * (10 ** $r); | |
$day += $days * ONE_DAY; | |
if ($day->date eq $now->date) { | |
say inflect "You are <#:$days> <N:days> old today!"; | |
} elsif ($day->date lt $now->date) { | |
say inflect "You were <#:$days> <N:days> old on ", | |
$day->strftime('%a, %d %B %Y'); | |
} else { | |
say inflect "You will be <#:$days> <N:days> old on ", | |
$day->strftime('%a, %d %B %Y'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment