pluf2

pluf2 Commit Details


Date:2012-04-22 17:30:20 (12 years 7 months ago)
Author:Thomas Keller
Branch:master
Commit:c68ed31ead9561883676a37bf0d2efb9e6f8b6ea
Parents: 0165f9ae4fe873afbf963ff5ba194bf99d9387f7
Message:Skip validation of dates and datetimes if a form field is not required and the entered value is recognized as empty value; also streamline the datetime validation a little more according to the date validation and don't accept '60' in the seconds part silently.

Changes:

File differences

src/Pluf/Form/Field/Date.php
3535
3636
3737
38
39
40
3841
3942
4043
public function clean($value)
{
parent::clean($value);
if (in_array($value, $this->empty_values)) {
return '';
}
foreach ($this->input_formats as $format) {
if (false !== ($date = strptime($value, $format))) {
$day = $date['tm_mday'];
src/Pluf/Form/Field/Datetime.php
3939
4040
4141
42
42
43
44
4345
4446
45
46
47
48
49
50
51
52
53
54
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
5564
5665
57
58
59
60
6166
6267
6368
public function clean($value)
{
parent::clean($value);
$out = null;
if (in_array($value, $this->empty_values)) {
return '';
}
foreach ($this->input_formats as $format) {
if (false !== ($date = strptime($value, $format))) {
$day = str_pad($date['tm_mday'], 2, '0', STR_PAD_LEFT);
$month = str_pad($date['tm_mon']+1, 2, '0', STR_PAD_LEFT);
$year = str_pad($date['tm_year']+1900, 4, '0', STR_PAD_LEFT);
$h = str_pad($date['tm_hour'], 2, '0', STR_PAD_LEFT);
$m = str_pad($date['tm_min'], 2, '0', STR_PAD_LEFT);
$s = $date['tm_sec'];
if ($s > 59) $s=59;
$s = str_pad($s, 2, '0', STR_PAD_LEFT);
$out = $year.'-'.$month.'-'.$day.' '.$h.':'.$m.':'.$s;
break;
$day = $date['tm_mday'];
$month = $date['tm_mon'] + 1;
$year = $date['tm_year'] + 1900;
// PHP's strptime has various quirks, e.g. it doesn't check
// gregorian dates for validity and it also allows '60' in
// the seconds part
if (checkdate($month, $day, $year) && $date['tm_sec'] < 60) {
$date = str_pad($year, 4, '0', STR_PAD_LEFT).'-'.
str_pad($month, 2, '0', STR_PAD_LEFT).'-'.
str_pad($day, 2, '0', STR_PAD_LEFT).' '.
str_pad($date['tm_hour'], 2, '0', STR_PAD_LEFT).':'.
str_pad($date['tm_min'], 2, '0', STR_PAD_LEFT).':';
str_pad($date['tm_sec'], 2, '0', STD_PAD_LEFT);
// we internally use GMT, so we convert it to a GMT date.
return gmdate('Y-m-d H:i:s', strtotime($date));
}
}
}
if ($out !== null) {
// We internally use GMT, so we convert it to a GMT date.
return gmdate('Y-m-d H:i:s', strtotime($out));
}
throw new Pluf_Form_Invalid(__('Enter a valid date/time.'));
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05474s using 13 queries.