DayOfNthWeek

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1.0   Wed Dec 04 20:56:21 2002
	- Tested repeatedly and sent out for peer review and no problems 
      found so decided to go to 1.0 release.
	- Changed the method week_day to day_week to make it consistent
	  with the other method names.  

0.03  Wed Nov 29 07:51:44 2002
	- Changed the required Perl version from 5.008 (default of h2xs)
      to 5.005.  Since it is pure core Perl it should work with any
      version.
	- Added calc_week.pl to Examples.  Show formula and logic for
      calculating which week the day falls in.

0.02  Tue Nov 26 23:11:05 2002
	- Original missed some test cases. Required me to change each of 
      the methods.  
	- Added some examples

0.01  Mon Nov 25 10:59:11 2002
	- original version; created by h2xs 1.22 with options
		-XA -n Date::DayOfNthWeek

DayOfNthWeek.pm  view on Meta::CPAN

		&tomorrow if $ok;		
	}
} 

sub nextweek { print "Meeting is next week\n"; }
sub tomorrow { print "Meeting is tomorrow\n";  }
sub tonight  { print "Meeting is tonight\n";   }

=head2 FORMULA

The formula for calculating the week is:

(int(((Day of the Month - 1)+ Day of the Week)/7))+1


	my %hash = ();

	for my $c (0 ..6 ) {
		my $a  = $date+$c;
		my $key = $a%7;
		my $w    = (int($a/7))+1;

Examples/calc_week.pl  view on Meta::CPAN

# This program goes cycles through every mday 
# then calculates each wday for that mday

# Compare the out put of this program against the file months.txt
# and you will see that wday always gives the correct week
# while cday is often wrong.  This is why I calculate all of the
# days and push them into a has keyed by wday instead of just running
# the calculation and using cday. 

# I am no mathematician so I cannot do the proof showing why this
# formula works, it just does.  

for $mday (1 .. 31) {

# makes mday index from 0 just like wday

	$date= $mday - 1;
	
	print "\nMday\tWday\tWeek\tCday\n$mday\n";

	for $c (0 ..6 ) {  # $c == cday 



( run in 0.243 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )