Skip to content

Commit

Permalink
Use DateTimeHelper to serialize ISO8601 UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
Bui Sy Nguyen committed Apr 27, 2016
1 parent 70fca81 commit b08c628
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions fproject/amqp/ActivityNoticeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
///////////////////////////////////////////////////////////////////////////////
namespace fproject\amqp;

use fproject\common\utils\DateTimeHelper;
use fproject\common\utils\JsonHelper;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
Expand Down Expand Up @@ -122,7 +123,7 @@ public function getSerializer()
* @param array $modelList1 if $action is "batchSave", this will be the inserted models, if action is "batchDelete" and
* there's multiple deletion executed, this will be the deleted models
* @param array $modelList2 if $action is "batchSave", this will be the updated models, if action is "batchDelete", this parameter is ignored.
* @return ActivityNotice The activity notice data that sent to AMQP Server
* @return ActivityNotice The activity notice data that sent to AMQP Server. If the notification action is failed, FALSE will be returned.
*/
public function noticeAfterModelAction($data, $configType, $action, $attributeNames=null, $modelList1=null, $modelList2=null)
{
Expand All @@ -138,13 +139,13 @@ public function noticeAfterModelAction($data, $configType, $action, $attributeNa
$config = $serializer->getActivityNoticeConfig($classId, $noticeAction, $attributeNames);

if(!isset($config))
return;
return false;

$a=explode('\\', $classId);
$shortClassId = array_pop($a);
$notice = new ActivityNotice([
'kind'=>lcfirst($shortClassId).'AUD',
'dispatchTime'=>date(DATE_ISO8601, time()),
'dispatchTime'=>DateTimeHelper::currentDateTime(),
'dispatcher'=>$this->getDispatcher(),
'contentUpdatedFields'=>$attributeNames
]);
Expand Down
3 changes: 2 additions & 1 deletion fproject/amqp/ActivityNoticeSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//
///////////////////////////////////////////////////////////////////////////////
namespace fproject\amqp;
use fproject\common\utils\DateTimeHelper;
use ReflectionClass;
use ReflectionProperty;
use Exception;
Expand Down Expand Up @@ -366,7 +367,7 @@ public function getSerializeData($data, $config)
if($sd[$att] instanceof \DateTime) {
/** @var \DateTime $date */
$date = $sd[$att];
$sd[$att] = $date->format(DATE_ISO8601);
$sd[$att] = DateTimeHelper::toISO8601UTC($date);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ActivityNoticeSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testGetSerializeData01()
$this->assertArrayNotHasKey('field3',$data);
$this->assertArrayHasKey('field2',$data);
$this->assertArrayHasKey('field1',$data);
$this->assertEquals($model->field1->format(DATE_ISO8601),$data['field1']);
$this->assertEquals($model->field1->format(\fproject\common\utils\DateTimeHelper::DATE_ISO8601_UTC),$data['field1']);
}

public function testGetSerializeData02()
Expand Down Expand Up @@ -184,7 +184,7 @@ public function testGetSerializeData05()
$this->assertArrayHasKey('field1',$data);
/** @var DateTime $tmpDate */
$tmpDate = $model['field1'];
$this->assertEquals($tmpDate->format(DATE_ISO8601),$data['field1']);
$this->assertEquals($tmpDate->format(\fproject\common\utils\DateTimeHelper::DATE_ISO8601_UTC),$data['field1']);
}

public function testGetSerializeData06()
Expand Down

0 comments on commit b08c628

Please sign in to comment.