task #10885: Optimize code
This commit is contained in:
parent
5a4004b49d
commit
792c04083f
@ -281,62 +281,24 @@ function dol_get_first_day_week($day,$month,$year,$gm=false)
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$date=dol_mktime(0,0,0,$month,$day,$year,$gm);
|
$date = dol_mktime(0,0,0,$month,$day,$year,$gm);
|
||||||
|
|
||||||
// TODO: Modify->the week can begins with any day!
|
//Checking conf of start week
|
||||||
|
$start_week = (isset($conf->global->MAIN_START_WEEK)?$conf->global->MAIN_START_WEEK:1);
|
||||||
|
|
||||||
if (isset($conf->global->MAIN_START_WEEK))
|
$tmparray = dol_getdate($date,true);
|
||||||
{
|
|
||||||
if ($conf->global->MAIN_START_WEEK==1)
|
|
||||||
{
|
|
||||||
$tmparray = dol_getdate($date,true);
|
|
||||||
|
|
||||||
// How many days ahead monday are we?
|
//Calculate days to count
|
||||||
switch ( $tmparray['wday'] )
|
$days = $start_week - $tmparray['wday'];
|
||||||
{
|
if ($days>=1) $days=7-$days;
|
||||||
case 0: // we are on sunday
|
$days = abs($days);
|
||||||
$days = 6;
|
$seconds = $days*24*60*60;
|
||||||
break;
|
|
||||||
|
|
||||||
default: // any other day
|
|
||||||
$days = $tmparray['wday']-1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$seconds = $days*24*60*60;
|
|
||||||
$tmpday = date($tmparray[0])-$seconds;
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$tmparray = dol_getdate($date,true);
|
|
||||||
// substact as many days as days ahead sunday we are
|
|
||||||
$seconds = $tmparray['wday']*24*60*60;
|
|
||||||
$tmpday = date($tmparray[0])-$seconds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$tmpday = dol_getdate($date,true);
|
|
||||||
|
|
||||||
// How many days ahead monday are we?
|
|
||||||
switch ( $tmparray['wday'] )
|
|
||||||
{
|
|
||||||
case 0: // we are on sunday
|
|
||||||
$days = 6;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: // any other day
|
|
||||||
$days = $tmparray['wday']-1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$seconds = $days*24*60*60;
|
|
||||||
$tmpday = date($tmparray[0])-$seconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//Get first day of week
|
||||||
|
$tmpday = date($tmparray[0])-$seconds;
|
||||||
$tmpday = date("d",$tmpday);
|
$tmpday = date("d",$tmpday);
|
||||||
|
|
||||||
|
//Check first day of week is form this month or not
|
||||||
if ($tmpday>$day)
|
if ($tmpday>$day)
|
||||||
{
|
{
|
||||||
$prev_month = $month-1;
|
$prev_month = $month-1;
|
||||||
@ -354,16 +316,13 @@ function dol_get_first_day_week($day,$month,$year,$gm=false)
|
|||||||
$prev_year = $year;
|
$prev_year = $year;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmpday = $tmpday;
|
//Get first day of next week
|
||||||
$prev_month = $prev_month;
|
|
||||||
$prev_year = $prev_year;
|
|
||||||
|
|
||||||
$tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0);
|
$tmptime=dol_mktime(12,0,0,$month,$tmpday,$year,1,0);
|
||||||
$tmptime-=24*60*60*7;
|
$tmptime-=24*60*60*7;
|
||||||
$tmparray=dol_getdate($tmptime,true);
|
$tmparray=dol_getdate($tmptime,true);
|
||||||
|
|
||||||
$prev_day = $tmparray['mday'];
|
$prev_day = $tmparray['mday'];
|
||||||
|
|
||||||
|
//Check first day of week is form this month or not
|
||||||
if ($prev_day>$tmpday)
|
if ($prev_day>$tmpday)
|
||||||
{
|
{
|
||||||
$prev_month = $month-1;
|
$prev_month = $month-1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user