diff options
Diffstat (limited to 'protected/components/DateCompareValidator.php')
| -rw-r--r-- | protected/components/DateCompareValidator.php | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/protected/components/DateCompareValidator.php b/protected/components/DateCompareValidator.php index efa6763..13a4126 100644 --- a/protected/components/DateCompareValidator.php +++ b/protected/components/DateCompareValidator.php @@ -41,15 +41,23 @@ class DateCompareValidator extends CValidator { } $start = $object->$attribute; - Yii::trace('Input value: '.$start. ' -> output timestamp: '.$object->$attribute, 'ccwn.astaf.format'); $end = $this->compareValue; - Yii::trace('Input value: '.$end. ' -> output timestamp: '.$this->compareValue, 'ccwn.astaf.format'); + + $pattern = '/[0-9]{2}\.[0-9]{2}\.[0-9]{4}\s[0-9]{2}:[0-9]{2}/'; + if (preg_match($pattern, $start)) { + $start = CDateTimeParser::parse($start, "dd.MM.yyyy HH:mm"); + } + if (preg_match($pattern, $end)) { + $end = CDateTimeParser::parse($end, "dd.MM.yyyy HH:mm"); + } //a little php trick - safe than eval and easier than a big switch statement if (version_compare($start, $end, $this->operator)) { + Yii::trace('Input value: '.$start.' - compare value: '.$end.' - operator: '.$this->operator.' - result: OK', 'ccwn.astaf.date.validate'); return; } else { + Yii::trace('Input value: '.$start.' - compare value: '.$end.' - operator: '.$this->operator.' - result: FAIL', 'ccwn.astaf.date.validate'); $message = $this->message !== null ? $this->message : Yii::t('astaf', 'The value of {attribute} ({value}) is not {operator} {compareAttribute} ({compareValue}).'); $this->addError($object, $attribute, $message, array('{operator}'=>$this->operator, '{compareValue}'=>$this->compareValue, '{value}'=>$object->$attribute, '{compareAttribute}'=>($object->getAttributeLabel($this->compareAttribute)))); } |
