Enh: Added DbDateValidator::timeZone for setting input time zone

This commit is contained in:
buddh4 2017-07-21 20:36:07 +02:00
parent 7d3a4fb9f0
commit 2b6e1c73d0
2 changed files with 15 additions and 5 deletions

View File

@ -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

View File

@ -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');
}
/**