http://www.perlmonks.org?node_id=827306


in reply to Simple calendar

The calendar thing is one those functions that you do use from day to day. Most of the time I have used Calendar::Calendar to generate a straight grid type, but you mentioned that this may no work for you.

There are formulas to calculate month length, but the easiest is to set up a table, zero relative of the month length. Thirty days as November, April, June, and September, the others, save February, have thirty-one. February....

In February a little math is necessary. It is a leap year, 29 day, if:

$is_leap_year = (($year % 4) == 0) && ((($year % 100) != 0) #<- fixed typo... || (($year % 400) == 0));

So, right to left, years that are divisible by 400 are leap years, years divisible by 100, but not 400, are not, other years, save those divisible by 100 before, that are divisible by 4 are, and what is left is not.

I hope was able to give you some timely information.

Good luck. -c

Updated to fix a typo... -c

Replies are listed 'Best First'.
Re^2: Simple calendar
by JavaFan (Canon) on Mar 08, 2010 at 07:54 UTC
    There are formulas to calculate month length, but the easiest is to set up a table, zero relative of the month length. Thirty days as November, April, June, and September, the others, save February, have thirty-one. February....

    In February a little math is necessary.

    Yeah, that was my first impression as well. But then, given the year, it's also known what day Jan 1 is. But this homework problem allows users to actually set the day of the week of Jan 1. So, the exercise is about imaginary calenders and years. I mean, if Jan 1, 2011 is to be a Wednesday, such a 2011 might as well have a Feb 29.
Re^2: Simple calendar
by perl_fool (Initiate) on Mar 08, 2010 at 04:42 UTC
    yeah i did see this before but i couldnt figure out anything about the 100 and 400. i will try to understand it. Thanks for ur help, I truly appreciate it.
      Wikipedia explains this.
        thanks a lot =)