Hi All,

I have started a project in which I need to figure out
the number of sundays in a given year. Here is what I have come up with.

Seams to work!! any suggestions :)

FAQ anyone:)

Ron Hill

========================script=========================

use strict;
use warnings;
use DateTime;

my $dt = DateTime->new( year => 2001 );
my $num = number_of_sundays($dt);
print $num;

sub number_of_sundays {

    my ($dt) = @_;
    my $dt2 = $dt->clone();

    if ( $dt->is_leap_year ) {

        my $dow = $dt2->day_of_week(
          year  => $dt->year,
          month => 1,
          day   => 1,
        );
        return 53 if ( $dow == 7 or $dow == 6 );

    }
    else {

        my $dow = $dt2->day_of_week(
          year  => $dt->year,
          month => 1,
          day   => 1,
        );
        return 53 if ( $dow == 7 );
    }

    return 52;
}

Reply via email to