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());
 }
Esempio n. 2
0
 public function sample_1()
 {
     $dateTime = \DateTime::createFromFormat('Y-m-d', '2015-09-03');
     $jalaliDate = JalaliDate::fromDateTime($dateTime);
     print "\n";
     print $jalaliDate->format('D S M ماه سال X');
 }
Esempio n. 3
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);
 }
Esempio n. 4
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'], []));
 }
Esempio n. 5
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'));
     }
 }
Esempio n. 6
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);
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 public function test_from_date_time()
 {
     $dateTime = \DateTime::createFromFormat('Y-m-d', '2015-08-23');
     $jDate = new JalaliDate(1394, 6, 1);
     $this->assertEquals($jDate, JalaliDate::fromDateTime($dateTime));
 }