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  


 [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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-10-20 14:08 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-10-20 15:08 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2006-10-20 15:42 UTC] macristo at gmx dot net
Thanks Lorenzo, It seems to work alright now! Regards, Patrick