Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ok.. so my simple hack. I compared what the time stamp of the widget was for my older post and compared it to the stamp on twitter. For me it was 7 hours which equates to 25200 seconds.

    So I just subtracted that from the &original before subtracting from $today.

    $since = $today - ($original - 25200);

    I know this is kind of a hack and I would like to know why twitter is 7 hours ahead. Also if its always 7 ahead, or if it gains/losses time. Also if it is 7 hours for everyone. Maybe timezone does matter?

    So many questions, but at least it works for my site (for now).

    I have been battling this problem since yesterday. I hunted down the wpcom_time_since(strtotime($tweet['created_at'])))
    and figured it for the problem. However I dint think I would have come to a solution for it. So thank you Tim for that.

    I have been looking at the wpcom_time_since function as a possible cause

    function wpcom_time_since( $original, $do_more = 0 ) {
    	// array of time period chunks
    	$chunks = array(
    		array( 60 * 60 * 24 * 365 , 'year' ),
    		array( 60 * 60 * 24 * 30 , 'month' ),
    		array( 60 * 60 * 24 * 7, 'week' ),
    		array( 60 * 60 * 24 , 'day' ),
    		array( 60 * 60 , 'hour' ),
    		array( 60 , 'minute' ),
    	);
    
    	$today = time();
    	$since =  $today - $original;
    
    	for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) {
    		$seconds = $chunks[$i][0];
    		$name = $chunks[$i][1];
    
    		if ( ( $count = floor( $since / $seconds ) ) != 0 )
    			break;
    	}
    
    $print = ( $count == 1 ) ? '1 ' . $name : $count . $name . 's';
    
    	if ( $i + 1 < $j ) {
    		$seconds2 = $chunks[$i + 1][0];
    		$name2 = $chunks[$i + 1][1];
    
    		// add second item if it's greater than 0
    		if ( ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) && $do_more )
    			$print .= ( $count2 == 1 ) ? ', 1 ' . $name2 : ", $count2 {$name2}s";
    	}
    	return $print;

    Now I am getting the -1 year problem myself. I am still hunting down the root of the problem, but I found the $original value that is passed from created_at is larger then the current time. So $since is set to a negative number which messes with the wpcom_time_since function.

    I don’t know enough yet with php or twitter api to know if it is the time() function or the created_at that is giving the wrong number. I also don’t know how they handle time zones and if that could be a problem. I am going to keep researching it, hopefully one of you have some more insight.

Viewing 2 replies - 1 through 2 (of 2 total)