Here you can see some examples how to set the dates by API to be displayed in the desired timezone.
First, you need to know your local timezone since it is needed for getting the time offset between your timezone and server's timezone. Here is an example how to get the time offset and set it as a constant 'TIME_OFFSET'. The time offset is in seconds (in the example as a local timezone the Europe/Bratislava timezone is used):
<?php define('LOCAL_TIMEZONE', 'Europe/Bratislava'); define('TIME_OFFSET', getTimeOffset()); function getTimeOffset() { $dateTimeServer = date_create("now", timezone_open('America/Los_Angeles')); $dateTimeClient = date_create("now", timezone_open(LOCAL_TIMEZONE)); return $dateTimeClient->getOffset() - $dateTimeServer->getOffset(); } ?>
<?php function getClientTime($clientTimeStamp) { return $clientTimeStamp + TIME_OFFSET; } function getServerTime($serverTimeStamp) { return $serverTimeStamp - TIME_OFFSET; } ?>
<?php function getDateTime($timestamp) { return date('Y-m-d H:i:s', $timestamp); } ?>
<?php function dateTimeToClientTime($dateTime) { return getDateTime(getClientTime((strtotime($dateTime)))); } function dateTimeToServerTime($dateTime) { return getDateTime(getServerTime((strtotime($dateTime)))); } ?>
<?php include 'PapApi.class.php'; //the PapApi.class.php can be found at the PAP installation folder, in the 'api' directory define('LOCAL_TIMEZONE', 'Europe/Bratislava'); define('TIME_OFFSET', getTimeOffset()); function getTimeOffset() { $dateTimeServer = date_create("now", timezone_open('America/Los_Angeles')); $dateTimeClient = date_create("now", timezone_open(LOCAL_TIMEZONE)); return $dateTimeClient->getOffset() - $dateTimeServer->getOffset(); } function getClientTime($clientTimeStamp) { return $clientTimeStamp + TIME_OFFSET; } function getServerTime($serverTimeStamp) { return $serverTimeStamp - TIME_OFFSET; } function getDateTime($timestamp) { return date('Y-m-d H:i:s', $timestamp); } function dateTimeToClientTime($dateTime) { return getDateTime(getClientTime((strtotime($dateTime)))); } function dateTimeToServerTime($dateTime) { return getDateTime(getServerTime((strtotime($dateTime)))); } $session = new Pap_Api_Session("https://www.yoursite.com/pap4/scripts/server.php"); if(!$session->login("merchant@username.com","merchant_password")) { die("Cannot login. Message: ". $session->getMessage()); } $request = new Pap_Api_TransactionsGrid($session); // set filter, this is same as if you set in merchant panel filter from 2011-04-11 to 2011-04-19 (value toDate is automatically converted to end of this day )$request->addFilter('dateinserted', 'D>=', dateTimeToServerTime('2011-04-11')); $request->addFilter('dateinserted', 'D<=', dateTimeToServerTime('2011-04-19 23:59:59')); $request->setLimit(0, 30); $request->setSorting('orderid', false); $request->sendNow(); $grid = $request->getGrid(); $recordset = $grid->getRecordset(); echo "Total number of records: ".$grid->getTotalCount()."<br>"; echo "Number of returned records: ".$recordset->getSize()."<br>"; // iterate through the records foreach($recordset as $rec) { echo 'Transaction OrderID: '.$rec->get('orderid').', Commission: '.$rec->get('commission').', Date inserted(server time: '.$rec->get('dateinserted'). '): '.dateTimeToClientTime($rec->get('dateinserted')).'<br>'; } ?>