Skip Menu |
 

This queue is for tickets about the Date-Simple CPAN distribution.

Report information
The Basics
Id: 8562
Status: open
Worked: 1 hour (60 min)
Priority: 0/
Queue: Date-Simple

People
Owner: JTOBEY [...] cpan.org
Requestors: anil [...] anilnatha.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.01
Fixed in: (no value)

Attachments


Subject: Incorrect day of week results
Download (untitled) / with headers
text/plain 268b
Certain days for large groups of years produce incorrect day_of_week results. I was testing Date::Simple version 3.01 on a machine running red hate enterprise linux ws. Perl 5.8.0 is installed on this machine. I've attached as test program to illustrate these bugs.
Download calendar_test.cgi
text/plain 4.4k
#!/usr/local/bin/perl -w ################################################################################ ################################################################################ ## Author: Anil Natha ################################################################################ ################################################################################ ## SCRIPT INCLUDES AND DECLARATIONS use strict; use diagnostics; use Date::Simple; ################################################################################ ################################################################################ ## HEADER INFORMATION print "Content-type: text/html\n\n"; ################################################################################ ################################################################################ ## MAIN PROCEDURE my @dayNames = ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); my @dayCount = ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); ## ----------------------------------------------------------------------------- ## ----------------------------------------------------------------------------- print <<HEADER; <html> <head> <title>Date Test</title> <style type="text/css"> body,table,tr,table,font { font-family: Arial,Verdana,Helvetica; font-size: 8pt; } </style> </head> <body> <table width='550' border='1'> <th>Date</th> <th>My Method</th> <th>Date::Simple</th> <th>Test</th> HEADER for( my $year = 1580; $year <= 2004; $year++ ) { for( my $month = 1; $month <= 12; $month++ ) { for( my $day = 1; $day <= $dayCount[$month]; $day++ ) { testDate($month,$day,$year); } if( $month == 2 && isLeapYear($year) ) { testDate($month,29,$year); } } } print <<FOOTER; </table> </body> </html> FOOTER ################################################################################ ################################################################################ ## ----------------------------------------------------------------------------- ## ----------------------------------------------------------------------------- sub testDate { my($month,$day,$year) = @_; my $dayIndex = dayOfWeek($month,$day,$year); my $dayObject = new Date::Simple($year,$month,$day); $dayObject = $dayObject->day_of_week; print " <tr valigh='center' align='center'>"; print " <td>$month/$day/$year</td>\n"; print " <td>" . $dayNames[$dayIndex] . "</td>\n"; print " <td>" . $dayNames[$dayObject] . "</td>\n"; if( $dayIndex != -1 ) { if( $dayIndex != $dayObject ) { print " <td><font color='#990000'>Invalid</font></td>\n"; } else { print " <td><font color='#006600'>Valid</font></td>\n"; } } else { print " <td><font color='#006600'>Error</font></td>\n"; } print " </tr>\n"; } ## ----------------------------------------------------------------------------- ## ----------------------------------------------------------------------------- sub dayOfWeek { my($month,$day,$year) = @_; my $a = int((14 - $month) / 12); my $y = $year - $a; my $m = $month + 12 * $a - 2; if( $year < 1582 || ($year == 1582 && ( $month < 10 || ($month == 10 && $day <= 4) ) ) ) { ## OUTPUT DAY BASED ON JULIAN CALENDAR return( (5 + $day + $y + int($y / 4) + int((31 * $m) / 12)) % 7 ); } elsif( $year > 1582 || ($year == 1582 && ( $month > 10 || ($month == 10 && $day >= 15) ) ) ) { ## OUTPUT DAY BASED ON GREGORIAN CALENDAR return( ($day + $y + int($y / 4) - int($y / 100) + int($y / 400) + int((31 * $m) / 12)) % 7 ); } else { ## RETURN ERROR return(-1); } } ## ----------------------------------------------------------------------------- ## ----------------------------------------------------------------------------- sub isLeapYear { my ($year) = @_; if ( ($year % 4 == 0) && ( ($year % 100) || ($year % 400 == 0) ) ) { return(1); } else { return(0); } } # end subroutine isLeapYear ## ----------------------------------------------------------------------------- ## ----------------------------------------------------------------------------- ################################################################################ ################################################################################ ## CLOSING INSTRUCTION CALLS exit;
Download (untitled) / with headers
text/plain 762b
Confirmed in 2.04. Fixed in 2.05. Will send patch to current maintainer. Index: Simple.xs =================================================================== RCS file: /home/jtobey/cvsroot/Date-Simple/Simple.xs,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- Simple.xs 7 Dec 2002 03:24:17 -0000 1.6 +++ Simple.xs 28 Nov 2004 01:24:00 -0000 1.7 @@ -47,11 +47,11 @@ if (x >= 1900) leap_holes_100 = (x - 1900) / 100; else - leap_holes_100 = - (1900 - x) / 100; + leap_holes_100 = - (1999 - x) / 100; if (x >= 1600) leap_days_400 = (x - 1600) / 400; else - leap_days_400 = - (1600 - x) / 400; + leap_days_400 = - (1999 - x) / 400; *days = nonleap_days + leap_days_4 - leap_holes_100 + leap_days_400; return TRUE;


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.