Permalink
Browse files

attempt to address GMT date issue, props bradt #16

  • Loading branch information...
1 parent 175272e commit 0dbd327207098c032bc0cc282e792b5871e7f4e4 @alexkingorg alexkingorg committed Oct 25, 2012
Showing with 19 additions and 2 deletions.
  1. +12 −0 classes/aktt.php
  2. +7 −2 classes/aktt_tweet.php
View
12 classes/aktt.php
@@ -1114,6 +1114,18 @@ static function download_tweet($status_id, $username = null) {
}
return $tweet;
}
+
+ static function gmt_to_wp_time($gmt_time) {
+ $gmt_date = date('Y-m-d H:i:s', $gmt_time);
+
+ // Not using get_option('gmt_offset') because it gets the offset for the
+ // current date/time which doesn't work for timezones with daylight savings time.
+ $datetime = new DateTime($gmt_date);
+ $datetime->setTimezone(new DateTimeZone(get_option('timezone_string')));
+ $offset_in_secs = $datetime->getOffset();
+
+ return $gmt_time + $offset_in_secs;
+ }
}
View
9 classes/aktt_tweet.php
@@ -463,14 +463,16 @@ function sideload_image() {
* @return void
*/
function add() {
+ $gmt_time = self::twdate_to_time($this->date());
// Build the post data
$data = apply_filters('aktt_tweet_add', array(
'post_title' => $this->title(),
'post_name' => $this->id(),
'post_content' => $this->content(),
'post_status' => 'publish',
'post_type' => AKTT::$post_type,
- 'post_date_gmt' => date('Y-m-d H:i:s', self::twdate_to_time($this->date())),
+ 'post_date' => date('Y-m-d H:i:s', AKTT::gmt_to_wp_time($gmt_time)),
+ 'post_date_gmt' => date('Y-m-d H:i:s', $gmt_time),
'guid' => $this->guid(),
// 'tax_input' => $tax_input, // see below...
));
@@ -541,6 +543,8 @@ function create_blog_post($args = array()) {
$post_content .= "\n\n".wp_get_attachment_image($this->featured_image_id, $size);
}
+ $gmt_time = self::twdate_to_time($this->meta['created_at']);
+
// Build the post data
$data = array(
'post_title' => $title_prefix.$this->title(),
@@ -553,7 +557,8 @@ function create_blog_post($args = array()) {
// ),
'post_status' => 'publish',
'post_type' => 'post',
- 'post_date_gmt' => date('Y-m-d H:i:s', self::twdate_to_time($this->meta['created_at'])),
+ 'post_date' => date('Y-m-d H:i:s', AKTT::gmt_to_wp_time($gmt_time)),
+ 'post_date_gmt' => date('Y-m-d H:i:s', $gmt_time),
'guid' => $this->guid().'-post'
);
$data = apply_filters('aktt_tweet_create_blog_post_data', $data);

0 comments on commit 0dbd327

Please sign in to comment.