Skip to content

Instantly share code, notes, and snippets.

@xsawyerx
Created July 13, 2012 20:38
Show Gist options
  • Select an option

  • Save xsawyerx/3107320 to your computer and use it in GitHub Desktop.

Select an option

Save xsawyerx/3107320 to your computer and use it in GitHub Desktop.
Finding Friday the 13th
use strict;
use warnings;
use DateTime;
my $dt = DateTime->new(
day => 13,
year => 2012,
);
my $count = 0;
while ( my $next_dt = $dt->add( months => 1 ) ) {
if ( $next_dt->day_name eq 'Friday' ) {
my $date = $next_dt->dmy('/');
print "Friday the 13th on: $date\n";
}
# stop after 5 years
$count++ == ( 12 * 5 ) and last;
}
use strict;
use warnings;
use DateTime;
foreach my $year ( 2012 .. 2020 ) {
foreach my $month ( 1 .. 12 ) {
my $dt = DateTime->new(
day => 13, month => $month, year => $year
);
if ( $dt->day_name eq 'Friday' ) {
print $dt->dmy('/'), "\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment