Пример #1
0
 /**
  * @param JalaliDate $jDate
  * @return DateTime
  */
 public static function jalaliToDateTime(JalaliDate $jDate)
 {
     $firstDay = (new GeorgianDate(622, 3, 22))->toInteger();
     $nDays = $jDate->toInteger() + $firstDay;
     $georgian = GeorgianDate::fromInteger($nDays);
     return static::georgianToDateTime($georgian);
 }
Пример #2
0
 /**
  * @param JalaliDate|JDateTime $jDate
  *
  * @return DateTime
  */
 public static function jalaliToDateTime(JalaliDate $jDate)
 {
     $firstDay = (new GeorgianDate(622, 3, 22))->toInteger();
     $nDays = $jDate->toInteger() + $firstDay - 1;
     $georgian = GeorgianDate::fromInteger($nDays);
     $dateTime = static::georgianToDateTime($georgian);
     if ($jDate instanceof JDateTime) {
         $dateTime->setTime($jDate->getHour(), $jDate->getMinute(), $jDate->getSecond());
     }
     return $dateTime;
 }
Пример #3
0
 public function sample_6()
 {
     $jalaliDate = JalaliDate::fromFormat('Y/m/d', '1394/6/20');
     print "\n";
     print $jalaliDate->format('D، d M y');
     print "\n";
 }
Пример #4
0
 public function test_jalali_after_or_before_replacer_is_applied_with_no_parameter()
 {
     $now = JalaliDate::fromDateTime(new DateTime())->format('Y/m/d', false);
     $validator = $this->factory->make(['graduation_date' => 'garbage'], ['graduation_date' => 'required|jalali_after|jalali_before']);
     $this->assertTrue($validator->fails());
     $this->assertEquals(['graduation_date' => ["The graduation date must be a Jalali date after {$now}.", "The graduation date must be a Jalali date before {$now}."]], $validator->messages()->toArray());
 }
Пример #5
0
 public function __construct($year, $month, $day, $hour = 0, $minute = 0, $second = 0)
 {
     $this->hour = (int) $hour;
     $this->minute = (int) $minute;
     $this->second = (int) $second;
     parent::__construct($year, $month, $day);
     $this->validateTime();
 }
Пример #6
0
 public function test_next_mismatch_event()
 {
     $gDate = \DateTime::createFromFormat('Y-m-d', '2095-3-20');
     $oDate = JalaliDate::fromDateTime($gDate)->format('Y-m-d', false);
     $sDate = jDateTime::date('Y-m-d', $gDate->getTimestamp(), false, true);
     $this->assertEquals('1473-12-30', $oDate);
     $this->assertEquals('1474-01-01', $sDate);
 }
Пример #7
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'], []));
 }
Пример #8
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'));
     }
 }
Пример #9
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function test_convert_to_days_after_farthest_supported_day_fails()
 {
     $farthest = JalaliDate::getFarthestSupportedDate();
     $this->_test_2_Way_conversion('2100-3-21', $farthest->getYear() + 1, 1, 1);
 }
Пример #10
0
 /**
  * @param string $format
  * @param string $rule
  *
  * @return string
  */
 protected function defaultSampleDate($format, $rule)
 {
     return preg_match('/^jalali/', $rule) ? JalaliDate::fromDateTime(new DateTime())->format($format, false) : JDateTime::fromDateTime(new DateTime())->format($format, false);
 }
Пример #11
0
 public function replaceAfterOrBefore($message, $attribute, $rule, $parameters)
 {
     $format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
     $date = count($parameters) ? $parameters[0] : JalaliDate::fromDateTime(new DateTime())->format($format, false);
     $faDate = StringCleaner::digitsToFarsi($date);
     return str_replace([':date', ':fa-date'], [$date, $faDate], $message);
 }
Пример #12
0
 public function publicNumberOfLeapYearsPast()
 {
     return parent::numberOfLeapYearsPast();
 }
Пример #13
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);
 }