Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug fix: Post date being set to current date. #16

Closed
wants to merge 1 commit into from

2 participants

@bradt

Also, not respecting daylight savings time.

@alexkingorg
Owner

Awesome! We need to implement this in two places ($tweet->add() and $tweet->create_blog_post()) so I'll abstract this to a utility method.

Thanks, I hadn't known about the DST issue.

@bradt

No prob, thanks for releasing this plugin, maintaining it, and providing support. I know first hand how much work is involved. :)

@alexkingorg
Owner

Uh-oh, this approach doesn't work as currently coded. There is a "Manual" section of time zones that we need to account for. This fix is working for me:

https://github.com/crowdfavorite/wp-twitter-tools/commits/feature/3.0.1-date-fix

Please confirm, thanks!

@alexkingorg
Owner

Ok, it's working for me and I only have time today to release so off we go. We can always do a 3.0.3 if needed. :)

@bradt

FYI, I believe this is the relevant bug reported in core:
http://core.trac.wordpress.org/ticket/20328

@bradt bradt referenced this pull request from a commit in bradt/wp-twitter-tools
@alexkingorg alexkingorg attempt to address GMT date issue, props bradt crowdfavorite#16 0dbd327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 24, 2012
  1. @bradt
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 1 deletion.
  1. +11 −1 classes/aktt_tweet.php
View
12 classes/aktt_tweet.php
@@ -463,6 +463,15 @@ function sideload_image() {
* @return void
*/
function add() {
+ $gmt_time = self::twdate_to_time($this->date());
+ $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();
+
// Build the post data
$data = apply_filters('aktt_tweet_add', array(
'post_title' => $this->title(),
@@ -470,7 +479,8 @@ function add() {
'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_gmt' => date('Y-m-d H:i:s', $gmt_time),
+ 'post_date' => date('Y-m-d H:i:s', $gmt_time + $offset_in_secs),
'guid' => $this->guid(),
// 'tax_input' => $tax_input, // see below...
));
Something went wrong with that request. Please try again.