Skip to content

Commit 1c99f89

Browse files
committed
Add dbDateFormat to support Oracle (and other) formatting
1 parent b1c55c7 commit 1c99f89

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NotificationsModule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class NotificationsModule extends Module
2525
*/
2626
public $allowDuplicate = false;
2727

28+
/**
29+
* @var string Database created_at field format
30+
*/
31+
public $dbDateFormat = 'Y-m-d H:i:s';
32+
2833
/**
2934
* @var callable|integer The current user id
3035
*/

controllers/NotificationsController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function actionPoll($seen = 0)
5454
$results = [];
5555

5656
foreach ($models as $model) {
57+
58+
// give user a chance to parse the date as needed
59+
$date = \DateTime::createFromFormat($this->module->dbDateFormat, $model->created_at)
60+
->format('Y-m-d H:i:s');
61+
5762
/** @var Notification $model */
5863
$results[] = [
5964
'id' => $model->id,
@@ -63,7 +68,7 @@ public function actionPoll($seen = 0)
6368
'url' => Url::to(['notifications/rnr', 'id' => $model->id]),
6469
'key' => $model->key,
6570
'flashed' => $model->flashed,
66-
'date' => $model->created_at
71+
'date' => $date,
6772
];
6873
}
6974
return $results;

docs/Configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ return [
2020
// Allow to have notification with same (user_id, key, key_id)
2121
// Default to FALSE
2222
'allowDuplicate' => false,
23+
// Allow custom date formatting in database
24+
'dbDateFormat' => 'Y-m-d H:i:s',
2325
// This callable should return your logged in user Id
2426
'userId' => function() {
2527
return \Yii::$app->user->id;

0 commit comments

Comments
 (0)