norkunas / onesignal-php-api

OneSignal API for PHP
MIT License
234 stars 83 forks source link

Notifications may not be scheduled in the past. #21

Closed devfelipereis closed 8 years ago

devfelipereis commented 8 years ago

Hello!

I can't send notifications with send_after. I have this object:

Carbon {#557 ▼
  +"date": "2016-02-23 16:00:00"
  +"timezone_type": 3
  +"timezone": "UTC"
}

Date now

Carbon {#557 ▼
  +"date": "2016-02-23 15:43:26"
  +"timezone_type": 3
  +"timezone": "UTC"
}

I have a Carbon object but it extends DateTime and it pass in your validation.

A dd in:

 ->setNormalizer('send_after', function (Options $options, \DateTime $value) {
                //Fri May 02 2014 00:00:00 GMT-0700 (PDT)
                return $value->format('D M d Y H:i:s eO (T)');
            })

give me this result: Tue Feb 23 2016 16:00:00 UTC+0000 (UTC)

I don't know if I'm missing something. Could you help me?

Thank!

EDIT

For the notification in the date "2016-02-23 15:43:26" be sent, I need to put 3 hours more: "2016-02-23 18:43:26".

norkunas commented 8 years ago

Hello,

Why do you want to provide the past date?

devfelipereis commented 8 years ago

But it's not in the past. I was sending at "2016-02-23 15:43:26" to the date "2016-02-23 16:00:00"(17 minutes later).

norkunas commented 8 years ago

@devfelipereis i've tested send_after option currently and for me it is working as intended, but with a little delay because of my time (which was March 24th 2016, 3:56:46 pm UTC +02:00) and onesignal server time difference.

$api->notifications->add([
    'included_segments' => array('..'),
    'data' => array('foo' => 'bar'),
    'contents' => ['en'=>'testing send after issue'],
    'send_after' => new \DateTime('1 minute'),
]);

Scheduled

And after that time: Completed

jonasof commented 8 years ago

Same problem here, the problem is with timezones:

//in Notifications.php, line 268, $value is a Carbon\Carbon variable:
$value->format('D M d Y H:i:s eO (T)'); 
// returns: "Tue Jun 21 2016 14:02:01 America/Sao_Paulo-0300 (BRT)"

OneSignal seems to not understand the "America/Sao_Paulo-0300 (BRT)", so firstly convert the carbon timezone to GMT:

'send_after' => $carbon_variable->setTimezone('GMT'),

This should send the message in the right time.

norkunas commented 8 years ago

Then I could add a note that the date timezone should be converted to GMT or UTC if this would help.