From ec2dacf90e9e9ccc56303219d178fc1924ffe5ea Mon Sep 17 00:00:00 2001 From: Lawrence Kay Date: Wed, 17 Jul 2019 15:39:58 +0900 Subject: [PATCH 1/3] [fix] Issue #3 resolved * Rounded up milliseconds for DateTime::__construct --- src/Config/APNsConfig.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Config/APNsConfig.php b/src/Config/APNsConfig.php index 87dfbed..54893f8 100644 --- a/src/Config/APNsConfig.php +++ b/src/Config/APNsConfig.php @@ -8,6 +8,10 @@ namespace phpFCMv1\Config; +use DateInterval; +use DateTime; +use Exception; + class APNsConfig implements CommonConfig { const PRIORITY_HIGH = '10', PRIORITY_NORMAL = '5'; private $payload; @@ -45,11 +49,11 @@ function setPriority($priority) { /** * @param $time : Time for notification to live in seconds * @return mixed : Expiration option using UNIX epoch date - * @throws \Exception + * @throws Exception */ function setTimeToLive($time) { - $expiration = new \DateTime('now'); - $expiration -> add(new \DateInterval('PT' . $time . 'S')); + $expiration = DateTime::createFromFormat('U', $this->roundUpMilliseconds()); + $expiration -> add(new DateInterval('PT' . $time . 'S')); $expValue = $expiration -> format('U'); $payload = array_merge($this -> payload, array('apns-expiration' => $expValue)); @@ -71,4 +75,14 @@ public function getPayload() { return $payload; } } + + /** + * Path for PHP@7.2. Refer to the issue. + * https://github.com/lkaybob/php-fcm-v1/issues/3 + * @return string + */ + private function roundUpMilliseconds() { + $converted = (new DateTime('now'))->add(new DateInterval('PT1S')); + return $converted->format('U'); + } } \ No newline at end of file From 43eb8168e00d216b9a686f272b40a618dc498a4b Mon Sep 17 00:00:00 2001 From: Lawrence Kay Date: Wed, 17 Jul 2019 15:51:59 +0900 Subject: [PATCH 2/3] [fix] Issue #3 implemented * Fixed broken build < 7.1 --- src/Config/APNsConfig.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Config/APNsConfig.php b/src/Config/APNsConfig.php index 54893f8..d935317 100644 --- a/src/Config/APNsConfig.php +++ b/src/Config/APNsConfig.php @@ -82,7 +82,12 @@ public function getPayload() { * @return string */ private function roundUpMilliseconds() { - $converted = (new DateTime('now'))->add(new DateInterval('PT1S')); + $converted = new DateTime('now'); + + if ($converted->format('u') != 0) { + $converted = $converted->add(new DateInterval('PT1S')); + } + return $converted->format('U'); } } \ No newline at end of file From 3fe45ed45d79e1188ac6cbdb956ff54f5a28275b Mon Sep 17 00:00:00 2001 From: Lawrence Kay Date: Wed, 17 Jul 2019 16:28:31 +0900 Subject: [PATCH 3/3] [fix] Issue #3 implemented * Fixed broken build on 7.1 --- src/Config/APNsConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/APNsConfig.php b/src/Config/APNsConfig.php index d935317..109b019 100644 --- a/src/Config/APNsConfig.php +++ b/src/Config/APNsConfig.php @@ -84,7 +84,7 @@ public function getPayload() { private function roundUpMilliseconds() { $converted = new DateTime('now'); - if ($converted->format('u') != 0) { + if ($converted->format('u') != 0 && strpos(PHP_VERSION,'7.1') !== 0) { $converted = $converted->add(new DateInterval('PT1S')); }