modified week_number method a bit more, to allow to call it for arbitrary dates, not just the weekstart

This commit is contained in:
Ralf Becker 2011-01-05 22:26:34 +00:00
parent a145fdb13f
commit 5382856b60

View File

@ -191,20 +191,24 @@ class calendar_uiviews extends calendar_ui
/** /**
* Calculate iso8601 week-number, which is defined for Monday as first day of week only * Calculate iso8601 week-number, which is defined for Monday as first day of week only
* *
* @param int|string|DateTime $weekstart * We addjust the day, if user prefs want a different week-start-day
*
* @param int|string|DateTime $time
* @return string * @return string
*/ */
public function week_number($weekstart) public function week_number($time)
{ {
$time = new egw_time($weekstart); if (!is_a($time,'DateTime')) $time = new egw_time($time);
switch($this->cal_prefs['weekdaystarts'])
// if week does not start Monday and $time is Sunday --> add one day
if ($this->cal_prefs['weekdaystarts'] != 'Monday' && !($wday = $time->format('w')))
{ {
case 'Sunday': $time->modify('+1day');
$time->modify('+1day'); }
break; // if week does start Saturday and $time is Saturday --> add two days
case 'Saturday': elseif ($this->cal_prefs['weekdaystarts'] == 'Saturday' && $wday == 6)
$time->modify('+2days'); {
break; $time->modify('+2days');
} }
return $time->format('W'); return $time->format('W');
} }