Skip to content

Commit

Permalink
Updated config and added date time attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
omnilight committed Feb 19, 2015
1 parent 5930bf6 commit 35c11f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions DatePickerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace omnilight\datetime;

use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;
use yii\helpers\FormatConverter;
use yii\i18n\Formatter;


/**
Expand All @@ -27,10 +25,16 @@ public static function get(DateTimeAttribute $attribute, $options = [], $datePic
$defaults = [
'language' => \Yii::$app->language,
'clientOptions' => [
'dateFormat' => 'php://'.FormatConverter::convertDateIcuToJui($format[1], $format[0]),
'dateFormat' => 'php:' . FormatConverter::convertDateIcuToJui($format[1], $format[0]),
]
];
break;
case 'omnilight\widgets\DatePicker':
$defaults = [
'language' => \Yii::$app->language,
'dateFormat' => 'php:' . FormatConverter::convertDateIcuToPhp($format[1], $format[0]),
];
break;
default:
return $options;
}
Expand Down
6 changes: 5 additions & 1 deletion DateTimeAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace omnilight\datetime;

use yii\base\Object;
use yii\helpers\FormatConverter;


/**
Expand Down Expand Up @@ -67,6 +68,9 @@ public function getValue()
public function setValue($value)
{
$this->_value = $value;
$this->behavior->owner->{$this->originalAttribute} = $this->behavior->formatter->format($this->_value, $this->originalFormat);
$normalizedFormat = DateTimeBehavior::normalizeIcuFormat($this->targetFormat, $this->behavior->formatter);
$phpFormat = FormatConverter::convertDateIcuToPhp($normalizedFormat[1], $normalizedFormat[0], \Yii::$app->language);
$value = date_create_from_format($phpFormat, $value);
$this->behavior->owner->{$this->originalAttribute} = $this->behavior->formatter->format($value, $this->originalFormat);
}
}

0 comments on commit 35c11f3

Please sign in to comment.