Skip to content

Instantly share code, notes, and snippets.

@davorg
Created February 1, 2016 15:35
Show Gist options
  • Save davorg/4da9ca7c679bfbf08a6c to your computer and use it in GitHub Desktop.
Save davorg/4da9ca7c679bfbf08a6c to your computer and use it in GitHub Desktop.
Work out some ages in days
#!/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