Determining my daughter's age
I imagine that just about every parent who programs has written something like this at one time or another.
use DateTime;
my $birthday = shift || 20110205;
$birthday =~ s/-//g;
my ( $year, $month, $day ) = ( $birthday =~ /^(\d\d\d\d)(\d\d)(\d\d)$/ );
$birthday = DateTime->new(
year => $year,
month => $month,
day => $day,
);
my $dur = DateTime->now->delta_days($birthday);
my ( $weeks, $days ) = ( $dur->weeks, $dur->days );
given ($days) {
when (0) { $days = "exactly" }
when (1) { $days = " and 1 day" }
default { $days = " and $_ days" }
}
say "$weeks weeks $days";
In other news, my daughter is "29 weeks exactly" today (though the picture above was actually taken in late June in Haarlem, a small town near Amsterdam).
She's a cutie! :)
Thanks, Robert :)