From: "Hill, Ronald" <[EMAIL PROTECTED]>
To: 'Syamala Tadigadapa' <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED]
Subject: RE: figuring out the number of sundays in a given year
Date: Thu, 18 Sep 2003 11:30:15 -0700

Hi Syamala,


> Here is a simple solution (unless you are bent on doing > it in a longer way using the class in ref.)

The project I have started on is using DateTime for other things, so I
figured I would use it here as well. Besides I don't think what I
wrote is doing it the long way, granted I did screw up by passing
in params to a method that was ignoring it. But I still got
what I wanted.


I understand.
I only wanted to mention that the issue here is not a complex computation.
( one responder hated the complexity of the simple solution, that is another matter).
Even in the datetime project code, may be you can add a method to supply the weekday of jan_first of present year if desired useful. May be a method can be added to return the count of specific week day occurrence in the year present. And these methods could be based on the Zeller's congruence simplified as shown,


> sub jan1{
>  my $y =  shift;
>  my $m = 1; $d = 1;
              ^^^^^^
why is that there? and I don't understand why you set $m to 1
and then set it to 11?

The above line can be eliminated.

> $m = 11; $y--; > my $c = int($y / 100); $yy = $y %100; > my $z = ( 1 + $yy + int($yy/4) + int($c/4) - 2*$c) % 7; > $z += 7 if $z < 0; > return $z; # 0 ==> Sun day. 6 ==> Sat. day. >} >sub sundays{ > my $year = shift; > my $j1st = jan1($year); > return 53 if $j1st == 0 || ($j1st == 6 && jan1($year+1) == 1); > return 52; >}

Ron Hill

_________________________________________________________________
Get McAfee virus scanning and cleaning of incoming attachments. Get Hotmail Extra Storage! http://join.msn.com/?PAGE=features/es




Reply via email to