Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DateTimeBetween
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
10
100.00% covered (success)
100.00%
1 / 1
 evaluate
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 generateDefaultMessage
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
7
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@noladev.com>
7 * @copyright  Copyright (c) 2009-2025 NOLA Interactive, LLC.
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Validator;
15
16/**
17 * Date-time between validator class
18 *
19 * @category   Pop
20 * @package    Pop\Validator
21 * @author     Nick Sagona, III <dev@noladev.com>
22 * @copyright  Copyright (c) 2009-2025 NOLA Interactive, LLC.
23 * @license    http://www.popphp.org/license     New BSD License
24 * @version    4.5.0
25 */
26class DateTimeBetween extends Between
27{
28
29    /**
30     * Traits
31     */
32    use DateTimeTrait;
33
34    /**
35     * Method to evaluate the validator
36     *
37     * @param  mixed $input
38     * @return bool
39     */
40    public function evaluate(mixed $input = null): bool
41    {
42        if ($input !== null) {
43            $input = strtotime($input);
44        }
45
46        // Set the default message
47        if (!$this->hasMessage()) {
48            $this->generateDefaultMessage();
49        }
50
51        return parent::evaluate($input);
52    }
53
54    /**
55     * Generate default message
56
57     * @param  mixed  $name
58     * @param  mixed  $value
59     * @return string
60     */
61    public function generateDefaultMessage(mixed $name = null, mixed $value = null): string
62    {
63        $value1 = null;
64        $value2 = null;
65
66        if (($this->value !== null) && is_array($this->value) && (count($this->value) == 2)) {
67            $value1 = $this->value[0];
68            $value2 = $this->value[1];
69
70            if (!empty($this->dateTimeFormat)) {
71                if (is_numeric($value1)) {
72                    $value1 = date($this->dateTimeFormat, $value1);
73                }
74                if (is_numeric($value2)) {
75                    $value1 = date($this->dateTimeFormat, $value2);
76                }
77            }
78        }
79
80        return parent::generateDefaultMessage($name, [$value1, $value2]);
81    }
82
83}