mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clone Carbon.
This commit is contained in:
parent
13c2db5378
commit
6d4303aa3f
@ -13,15 +13,16 @@ use FireflyIII\Exception\FireflyException;
|
|||||||
class Date
|
class Date
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param Carbon $date
|
* @param Carbon $theDate
|
||||||
* @param $repeatFreq
|
* @param $repeatFreq
|
||||||
* @param $skip
|
* @param $skip
|
||||||
*
|
*
|
||||||
* @return Carbon
|
* @return Carbon
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function addPeriod(Carbon $date, $repeatFreq, $skip)
|
public function addPeriod(Carbon $theDate, $repeatFreq, $skip)
|
||||||
{
|
{
|
||||||
|
$date = clone $theDate;
|
||||||
// TODO clone the dates so referred date won't be altered.
|
// TODO clone the dates so referred date won't be altered.
|
||||||
$add = ($skip + 1);
|
$add = ($skip + 1);
|
||||||
switch ($repeatFreq) {
|
switch ($repeatFreq) {
|
||||||
@ -56,13 +57,15 @@ class Date
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Carbon $currentEnd
|
* @param Carbon $theCurrentEnd
|
||||||
* @param $repeatFreq
|
* @param $repeatFreq
|
||||||
*
|
*
|
||||||
|
* @return mixed
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function endOfPeriod(Carbon $currentEnd, $repeatFreq)
|
public function endOfPeriod(Carbon $theCurrentEnd, $repeatFreq)
|
||||||
{
|
{
|
||||||
|
$currentEnd = clone $theCurrentEnd;
|
||||||
switch ($repeatFreq) {
|
switch ($repeatFreq) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
|
throw new FireflyException('Cannot do endOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||||
@ -93,14 +96,15 @@ class Date
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Carbon $date
|
* @param Carbon $theDate
|
||||||
* @param $repeatFreq
|
* @param $repeatFreq
|
||||||
*
|
*
|
||||||
* @return Carbon
|
* @return Carbon
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function startOfPeriod(Carbon $date, $repeatFreq)
|
public function startOfPeriod(Carbon $theDate, $repeatFreq)
|
||||||
{
|
{
|
||||||
|
$date = clone $theDate;
|
||||||
switch ($repeatFreq) {
|
switch ($repeatFreq) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
|
throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq);
|
||||||
@ -133,43 +137,4 @@ class Date
|
|||||||
|
|
||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param Carbon $date
|
|
||||||
* @param $repeatFreq
|
|
||||||
* @param int $substract
|
|
||||||
*
|
|
||||||
* @return Carbon
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
public function substractPeriod(Carbon $date, $repeatFreq, $substract = 1)
|
|
||||||
{
|
|
||||||
switch ($repeatFreq) {
|
|
||||||
default:
|
|
||||||
throw new FireflyException('Cannot do addPeriod for $repeat_freq ' . $repeatFreq);
|
|
||||||
break;
|
|
||||||
case 'daily':
|
|
||||||
$date->subDays($substract);
|
|
||||||
break;
|
|
||||||
case 'weekly':
|
|
||||||
$date->subWeeks($substract);
|
|
||||||
break;
|
|
||||||
case 'monthly':
|
|
||||||
$date->subMonths($substract);
|
|
||||||
break;
|
|
||||||
case 'quarterly':
|
|
||||||
$months = $substract * 3;
|
|
||||||
$date->subMonths($months);
|
|
||||||
break;
|
|
||||||
case 'half-year':
|
|
||||||
$months = $substract * 6;
|
|
||||||
$date->subMonths($months);
|
|
||||||
break;
|
|
||||||
case 'yearly':
|
|
||||||
$date->subYears($substract);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $date;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user