Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.5.5

Bug #8758 Week-class displays wrong year
Submitted: 2006-09-21 13:35 UTC
From: macristo at gmx dot net Assigned: quipo
Status: Closed Package: Calendar (version 0.5.3)
PHP Version: 5.1.6 OS: Debian GNU/Linux Etch
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 20 + 49 = ?

 
 [2006-09-21 13:35 UTC] macristo at gmx dot net (Patrick Nijs)
Description: ------------ If you instantiate a Calendar_Week with the day set to january 1. 2004 and you call $Week->thisYear(), you will see that the year returned will be 2003, because the first day of that week falls in 2003. Of course, the correct year for week 1 of 2004 would be 2004, not 2003. Is there a way to get the correct year for the weeks, from which the first days fall in the previous year. Test script: --------------- <?php require_once 'Calendar/Week.php'; require_once 'Calendar/Decorator/Uri.php'; if (!isset($_GET['year']) || !isset($_GET['month']) || !isset($_GET['day'])) { $_GET['year'] = date('Y'); $_GET['month'] = date('n'); $_GET['day'] = date('d'); } $Week = new Calendar_Week($_GET['year'], $_GET['month'], $_GET['day']); $Week->build(); $Uri =& new Calendar_Decorator_Uri($Week); $Uri->setFragments('year', 'month', 'day'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Test</title></head><body><table border="1"><tr><td colspan="7">Week: <?php echo $Week->thisWeek('n_in_year'); ?> of <?php echo $Week->thisYear(); ?></td></tr><tr><td width=80>Monday</td><td width=80>Tuesday</td><td width=80>Wednesday</td><td width=80>Thursday</td><td width=80>Friday</td><td width=80>Saturday</td><td width=80>Sunday</td></tr><tr> <?php while ($Day = $Week->fetch()) { echo "<td>" . $Day->thisYear() . "-" . $Day->thisMonth() . "-" . $Day->thisDay() . "</td>"; } ?> </tr></table><p> <?php $prev = $_SERVER['PHP_SELF'] . "?" . $Uri->prev('week'); $next = $_SERVER['PHP_SELF'] . "?" . $Uri->next('week'); echo "<a href='${prev}'>Previous week</a>  "; echo "<a href='${_SERVER['PHP_SELF']}?year=".date('Y')."&month=".date('n')."&day=".date('d')."'>Current week</a>  "; echo "<a href='${next}'>Next week</a>"; ?> <p>Erroneous year:<a href="<?php echo $_SERVER['PHP_SELF']; ?>?year=2003&month=12&day=29">First week of 2004 displays wrong year!</a></body></html> Expected result: ---------------- The first week of 2004 should display 2004 when calling $Week->thisYear() when using the parameters: year=2003&month=12&day=29. Actual result: -------------- The wrong year for the $Week object is returned, because the first day of the $Week-object is in the previous year.

Comments

 [2006-10-18 19:21 UTC] scottmattocks (Scott Mattocks)
Here is a patch that should fix the issue. I think the original post was confusing. Basically, ISO rules say that the first week of 2004 actually starts in 2003. So if you enter a date of Dec 29, 2003, the year for that week is actually 2004. http://crisscott.com/tmp/PEAR/pear_bug_8758.patch My patch may be a little hack-ish, but I haven't spent enough time with the package to know all its ins and outs. The unit tests still pass and the expected results come back.
 [2006-10-20 14:08 UTC] quipo (Lorenzo Alberton)
Hi, I just committed a fix to CVS. Please fetch it and test it. Unfortunately the patch submitted by Matt wasn't acceptable (it used the php date() function and still had the wrong result in some cases), but thanks anyway. I also added a few tests in the testsuite, if you think they're incomplete please tell me what cases I should add. Thanks, -- Lorenzo Alberton http://pear.php.net/user/quipo
 [2006-10-20 15:08 UTC] quipo (Lorenzo Alberton)
> the patch submitted by Matt I meant Scott, sorry :-p
 [2006-10-20 15:42 UTC] macristo at gmx dot net
Thanks Lorenzo, It seems to work alright now! Regards, Patrick