We have a process that generates shipments every 4 hours. Only the items that are shipped should be invoiced, so invoice creation is part of this process. 

This process runs in an external PHP script that loads the Magento environment and then processes the pending orders.

When the invoices are created, the create at time is off by 4 hours, so that looks like it's not using the store time. I've reviewed the Magento code and searched the web, but, I don't see any indication that you should do something to set the correct store time when creating an invoice. 

At the top of the script the timezone to the store's timezone -

```
date_default_timezone_set('America/Boston');

```

The magento environment based on the order's store id -

```
//Start environment emulation of the specified store
$storeId = $order->getStoreId();
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

```

Later, for order that shipment, an invoice is created -

```
// create an invoice for the invoiceable items
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice($toInvoice);

if (!$invoice->getTotalQty()) {
    Mage::throwException(Mage::helper('core')->__('Invoice generation failed - no items to invoice.'));
}

$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->register();

$transactionSave = Mage::getModel('core/resource_transaction')
    ->addObject($invoice)
    ->addObject($invoice->getOrder());
$transactionSave->save();

$invoiceID = $invoice->getIncrementId();

```

Any suggestions what should be done differently?

Thanks!