Order timestamps in MarketPress are in UTC/GMT. Where does this timestamp come from? Is it possible

Order timestamps in MarketPress are in UTC/GMT, but would love to have them reflect the WordPress time - America/New_York. WordPress time and server (HostGator shared hosting) are both set to America/New_York. Tried unsuccessfully to change this by deactivating all plugins, deactivating/activating MarketPress, and switching to WP's Twenty Eleven theme. No luck. Am I missing the obvious? Is this timestamp coming from PayPal settings? Mahalo!

Dev site is up at: http://triangleworkshop.com/qai/e-store/products/

  • BCain

    Aloha, Patrick
    Thanks for the quick assist! So the time stamp comes from PayPal? If so, is it based on the time zone of the seller or the buyer?

    Unfortunately I am not able to change the time zone for my Sandbox accounts - Personal or Business. That Settings menu on PayPal's Sandbox site just thinks and thinks without loading across multiple browsers for all my Sandbox accounts. However, our live PayPal account can be changed as normal, and is set to Pacific Time. However orders still reflect GMT/UTC.

    I read on a non-WPMU Dev board that incorrect time stamps were a Sandbox issue that resolves itself when you switch to live. That said, I hate to go live until I know it is working correctly. Any thoughts or experience with this? Mahalo!

  • BCain

    Okay, found the issue! It appears to be a MarketPress bug, and fixing requires modifying core MarketPress files. If there is a better way to fix this, I welcome the sage advice! For anyone else that has this issue:

    MarketPress creates $timestamp by calling time(), rather than current_time('timestamp'). As per the WordPress Codex:

    "current_time('timestamp') should be used in lieu of time() to return the blog's local time. In WordPress, PHP's time() will always return UTC and is the same as calling current_time('timestamp', true)." (http://codex.wordpress.org/Function_Reference/current_time)

    To fix, I did a quick find and replace in marketpress.php to replace $timestamp = time() with $timestamp = current_time('timestamp') in all 5 places it appeared. This partially resolved the issue. Timestamp now for Received and Paid reflects the time zone set in WP's Settings>General menu.

    This does NOT fix the timestamp when orders are marked Shipped or Closed. I will post fixes for those as soon as I can find them buried in the MarketPress code. Let me know if you find it first!

  • BCain

    Part 2 of the fix! To extend this fix so that order status updates in "Manage Orders" (i.e. Shipped & Closed) also reflects the time zone set in WP's Settings>General menu, make the following change to the marketpress.php file:

    Find these lines:

    //update paid time, can't be adjusted as we don't want to loose gateway info
            if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
              update_post_meta($order->ID, 'mp_paid_time', time());
              do_action( 'mp_order_paid', $order );
            }
            break;
    
          case 'shipped':
            //update paid time if paid step was skipped
            if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
              update_post_meta($order->ID, 'mp_paid_time', time());
              do_action( 'mp_order_paid', $order );
            }
    
            //update shipped time, can be adjusted
            update_post_meta($order->ID, 'mp_shipped_time', time());
            do_action( 'mp_order_shipped', $order );
    
            //send email
    				$this->order_shipped_notification($order->ID);
            break;
    
          case 'closed':
            //update paid time if paid step was skipped
            if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
              update_post_meta($order->ID, 'mp_paid_time', time());
              do_action( 'mp_order_paid', $order );
            }
    
            //update shipped time if shipped step was skipped
            if (!get_post_meta($order->ID, 'mp_shipped_time', true)) {
              update_post_meta($order->ID, 'mp_shipped_time', time());
              do_action( 'mp_order_shipped', $order );
            }
    
            //update closed
            update_post_meta($order->ID, 'mp_closed_time', time());
            do_action( 'mp_order_closed', $order );
            break;

    And change it to:

    //update paid time, can't be adjusted as we don't want to loose gateway info
            if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
              update_post_meta($order->ID, 'mp_paid_time', current_time('timestamp'));
              do_action( 'mp_order_paid', $order );
            }
            break;
    
          case 'shipped':
            //update paid time if paid step was skipped
            if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
              update_post_meta($order->ID, 'mp_paid_time', current_time('timestamp'));
              do_action( 'mp_order_paid', $order );
            }
    
            //update shipped time, can be adjusted
            update_post_meta($order->ID, 'mp_shipped_time', current_time('timestamp'));
            do_action( 'mp_order_shipped', $order );
    
            //send email
    				$this->order_shipped_notification($order->ID);
            break;
    
          case 'closed':
            //update paid time if paid step was skipped
            if (!get_post_meta($order->ID, 'mp_paid_time', true)) {
              update_post_meta($order->ID, 'mp_paid_time', current_time('timestamp'));
              do_action( 'mp_order_paid', $order );
            }
    
            //update shipped time if shipped step was skipped
            if (!get_post_meta($order->ID, 'mp_shipped_time', true)) {
              update_post_meta($order->ID, 'mp_shipped_time', current_time('timestamp'));
              do_action( 'mp_order_shipped', $order );
            }
    
            //update closed
            update_post_meta($order->ID, 'mp_closed_time', current_time('timestamp'));
            do_action( 'mp_order_closed', $order );
            break;

    Combined with the fix mentioned previously, this should get all the main timestamps back in line with WP's timestamp.

    There are a number of other calls for time() throughout the various MarketPress files & plugins, but I'm hesitant to meddle too much under the hood. I would be interested in hearing if an update will be released anytime that solves this issue more permanently. Thankfully the excellent markup makes it easy to pinpoint and patch in the meantime! I just hate to go back to square one with the next awesome update.

  • Aaron

    Thanks for all your work on this. MP wasn't designed with timezone support so this is a feature request. Unfortunately your solution is not ideal, timestamps should be stored in UTC. If we want to display them locally then we should interpret on output instead.

    Otherwise if you change timezones later, or daylight savings etc, it will be a problem. I'll code this up right now for next release. Mean while I suggest you revert your code otherwise timestamps will be polluted.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.