public function CarbonInterval::__construct in Persian Date for Drupal 8 8.4
Create a new CarbonInterval instance.
Parameters
int $years:
int $months:
int $weeks:
int $days:
int $hours:
int $minutes:
int $seconds:
File
- src/
Library/ Carbon/ CarbonInterval.php, line 120
Class
- CarbonInterval
- A simple API extension for DateInterval. The implementation provides helpers to handle weeks but only days are saved. Weeks are calculated based on the total days of the current instance.
Namespace
Drupal\persian_date\Library\CarbonCode
public function __construct($years = 1, $months = null, $weeks = null, $days = null, $hours = null, $minutes = null, $seconds = null) {
$spec = static::PERIOD_PREFIX;
$spec .= $years > 0 ? $years . static::PERIOD_YEARS : '';
$spec .= $months > 0 ? $months . static::PERIOD_MONTHS : '';
$specDays = 0;
$specDays += $weeks > 0 ? $weeks * Carbon::DAYS_PER_WEEK : 0;
$specDays += $days > 0 ? $days : 0;
$spec .= $specDays > 0 ? $specDays . static::PERIOD_DAYS : '';
if ($hours > 0 || $minutes > 0 || $seconds > 0) {
$spec .= static::PERIOD_TIME_PREFIX;
$spec .= $hours > 0 ? $hours . static::PERIOD_HOURS : '';
$spec .= $minutes > 0 ? $minutes . static::PERIOD_MINUTES : '';
$spec .= $seconds > 0 ? $seconds . static::PERIOD_SECONDS : '';
}
if ($spec === static::PERIOD_PREFIX) {
// Allow the zero interval.
$spec .= '0' . static::PERIOD_YEARS;
}
parent::__construct($spec);
}