Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Rewrite the attribute value (unix timestamp) to a datetime #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public function init()
*/
public function run()
{
if($this->hasModel()){
$this->model->{$this->attribute} = \Yii::$app->formatter->asDatetime($this->model->{$this->attribute});
}

$input = $this->hasModel()
? Html::activeTextInput($this->model, $this->attribute, $this->options)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/DateTimePickerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testRenderWithModel()
'model' => $model,
'attribute' => 'create_time'
]);
$expected = '<div class="input-group date"><input type="text" id="post-create_time" class="form-control" name="Post[create_time]" value="1425807308" readonly="readonly"><span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span><span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span></div>';
$expected = '<div class="input-group date"><input type="text" id="post-create_time" class="form-control" name="Post[create_time]" value="Mar 8, 2015 9:35:08 AM" readonly="readonly"><span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span><span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span></div>';

$this->assertEqualsWithoutLE($expected, $out);
}
Expand Down