diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index 04db4a961d..8facba8ca8 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -32,7 +32,7 @@ HumHub Change Log - Enh: Added `Modal::closable` in order to respect `backdrop` and `keyboard` data setting of `Modal` and `ModalDialog` widget - Enh: Avoid cutting oembed entry in stream if it's the first part of a richtext - Enh: Added `humhub/widgets/TimePicker` widget - +- Enh: Added `DbDateValidator::timeZone` for setting input time zone 1.2.1 (June 17, 2017) - Fix: Invite error in french language diff --git a/protected/humhub/libs/DbDateValidator.php b/protected/humhub/libs/DbDateValidator.php index 203b682e3d..49230f7dd4 100644 --- a/protected/humhub/libs/DbDateValidator.php +++ b/protected/humhub/libs/DbDateValidator.php @@ -33,11 +33,22 @@ class DbDateValidator extends \yii\validators\DateValidator */ public $timeAttribute = ''; + /** + * @var defines the source time zone which is by default the user time zone, this can be used if a form uses an own + * timestamp setting. + */ + public $timeZone; + /** * @inheritdoc */ public function validateAttribute($model, $attribute) { + // If no source timeZone + if(empty($this->timeZone)) { + $this->timeZone = (!\Yii::$app->formatter->timeZone) ? \Yii::$app->timeZone : \Yii::$app->formatter->timeZone; + } + $timestamp = $this->parseDateTimeValue($model->$attribute, $this->getTimeValue($model)); if ($timestamp === false) { @@ -118,15 +129,14 @@ class DbDateValidator extends \yii\validators\DateValidator if ($this->hasTime() && $timeValue != "") { $timestamp += $this->parseTimeValue($timeValue); - $timeZone = (!\Yii::$app->formatter->timeZone) ? \Yii::$app->timeZone : \Yii::$app->formatter->timeZone; - $timestamp = $this->fixTimestampTimeZone($timestamp, $timeZone); + $timestamp = $this->fixTimestampTimeZone($timestamp, $this->timeZone); } return $timestamp; } /** - * Converts a timestamp in user timezone to a utc timestamp + * Converts the given timestamp from user (or configured) timezone to a utc timestamp * * @param long $ts the timestamp * @param String $timeZone users timezone @@ -153,7 +163,7 @@ class DbDateValidator extends \yii\validators\DateValidator */ protected function parseTimeValue($value) { - return strtotime($value . ':00') - strtotime('TODAY'); + return strtotime($value) - strtotime('TODAY'); } /**