示例#1
0
function get_days(Carbon $begin, Carbon $end = null) : array
{
    $end = $end ?? $begin;
    $diff = $begin->diff($end);
    $one_day = new DateInterval('P1D');
    $days = [];
    for ($i = 1; $i <= $diff->days; $i++) {
        $days[] = $begin->add($one_day)->getTimestamp();
    }
    return $days;
}
示例#2
0
 public function editBudget($id)
 {
     $budget = Auth::user()->budgets()->find($id);
     if ($budget) {
         $dates = array();
         $start = new Carbon($budget->date);
         $start->sub(new DateInterval('P1Y'));
         for ($i = 0; $i <= 24; $i++) {
             $dates[$start->format('Y-m') . '-01'] = $start->format('F Y');
             $start->add(new DateInterval('P1M'));
         }
         return View::make('budgets.edit')->with('budget', $budget)->with('dates', $dates);
     } else {
         return App::abort(404);
     }
 }
示例#3
0
 /**
  * Adds an amount of days, months, years, hours, minutes and seconds to a Date object.
  *
  * @param  string|DateInterval $interval
  * @return Date
  */
 public function add($interval)
 {
     if (is_string($interval)) {
         // Check for ISO 8601
         if (strtoupper(substr($interval, 0, 1)) == 'P') {
             $interval = new DateInterval($interval);
         } else {
             $interval = DateInterval::createFromDateString($interval);
         }
     }
     return parent::add($interval);
 }
 /**
  * Add \DateInterval to the instance.
  *
  * @param \DateInterval $interval
  * @return $this
  */
 public function add(\DateInterval $interval)
 {
     $this->startDate->add($interval);
     $this->endDate->add($interval);
     return $this;
 }
 private function MonthInterval(Carbon $fr, Carbon $to)
 {
     $interval = new DateInterval('P6D');
     $to->add($interval);
     return new DatePeriod($fr, $interval, $to);
 }