Skip to content
Merged
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
25 changes: 22 additions & 3 deletions src/Config/APNsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -71,4 +75,19 @@ 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');

if ($converted->format('u') != 0 && strpos(PHP_VERSION,'7.1') !== 0) {
$converted = $converted->add(new DateInterval('PT1S'));
}

return $converted->format('U');
}
}