{"action":"created","issue":{"url":"https://api.github.com/repos/Prospress/action-scheduler/issues/43","repository_url":"https://api.github.com/repos/Prospress/action-scheduler","labels_url":"https://api.github.com/repos/Prospress/action-scheduler/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/Prospress/action-scheduler/issues/43/comments","events_url":"https://api.github.com/repos/Prospress/action-scheduler/issues/43/events","html_url":"https://github.com/Prospress/action-scheduler/pull/43","id":113994957,"number":43,"title":"Timezone fixes","user":{"login":"thenbrent","id":235523,"avatar_url":"https://avatars.githubusercontent.com/u/235523?v=3","gravatar_id":"","url":"https://api.github.com/users/thenbrent","html_url":"https://github.com/thenbrent","followers_url":"https://api.github.com/users/thenbrent/followers","following_url":"https://api.github.com/users/thenbrent/following{/other_user}","gists_url":"https://api.github.com/users/thenbrent/gists{/gist_id}","starred_url":"https://api.github.com/users/thenbrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thenbrent/subscriptions","organizations_url":"https://api.github.com/users/thenbrent/orgs","repos_url":"https://api.github.com/users/thenbrent/repos","events_url":"https://api.github.com/users/thenbrent/events{/privacy}","received_events_url":"https://api.github.com/users/thenbrent/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Prospress/action-scheduler/labels/priority:low","name":"priority:low","color":"c7def8"}],"state":"open","locked":false,"assignee":{"login":"mattallan","id":2275145,"avatar_url":"https://avatars.githubusercontent.com/u/2275145?v=3","gravatar_id":"","url":"https://api.github.com/users/mattallan","html_url":"https://github.com/mattallan","followers_url":"https://api.github.com/users/mattallan/followers","following_url":"https://api.github.com/users/mattallan/following{/other_user}","gists_url":"https://api.github.com/users/mattallan/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallan/subscriptions","organizations_url":"https://api.github.com/users/mattallan/orgs","repos_url":"https://api.github.com/users/mattallan/repos","events_url":"https://api.github.com/users/mattallan/events{/privacy}","received_events_url":"https://api.github.com/users/mattallan/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-10-29T07:24:04Z","updated_at":"2016-05-13T04:48:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Prospress/action-scheduler/pulls/43","html_url":"https://github.com/Prospress/action-scheduler/pull/43","diff_url":"https://github.com/Prospress/action-scheduler/pull/43.diff","patch_url":"https://github.com/Prospress/action-scheduler/pull/43.patch"},"body":"This is the first draft of a PR to ensure we use UTC and `post_date_gmt` to avoid issues relating to daylight savings time, changes to the site's timezone and 3rd party code calling `date_default_timezone_set()`."},"comment":{"url":"https://api.github.com/repos/Prospress/action-scheduler/issues/comments/218951166","html_url":"https://github.com/Prospress/action-scheduler/pull/43#issuecomment-218951166","issue_url":"https://api.github.com/repos/Prospress/action-scheduler/issues/43","id":218951166,"user":{"login":"mattallan","id":2275145,"avatar_url":"https://avatars.githubusercontent.com/u/2275145?v=3","gravatar_id":"","url":"https://api.github.com/users/mattallan","html_url":"https://github.com/mattallan","followers_url":"https://api.github.com/users/mattallan/followers","following_url":"https://api.github.com/users/mattallan/following{/other_user}","gists_url":"https://api.github.com/users/mattallan/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallan/subscriptions","organizations_url":"https://api.github.com/users/mattallan/orgs","repos_url":"https://api.github.com/users/mattallan/repos","events_url":"https://api.github.com/users/mattallan/events{/privacy}","received_events_url":"https://api.github.com/users/mattallan/received_events","type":"User","site_admin":false},"created_at":"2016-05-13T04:48:06Z","updated_at":"2016-05-13T04:48:06Z","body":"There are still some timezone issues in the action scheduler which I think are stemming from the use of `new DateTime();` especially when we fire off a scheduled action, and then check if original scheduled time is still in the future (to see if the AS should reschedule at the original time)\r\n\r\nStepping through the code..\r\nAfter the action is run, see if we need to reschedule it. \r\n\r\n```\r\nprotected function schedule_next_instance( ActionScheduler_Action $action ) {\r\n\t$next = $action->get_schedule()->next( new DateTime() );\r\n\tif ( $next ) {\r\n\t\t$this->store->save_action( $action, $next );\r\n\t}\r\n}\r\n```\r\n\r\n[`next()`](https://github.com/Prospress/action-scheduler/blob/master/classes/ActionScheduler_SimpleSchedule.php#L18) will return null if the next scheduled date is not in the future.\r\n\r\nThis is where the issue is. It shouldn't return a next date that is in the future, so now going to where the scheduled date is stored ([here](https://github.com/Prospress/action-scheduler/blob/master/classes/ActionScheduler_ActionFactory.php#L15))\r\n\r\n```\r\npublic function single( $hook, $args = array(), $when = NULL, $group = '' ) {\r\n\t$date = ActionScheduler::get_datetime_object( $when );\r\n\t$schedule = new ActionScheduler_SimpleSchedule( $date );\r\n\t$action = new ActionScheduler_Action( $hook, $args, $schedule, $group );\r\n\treturn $this->store( $action );\r\n}\r\n```\r\n\r\nThe [`get_date_object()`](https://github.com/Prospress/action-scheduler/blob/master/classes/ActionScheduler.php#L31) function looks like:\r\n\r\n```\r\npublic static function get_datetime_object( $when ) {\r\n\t\t$when = empty($when) ? time() : $when;\r\n\t\tif ( is_object($when) && $when instanceof DateTime ) {\r\n\t\t\t$date = $when;\r\n\t\t} elseif ( is_numeric( $when ) ) {\r\n\t\t\t$date = new DateTime( '@'.$when );\r\n\t\t} else {\r\n\t\t\t$date = new DateTime( $when );\r\n\t\t}\r\n\t\treturn $date;\r\n\t}\r\n```\r\n\r\n@thenbrent: following your recent changes, should we adding `new DateTimeZone('UTC')` to these DateTime uses?\r\n\r\nI was using https://gimme.subscription.beer/AS_Timezones to test and replicate the bug."}}