You are here

static function PersianDateFactory::buildFromExactDate in Persian Date for Drupal 8 8

Same name and namespace in other branches
  1. 8.4 src/Converter/PersianDateFactory.php \Drupal\persian_date\Converter\PersianDateFactory::buildFromExactDate()

Build PersianDateTime instance from given parameters.

Parameters

int $hour:

int $minute:

int $second:

int $month:

int $day:

int $year:

int $is_dst:

Return value

PersianDate

1 call to PersianDateFactory::buildFromExactDate()
PersianDrupalDateTime::createFromFormat in src/Plugin/Datetime/PersianDrupalDateTime.php
Creates a date object from an input format.

File

src/Converter/PersianDateFactory.php, line 34

Class

PersianDateFactory
This class is responsible to build Persian DateTime instances.

Namespace

Drupal\persian_date\Converter

Code

static function buildFromExactDate($hour = null, $minute = null, $second = null, $month = null, $day = null, $year = null, $is_dst = -1) {
  if (!$hour and !$minute and !$second and !$month and !$day and !$year) {
    $timestamp = mktime();
  }
  else {
    list($gy, $gm, $gd) = PersianDateConverter::jalali_to_gregorian($year, $month, $day);
    $timestamp = mktime($hour, $minute, $second, $gm, $gd, $gy);
  }
  $object = new PersianDate();
  $object
    ->setTimestamp($timestamp);
  return $object;
}