Simplify conditionals.

Set default values to remove else cases.
This commit is contained in:
mark_story 2014-02-19 21:46:53 -05:00
parent a254d2dd6d
commit a80cbc205a

View file

@ -2116,11 +2116,10 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('day', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('day', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { if (strlen($attributes['value']) > 2) {
$Date = date_create($attributes['value']); $date = date_create($attributes['value']);
if ($Date) { $attributes['value'] = null;
$attributes['value'] = $Date->format('d'); if ($date) {
} else { $attributes['value'] = $date->format('d');
$attributes['value'] = null;
} }
} elseif ($attributes['value'] === false) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
@ -2168,11 +2167,10 @@ class FormHelper extends AppHelper {
} }
if (strlen($attributes['value']) > 4 || $attributes['value'] === 'now') { if (strlen($attributes['value']) > 4 || $attributes['value'] === 'now') {
$Date = date_create($attributes['value']); $date = date_create($attributes['value']);
if ($Date) { $attributes['value'] = null;
$attributes['value'] = $Date->format('Y'); if ($date) {
} else { $attributes['value'] = $date->format('Y');
$attributes['value'] = null;
} }
} elseif ($attributes['value'] === false) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
@ -2209,11 +2207,10 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('month', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('month', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { if (strlen($attributes['value']) > 2) {
$Date = date_create($attributes['value']); $date = date_create($attributes['value']);
if ($Date) { $attributes['value'] = null;
$attributes['value'] = $Date->format('m'); if ($date) {
} else { $attributes['value'] = $date->format('m');
$attributes['value'] = null;
} }
} elseif ($attributes['value'] === false) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
@ -2251,11 +2248,11 @@ class FormHelper extends AppHelper {
if (strlen($attributes['value']) > 2) { if (strlen($attributes['value']) > 2) {
try { try {
$Date = new DateTime($attributes['value']); $date = new DateTime($attributes['value']);
if ($format24Hours) { if ($format24Hours) {
$attributes['value'] = $Date->format('H'); $attributes['value'] = $date->format('H');
} else { } else {
$attributes['value'] = $Date->format('g'); $attributes['value'] = $date->format('g');
} }
} catch (Exception $e) { } catch (Exception $e) {
$attributes['value'] = null; $attributes['value'] = null;
@ -2297,11 +2294,10 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('min', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('min', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { if (strlen($attributes['value']) > 2) {
$Date = date_create($attributes['value']); $date = date_create($attributes['value']);
if ($Date) { $attributes['value'] = null;
$attributes['value'] = $Date->format('i'); if ($date) {
} else { $attributes['value'] = $date->format('i');
$attributes['value'] = null;
} }
} elseif ($attributes['value'] === false) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
@ -2370,11 +2366,10 @@ class FormHelper extends AppHelper {
$attributes['value'] = date('a'); $attributes['value'] = date('a');
} }
} else { } else {
$Date = date_create($attributes['value']); $date = date_create($attributes['value']);
if ($Date) { $attributes['value'] = null;
$attributes['value'] = $Date->format('a'); if ($date) {
} else { $attributes['value'] = $date->format('a');
$attributes['value'] = null;
} }
} }
} }