You are here

public function Carbon::__construct in Persian Date for Drupal 8 8.4

Create a new Carbon instance.

Please see the testing aids section (specifically static::setTestNow()) for more on the possibility of this constructor returning a test instance.

Parameters

string|null $time:

\DateTimeZone|string|null $tz:

File

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

Class

Carbon
A simple API extension for DateTime

Namespace

Drupal\persian_date\Library\Carbon

Code

public function __construct($time = null, $tz = null) {

  // If the class has a test now set and we are trying to create a now()
  // instance then override as required
  if (static::hasTestNow() && (empty($time) || $time === 'now' || static::hasRelativeKeywords($time))) {
    $testInstance = clone static::getTestNow();
    if (static::hasRelativeKeywords($time)) {
      $testInstance
        ->modify($time);
    }

    //shift the time according to the given time zone
    if ($tz !== null && $tz !== static::getTestNow()
      ->getTimezone()) {
      $testInstance
        ->setTimezone($tz);
    }
    else {
      $tz = $testInstance
        ->getTimezone();
    }
    $time = $testInstance
      ->toDateTimeString();
  }
  parent::__construct($time, static::safeCreateDateTimeZone($tz));
}