Ejemplo n.º 1
0
 public function test_jalali_after_or_before_replacer_is_applied_with_date_and_format()
 {
     $now = '1394-9-15';
     $faNow = StringCleaner::digitsToFarsi($now);
     $validator = $this->factory->make(['graduation_date' => 'garbage'], ['graduation_date' => "required|jalali_after:{$now},Y-m-d|jalali_before:{$now},Y-m-d"]);
     $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());
 }
Ejemplo n.º 2
0
 public function sample_5()
 {
     print StringCleaner::digitsToFarsi('1394');
     print "\n";
     print StringCleaner::digitsToEnglish('۱۳۹۴');
     print "\n";
     print StringCleaner::arabicToFarsi('كيك پي اچ پي چيست؟');
     print "\n";
 }
Ejemplo n.º 3
0
 /**
  * @param string $format
  * @param string $date
  * @throw InvalidArgumentException
  * @return JalaliDate
  */
 public static function createJalaliFromFormat($format, $date)
 {
     $dateParts = new DateParts();
     $regexp = '';
     $matchCount = 0;
     $escaped = false;
     $functions = str_split($format);
     foreach ($functions as $function) {
         if ($escaped) {
             $regexp .= preg_quote($function);
             $escaped = false;
         } elseif ($function === '\\') {
             $escaped = true;
         } elseif ($function === '.') {
             $regexp .= '.';
         } elseif ($function === '*') {
             $regexp .= '.*';
         } elseif ($function === '/') {
             $regexp .= '\\/';
         } elseif (array_key_exists($function, static::$conversionFunctions)) {
             $f = static::$conversionFunctions[$function];
             $regexp .= '(' . static::$f($dateParts, $matchCount) . ')';
         } else {
             $regexp .= preg_quote($function);
         }
     }
     if ($dateParts->isAmbiguous()) {
         throw new InvalidArgumentException();
     }
     $regexp = "/^{$regexp}\$/";
     $date = StringCleaner::digitsToEnglish($date);
     if (!preg_match($regexp, $date, $matches)) {
         throw new InvalidArgumentException();
     }
     $dateParts->fillWithMatches($matches);
     return $dateParts->createJalaliDate();
 }
Ejemplo n.º 4
0
 public function test_convert_digits_to_English()
 {
     $this->assertEquals('09134107', $this->cleaner->digitsToEnglish('۰۹۱۳۴۱۰۷'));
     $this->assertEquals('09134107', $this->cleaner->digitsToEnglish('۰۹۱۳۴۱0۷'));
     $this->assertEquals('09134107abcd', $this->cleaner->digitsToEnglish('۰۹۱۳۴۱0۷abcd'));
 }
Ejemplo n.º 5
0
 public function replaceAfterOrBefore($message, $attribute, $rule, $parameters)
 {
     $format = count($parameters) > 1 ? $parameters[1] : $this->defaultFormat($rule);
     $date = count($parameters) ? $parameters[0] : $this->defaultSampleDate($format, $rule);
     $faDate = StringCleaner::digitsToFarsi($date);
     return str_replace([':date', ':fa-date'], [$date, $faDate], $message);
 }
Ejemplo n.º 6
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);
 }