Does anyone know if there is some sort of site which is collecting useful view helpers to use? Might be a good idea. In any case, here is a view helper I use to convert a UNIX timestamp stored as UTC to a user-defined timezone and locale:

class My_View_Helper_FormatDate extends Zend_View_Helper_Abstract
{
  /**
   * Format a timestamp in the user's locale and timezone
   *
   * @param  integer $timestamp
   * @param  string  $format
   * @return string
   */
  public function formatDate($timestamp, $format=Zend_Date::DATE_SHORT)
  {
    if (Zend_Registry::isRegistered('locale')) { // "en_US"
      $locale = Zend_Registry::get('locale');
    }
    else {
      $locale = null;
    }

    $date = new Zend_Date($timestamp, Zend_Date::TIMESTAMP, $locale);
    if (Zend_Registry::isRegistered('timezome')) { // "America/New_York"
      $date->setTimezone(Zend_Registry::get('timezone'));
    }

    return $date->get($format, $locale);
  }
}

Then, as long as 'locale' and 'timezone' variables are set in Zend_Registry, in my view I can do:

<?php echo $this->formatDate($timestamp); ?>

-Justin

Reply via email to