Code Duplication    Length = 17-17 lines in 3 locations

src/Forms/DateField.php 1 location

@@ 568-584 (lines=17) @@
565
     * @param string $date Date in ISO 8601 or approximate form
566
     * @return string ISO 8601 date, or null if not valid
567
     */
568
    protected function tidyInternal($date)
569
    {
570
        if (!$date) {
571
            return null;
572
        }
573
        // Re-run through formatter to tidy up (e.g. remove time component)
574
        $formatter = $this->getInternalFormatter();
575
        $timestamp = $formatter->parse($date);
576
        if ($timestamp === false) {
577
            // Fallback to strtotime
578
            $timestamp = strtotime($date, DBDatetime::now()->getTimestamp());
579
            if ($timestamp === false) {
580
                return null;
581
            }
582
        }
583
        return $formatter->format($timestamp);
584
    }
585
}
586

src/Forms/DatetimeField.php 1 location

@@ 400-416 (lines=17) @@
397
     * @param string $date Date in ISO 8601 or approximate form
398
     * @return string ISO 8601 date, or null if not valid
399
     */
400
    public function tidyInternal($datetime)
401
    {
402
        if (!$datetime) {
403
            return null;
404
        }
405
        // Re-run through formatter to tidy up (e.g. remove time component)
406
        $formatter = $this->getInternalFormatter();
407
        $timestamp = $formatter->parse($datetime);
408
        if ($timestamp === false) {
409
            // Fallback to strtotime
410
            $timestamp = strtotime($datetime, DBDatetime::now()->getTimestamp());
411
            if ($timestamp === false) {
412
                return null;
413
            }
414
        }
415
        return $formatter->format($timestamp);
416
    }
417
418
    /**
419
     * Get length of the date format to use. One of:

src/Forms/TimeField.php 1 location

@@ 440-456 (lines=17) @@
437
     * @param string $time Time in ISO 8601 or approximate form
438
     * @return string ISO 8601 time, or null if not valid
439
     */
440
    protected function tidyInternal($time)
441
    {
442
        if (!$time) {
443
            return null;
444
        }
445
        // Re-run through formatter to tidy up (e.g. remove date component)
446
        $formatter = $this->getInternalFormatter();
447
        $timestamp = $formatter->parse($time);
448
        if ($timestamp === false) {
449
            // Fallback to strtotime
450
            $timestamp = strtotime($time, DBDatetime::now()->getTimestamp());
451
            if ($timestamp === false) {
452
                return null;
453
            }
454
        }
455
        return $formatter->format($timestamp);
456
    }
457
458
    /**
459
     * @return string