You are here

public static function Carbon::create in Persian Date for Drupal 8 8.4

Create a new Carbon instance from a specific date and time.

If any of $year, $month or $day are set to null their now() values will be used.

If $hour is null it will be set to its now() value and the default values for $minute and $second will be their now() values.

If $hour is not null then the default values for $minute and $second will be 0.

Parameters

int|null $year:

int|null $month:

int|null $day:

int|null $hour:

int|null $minute:

int|null $second:

\DateTimeZone|string|null $tz:

Return value

static

5 calls to Carbon::create()
Carbon::createFromDate in src/Library/Carbon/Carbon.php
Create a Carbon instance from just a date. The time portion is set to now.
Carbon::createFromTime in src/Library/Carbon/Carbon.php
Create a Carbon instance from just a time. The date portion is set to today.
Carbon::createSafe in src/Library/Carbon/Carbon.php
Create a new safe Carbon instance from a specific date and time.
Carbon::maxValue in src/Library/Carbon/Carbon.php
Create a Carbon instance for the greatest supported date.
Carbon::minValue in src/Library/Carbon/Carbon.php
Create a Carbon instance for the lowest supported date.

File

src/Library/Carbon/Carbon.php, line 429

Class

Carbon
A simple API extension for DateTime

Namespace

Drupal\persian_date\Library\Carbon

Code

public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null) {
  $now = static::hasTestNow() ? static::getTestNow()
    ->getTimestamp() : time();
  $defaults = array_combine(array(
    'year',
    'month',
    'day',
    'hour',
    'minute',
    'second',
  ), explode('-', date('Y-n-j-G-i-s', $now)));
  $year = $year === null ? $defaults['year'] : $year;
  $month = $month === null ? $defaults['month'] : $month;
  $day = $day === null ? $defaults['day'] : $day;
  if ($hour === null) {
    $hour = $defaults['hour'];
    $minute = $minute === null ? $defaults['minute'] : $minute;
    $second = $second === null ? $defaults['second'] : $second;
  }
  else {
    $minute = $minute === null ? 0 : $minute;
    $second = $second === null ? 0 : $second;
  }
  $fixYear = null;
  if ($year < 0) {
    $fixYear = $year;
    $year = 0;
  }
  elseif ($year > 9999) {
    $fixYear = $year - 9999;
    $year = 9999;
  }
  $instance = static::createFromFormat('Y-n-j G:i:s', sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second), $tz);
  if ($fixYear !== null) {
    $instance
      ->addYears($fixYear);
  }
  return $instance;
}