Example #1
0
 /**
  * Converts a DateTime object to corresponding JalaliDate object.
  *
  * @param DateTime $dateTime
  *
  * @return JDateTime
  */
 public static function dateTimeToJDateTime(DateTime $dateTime)
 {
     $georgian = static::dateTimeToGeorgian($dateTime);
     $firstDay = new GeorgianDate(622, 3, 22);
     $jDate = JalaliDate::fromInteger($georgian->toInteger() - $firstDay->toInteger() + 1);
     return new JDateTime($jDate->getYear(), $jDate->getMonth(), $jDate->getDay(), $dateTime->format('H'), $dateTime->format('i'), $dateTime->format('s'));
 }
Example #2
0
 public function test_validate_before_without_parameter()
 {
     $now = JalaliDate::fromDateTime(new DateTime());
     $tomorrow = JalaliDate::fromInteger($now->toInteger() + 1)->format('Y/m/d');
     $yesterday = JalaliDate::fromInteger($now->toInteger() - 1)->format('Y/m/d');
     $this->assertFalse($this->validator->validateBefore('foo', $tomorrow, []));
     $this->assertTrue($this->validator->validateBefore('foo', $yesterday, []));
     $this->assertFalse($this->validator->validateBefore('foo', $now->format('Y/m/d'), []));
     $this->assertFalse($this->validator->validateBefore('foo', 'bar', []));
     $this->assertFalse($this->validator->validateBefore('foo', ['bar'], []));
 }
Example #3
0
 /**
  * @test
  * @group brute_force
  */
 public function brute_force_test_convert_between_georgian_and_jalali()
 {
     for ($i = 1; $i <= 539828; $i++) {
         $this->assertEquals(JalaliDate::fromInteger($i)->format('Y-m-d'), JalaliDate::fromDateTime(JalaliDate::fromInteger($i)->toDateTime())->format('Y-m-d'));
     }
 }
Example #4
0
 /**
  * Converts a DateTime object to corresponding JalaliDate object
  *
  * @param DateTime $dateTime
  * @return JalaliDate
  */
 public static function dateTimeToJalali(DateTime $dateTime)
 {
     $georgian = static::dateTimeToGeorgian($dateTime);
     $firstDay = new GeorgianDate(622, 3, 22);
     return JalaliDate::fromInteger($georgian->toInteger() - $firstDay->toInteger() + 1);
 }
Example #5
0
 public function createJalaliDate()
 {
     $y = $this->year ?: static::$defaultCentury + $this->yearOfCentury;
     if (!$this->hasNoMonth() && $this->day) {
         return new JalaliDate($y, $this->getMonth(), $this->day);
     }
     $firstDay = new JalaliDate($y, 1, 1);
     return JalaliDate::fromInteger($firstDay->toInteger() - 1 + $this->dayOfYear);
 }
Example #6
0
 /**
  * @throws \Exception
  * @test
  * @group brute_force
  */
 public function brute_force_test_from_and_to_integer()
 {
     for ($i = 1; $i <= 539828; $i++) {
         $this->assertEquals($i, JalaliDate::fromInteger($i)->toInteger());
     }
 }