/** * Save subscription to RDMBS * * @param array $data * @return bool */ public function setSubscription(array $data) { if (!isset($data['id'])) { require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; throw new Zend_Feed_Pubsubhubbub_Exception( 'ID must be set before attempting a save' ); } $result = $this->_db->find($data['id']); if (count($result)) { $data['created_time'] = $result->current()->created_time; $now = new Zend_Date; if (isset($data['lease_seconds'])) { $data['expiration_time'] = $now->add($data['lease_seconds'], Zend_Date::SECOND) ->get('yyyy-MM-dd HH:mm:ss'); } $this->_db->update( $data, $this->_db->getAdapter()->quoteInto('id = ?', $data['id']) ); return false; } $this->_db->insert($data); return true; }
/** * Checks the legal age * * @param array $data * @param int $customerAddressId * @return Mage_Checkout_Model_Type_Onepage */ public function saveBilling($data, $customerAddressId) { $result = parent::saveBilling($data, $customerAddressId); if (isset($result['error'])) { return $result; } $dobIso = $this->getQuote()->getCustomerDob(); $dob = new Zend_Date($dobIso, Zend_Date::ISO_8601); $legalBirthDay = $dob->add(self::LIMITED_AGE, Zend_Date::YEAR); $legal1 = Zend_Date::now()->isLater($legalBirthDay); if (!$legal1) { // not even limited legal $result['error'] = 1; $result['message'] = Mage::helper('n98legalage')->__('You are not yet limited contractually capable. You can ask your legal guardian to purchase.'); return $result; } $dob = new Zend_Date($dobIso, Zend_Date::ISO_8601); $legalBirthDay = $dob->add(self::LEGAL_AGE, Zend_Date::YEAR); $legal2 = Zend_Date::now()->isLater($legalBirthDay); if (!$legal2) { $result['error'] = 1; $result['message'] = Mage::helper('n98legalage')->__('You are not yet contractually capable. You can ask your legal guardian to purchase on your behalf.'); return $result; } return $result; }
/** * Enter description here... * */ public function indexAction() { $currentDate = new Zend_Date(); $currentMonth = $currentDate->toString(Zend_Date::MONTH_SHORT); $currentDay = $currentDate->toString(Zend_Date::DAY_SHORT); $month = $this->_getParam('month', $currentMonth); if (false === is_numeric($month)) { $month = $this->_monthMap[urldecode($month)]; } $currentDate->setMonth($month); $currentDate->setDay(1); $days = $currentDate->toString(Zend_Date::MONTH_DAYS); $this->view->selectedMonth = $month; $this->view->currentMonth = $currentMonth; $this->view->currentDay = $currentDay; $result = Bc_UserDTO::fetchAsArray(array('month' => $month)); $month = array(); for ($i = 1; $i <= $days; $i++) { $data = array(); $data['date'] = $currentDate->toString(Zend_Date::DAY . '.' . Zend_Date::MONTH . '.' . Zend_Date::YEAR); $user = array(); foreach ($result as $birthday) { if ($i == $birthday['birthday']) { $user[] = $birthday; } } $data['user'] = empty($user) ? null : $user; $month[$i] = $data; $currentDate->add('24:00:00', Zend_Date::TIMES); } $this->view->month = $month; }
public function generateInvoiceAction() { if ($this->getRequest()->isGet()) { $sessionid = $this->_getParam('id'); $config = new Zend_Config_Ini(APPLICATION_PATH . '/forms/session.ini', 'invoice'); $this->view->form = new Zend_Form($config->session); $this->view->form->sessionid->setValue($sessionid); } else { if ($this->getRequest()->isPost()) { $inv = new Model_Invoice(); $date = new Zend_Date(); $inv->generationdate = $date->get(Zend_Date::W3C); $duedate = $date->add($this->_getParam('daystopay'), Zend_Date::DAY); $inv->duedate = $duedate->get(Zend_Date::W3C); $inv->amount = $this->_getParam('amount'); $inv->save(); $session = Model_Session::findOneById($this->_getParam('id')); $session->invoiceid = $inv->id; $session->save(); $this->_redirect('/admin/'); } else { $this->_redirect('/admin/'); } } }
public static function checkDateConstraint($dateTime, $limit) { $dateStr = $dateTime->format('Y-m-d H:i:s'); $date = new Zend_Date($dateStr, 'yyyy-MM-dd HH:mm:ss'); $now = new Zend_Date(); $date->add($limit, Zend_Date::DAY); return $date->isLater($now); }
/** * manipulate data and output to a string. * * @param $date * @param $offset * @param $measure * @return string */ public function manipulatDate($date, $offset, $measure) { date_default_timezone_set('Europe/Stockholm'); $sql_date_pattern = 'yyyy-MM-dd HH:mm:ss'; $date_obj = new Zend_Date($date, $sql_date_pattern); $date_obj->add($offset, $measure); $current_time = $date_obj->get($sql_date_pattern); return $current_time; }
/** * This uses the zend framwork date add function. * Good for adding a number of days to a date. * * @param string $datestring MySQL formatted Date String Y-m-d. * @param string number of days to be added. * @return string result date formatted as a MySQL Date Y-m-d. */ public function dateAdd($datestring, $numberofdays = 1) { $dateEl = explode("-", $datestring); $datearray = array('year' => date($dateEl[0]), 'month' => date($dateEl[1]), 'day' => date($dateEl[2])); $zenddate = new Zend_Date($datearray); $zenddate->add($numberofdays, Zend_Date::DAY_SHORT); $dateVal = $zenddate->toString('Y-m-d'); return $dateVal; }
/** * @param array $params * * @return SS_List */ public function sourceRecords($params = array()) { Versioned::reading_stage("Stage"); $records = SiteTree::get(); $compatibility = ContentReviewCompatability::start(); if (empty($params["ReviewDateBefore"]) && empty($params["ReviewDateAfter"])) { // If there's no review dates set, default to all pages due for review now $reviewDate = new Zend_Date(SS_Datetime::now()->Format("U")); $reviewDate->add(1, Zend_Date::DAY); $records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString("YYYY-MM-dd"))); } else { // Review date before if (!empty($params['ReviewDateBefore'])) { // TODO Get value from DateField->dataValue() once we have access to form elements here $reviewDate = new Zend_Date($params["ReviewDateBefore"], Config::inst()->get("i18n", "date_format")); $reviewDate->add(1, Zend_Date::DAY); $records = $records->where(sprintf("\"NextReviewDate\" < '%s'", $reviewDate->toString("YYYY-MM-dd"))); } // Review date after if (!empty($params["ReviewDateAfter"])) { // TODO Get value from DateField->dataValue() once we have access to form elements here $reviewDate = new Zend_Date($params["ReviewDateAfter"], Config::inst()->get("i18n", "date_format")); $records = $records->where(sprintf("\"NextReviewDate\" >= '%s'", $reviewDate->toString("YYYY-MM-dd"))); } } // Show virtual pages? if (empty($params["ShowVirtualPages"])) { $virtualPageClasses = ClassInfo::subclassesFor("VirtualPage"); $records = $records->where(sprintf("\"SiteTree\".\"ClassName\" NOT IN ('%s')", implode("','", array_values($virtualPageClasses)))); } // Owner dropdown if (!empty($params["ContentReviewOwner"])) { $ownerNames = Convert::raw2sql($params["ContentReviewOwner"]); $records = $records->filter("OwnerNames:PartialMatch", $ownerNames); } // Only show pages assigned to the current user? // This come last because it transforms $records to an ArrayList. if (!empty($params["OnlyMyPages"])) { $currentUser = Member::currentUser(); $records = $records->filterByCallback(function ($page) use($currentUser) { $options = $page->getOptions(); foreach ($options->ContentReviewOwners() as $owner) { if ($currentUser->ID == $owner->ID) { return true; } } return false; }); } ContentReviewCompatability::done($compatibility); return $records; }
public function weeklystatsAction() { $this->disableLayout(); $this->disableViewAutoRender(); $type = $this->getParam('type'); $end = new Zend_Date(); $end->setTime('23:59:59'); $date = new Zend_Date(); $date->sub(6, Zend_Date::DAY); $date->setTime('00:00:01'); //Build reference array $i = 0; //echo $end->getTimestamp(); echo "<br>"; while ($i <= 6) { $referencearray[$date->get('dd-MM-YYYY')] = 0; $date->add(1, Zend_Date::DAY); $i++; } //Get the results array $start = new Zend_date(); $start->sub(6, Zend_Date::DAY); $start->setTime('00:00:01'); $stat = new \Object\Stats(); $results = $stat->getStatistics($this->selectedLocation->getId(), $start, $end); $startoftheweek = $start->get('dd-MM-YYYY'); //echo $start->getTimestamp(); echo "<br>";exit; foreach ($this->selectedLocation->getServings() as $serving) { //initiate orderarray and seatsarray $orderarray = $referencearray; $seatsarray = $referencearray; foreach ($results as $result) { $datein = date("d-m-Y", $result["date_start"]); if ($serving->getId() == $result['serving_id']) { $servingid = $result['serving_id']; if (array_key_exists($datein, $referencearray)) { $orderarray[$datein] = $result["nbre"]; $seatsarray[$datein] = $result["couverts"]; } } } if ($type == 'seats') { $servingarray[$serving->getTitle()] = $seatsarray; } else { $servingarray[$serving->getTitle()] = $orderarray; } } $reponse = new Reponse(); $reponse->data = $servingarray; $reponse->message = "TXT_STATS_SENT"; $reponse->success = true; $this->render($reponse); }
public function add($date, $part = null, $locale = null) { if ($date instanceof Period) { // now you've got to love that irony // because period actually returns a new date object (the world how it's supposed to be) // we can't do much with the result anyhow // and have to actually set the resulting (new) date as this date // cool, isn't it? $newSelf = $date->addToDate($this); return $this->set($newSelf); } else { return parent::add($date, $part, $locale); } }
/** Display meta data * * @param string $keywords * @uses Pas_View_Helper_CurUrl * @uses Zend_View_Helper_PartialLoop * @uses Zend_View_Helper_HeadMeta * @uses Pas_View_Helper_Title * */ public function meta() { $date = new Zend_Date(); $date->add('72', Zend_Date::HOUR); $this->view->headMeta()->appendHttpEquiv('expires', $date->get(Zend_Date::RFC_1123))->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')->appendHttpEquiv('Content-Language', 'en-GB')->appendHttpEquiv('imagetoolbar', 'no'); $this->view->headMeta($this->view->partialLoop('partials/database/author.phtml', $this->view->peoples), 'dc.creator'); $this->view->headMeta($this->view->CurUrl(), 'dc.identifier'); $this->view->headMeta($this->view->title(), 'dc.title'); $this->view->headMeta($keywords, 'dc.keywords'); $this->view->headMeta('The Portable Antiquities Scheme and the British Museum', 'dc.publisher'); $this->view->headMeta(strip_tags($this->view->partialLoop('partials/database/description.phtml', $this->view->finds)), 'dc.description'); $this->view->headMeta($this->view->partialLoop('partials/database/datecreated.phtml', $this->view->finds), 'dc.date.created'); $this->view->headMeta('Archaeological artefact found in England or Wales', 'dc.subject'); }
function metaBasic() { $date = new Zend_Date(); $date->add('72', Zend_Date::HOUR); $this->view->headMeta()->appendHttpEquiv('expires', $date->get(Zend_Date::RFC_1123))->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')->appendHttpEquiv('Content-Language', 'en-GB')->appendHttpEquiv('imagetoolbar', 'no'); $this->view->headMeta('Daniel Pett', 'DC.Creator'); $this->view->headMeta($this->CurUrl(), 'DC.Identifier'); $this->view->headMeta($this->title(), 'DC.Title'); $this->view->headMeta('basic,search,what,where,when,portable antiquities', 'DC.Keywords'); $this->view->headMeta('The Portable Antiquities Scheme and the British Museum', 'DC.Publisher'); $this->view->headMeta('Search the Portable Antiquities Scheme Database using our basic what where when search interface.', 'DC.Description'); $this->view->headMeta('', 'DC.date.created'); $this->view->headMeta('Archaeology', 'DC.subject'); }
protected function _data() { $model = new Application_Model_Encontro(); $sessao = Zend_Auth::getInstance()->getIdentity(); $where = $model->getAdapter()->quoteInto('id_encontro = ?', $sessao["idEncontro"]); $row = $model->fetchRow($where); $element = $this->createElement('radio', 'data', array('label' => 'Data: ')); $data_ini = new Zend_Date($row->data_inicio); $data_fim = new Zend_Date($row->data_fim); while ($data_ini <= $data_fim) { $element->addMultiOption($data_ini->toString('dd/MM/YYYY'), $data_ini->toString('dd/MM/YYYY')); $data_ini->add(1, Zend_Date::DAY); } $element->setRequired(true)->addErrorMessage("Escolha uma data para realização do evento"); $element->setDecorators(array('ViewHelper', 'Description', 'Errors', array('HtmlTag', ''), array('Label', ''))); return $element; }
/** * Check if data transfer is activated and if enough time has passed since the last request * * @return bool */ public function showTracking() { if (!Mage::getStoreConfig('germanstoreconfig/installation_id')) { return false; } if (Mage::getStoreConfig('admin/germanstoreconfig/datatransfer') == IntegerNet_GermanStoreConfig_Model_Source_Datatransfer::DATATRANSFER_NONE) { return false; } $lastTransferDate = Mage::getStoreConfig('germanstoreconfig/transfer_date'); if (!$lastTransferDate) { return true; } date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone')); $lastTransferDateObject = new Zend_Date(); $lastTransferDateObject->set($lastTransferDate, Zend_Date::ISO_8601); return $lastTransferDateObject->add(self::DAYS_BETWEEN_TRACKING_REQUESTS, Zend_Date::DAY)->isEarlier(new Zend_Date()); }
public function validateAge($value) { $parts = @explode('-', $value); // Error if not filled out if (count($parts) < 3 || count(array_filter($parts)) < 3) { //$this->addError('Please fill in your birthday.'); return false; } $value = mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]); // Error if too low $date = new Zend_Date($value); $date->add((int) $this->min_age, Zend_Date::YEAR); if ($date->compare(new Zend_Date()) > 0) { //$this->addError('You are not old enough.'); return false; } return true; }
/** * Save subscription to RDMBS * * @param array $data * @return bool */ public function setSubscription(array $data) { if (!isset($data['id'])) { require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; throw new Zend_Feed_Pubsubhubbub_Exception('ID must be set before attempting a save'); } $result = $this->find($data['id']); if ($result) { $data['created_time'] = $result->created_time; $now = new Zend_Date(); if ($data['lease_seconds']) { $data['expiration_time'] = $now->add($data['lease_seconds'], Zend_Date::SECOND)->get('yyyy-MM-dd HH:mm:ss'); } $result->merge($data); $result->save(); return false; } $subscription = new Zfplanet_Model_Subscription(); $subscription->merge($data); $subscription->save(); return true; }
/** * @param array $params * * @return SS_List */ public function sourceRecords($params = array()) { Versioned::reading_stage("Stage"); $records = SiteTree::get(); $compatibility = ContentReviewCompatability::start(); if (empty($params["ReviewDateBefore"]) && empty($params["ReviewDateAfter"])) { // If there's no review dates set, default to all pages due for review now $reviewDate = new Zend_Date(SS_Datetime::now()->Format("U")); $reviewDate->add(1, Zend_Date::DAY); $records = $records->where(sprintf('"NextReviewDate" < \'%s\'', $reviewDate->toString("YYYY-MM-dd"))); } else { // Review date before if (!empty($params['ReviewDateBefore'])) { // TODO Get value from DateField->dataValue() once we have access to form elements here $reviewDate = new Zend_Date($params["ReviewDateBefore"], Config::inst()->get("i18n", "date_format")); $reviewDate->add(1, Zend_Date::DAY); $records = $records->where(sprintf("\"NextReviewDate\" < '%s'", $reviewDate->toString("YYYY-MM-dd"))); } // Review date after if (!empty($params["ReviewDateAfter"])) { // TODO Get value from DateField->dataValue() once we have access to form elements here $reviewDate = new Zend_Date($params["ReviewDateAfter"], Config::inst()->get("i18n", "date_format")); $records = $records->where(sprintf("\"NextReviewDate\" >= '%s'", $reviewDate->toString("YYYY-MM-dd"))); } } // Show virtual pages? if (empty($params["ShowVirtualPages"])) { $virtualPageClasses = ClassInfo::subclassesFor("VirtualPage"); $records = $records->where(sprintf("\"SiteTree\".\"ClassName\" NOT IN ('%s')", implode("','", array_values($virtualPageClasses)))); } // Owner dropdown if (!empty($params["ContentReviewOwner"])) { $ownerNames = Convert::raw2sql($params["ContentReviewOwner"]); $records = $records->filter("OwnerNames:PartialMatch", $ownerNames); } $records = new ArrayList($records->sort("NextReviewDate", "DESC")->toArray()); ContentReviewCompatability::done($compatibility); return $records; }
/** * @todo This should be generated by JavaScript, but we don't have the date libraries' */ function Field($properties = array()) { $this->addExtraClass('timedropdownfield'); $html = parent::Field($properties); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript('framework/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript('timedropdownfield/javascript/TimeDropdownField.js'); Requirements::css('timedropdownfield/css/TimeDropdownField.css'); $iteratedTime = new Zend_Date('00:00:00', 'h:mm:ss'); $options = array(); $count = 24 * (60 / $this->config['interval']); for ($i = 0; $i < $count; $i++) { $key = $iteratedTime->toString($this->getConfig('datavalueformat')); $options[$key] = $iteratedTime->toString($this->getConfig('timeformat')); $iteratedTime->add($this->config['interval'], Zend_Date::MINUTE); } $dropdownField = new DropdownField('dropdown_' . $this->getName(), false, $options, $this->Value()); $dropdownField->addExtraClass('presets'); $dropdownField->setHasEmptyDefault(true); $dropdownField->setForm($this->getForm()); $html .= $dropdownField->Field(); $html .= '<a href="#" class="presets-trigger"></a>'; return $html; }
protected function mapDirectiveSalePriceEffectiveDate($params = array()) { /** @var $product Mage_Catalog_Model_Product */ $product = $this->getProduct(); $assocMapArr = $this->getAssocMaps(); $cDate = Mage::app()->getLocale()->date(null, null, Mage::app()->getLocale()->getDefaultLocale()); $timezone = Mage::app()->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE); $cell = ""; if (!$this->hasSpecialPrice($product, $this->getSpecialPrice($product))) { return $cell; } $has_default_qty = $this->_hasDefaultQty($assocMapArr); $display_min = $this->getConfigVar('grouped_price_display_mode', 'columns'); if ($has_default_qty) { if ($display_min == RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_SUM_DEFAULT_QTY) { $product_from_date = $product_to_date = null; $from_time = -1; $to_time = PHP_INT_MAX; foreach ($assocMapArr as $assocMap) { $associatedProduct = $assocMap->getProduct(); if ($associatedProduct->getQty() > 0) { if ($assocMap->hasSpecialPrice($associatedProduct, $assocMap->getSpecialPrice($associatedProduct))) { if ($assocMap->hasPriceByCatalogRules($associatedProduct)) { // Current date to cdate + ttl $fromDate = clone $cDate; $fromDate->setTime('00:00:00', 'HH:mm:ss'); $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY); $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00'); $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59'); } else { $compare_from_date = $associatedProduct->getSpecialFromDate(); $compare_to_date = $associatedProduct->getSpecialToDate(); } if ($from_time < $this->dateToTime($compare_from_date)) { $product_from_date = $compare_from_date; $from_time = $this->dateToTime($product_from_date); } if (!is_empty_date($compare_to_date) && $to_time > $this->dateToTime($compare_to_date)) { $product_to_date = $compare_to_date; $to_time = $this->dateToTime($product_to_date); } } } } } else { // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT $minAssocMap = $this->findMinimalPriceProduct($assocMapArr); if ($minAssocMap === false) { return $cell; } $associatedProduct = $minAssocMap->getProduct(); if ($minAssocMap->hasPriceByCatalogRules($associatedProduct)) { // Current date to cdate + ttl $fromDate = clone $cDate; $fromDate->setTime('00:00:00', 'HH:mm:ss'); $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY); $compare_from_date = $fromDate->toString('yyyy-MM-dd 00:00:00'); $compare_to_date = $toDate->toString('yyyy-MM-dd 23:59:59'); } else { $compare_from_date = $associatedProduct->getSpecialFromDate(); $compare_to_date = $associatedProduct->getSpecialToDate(); } $product_from_date = $compare_from_date; $product_to_date = $compare_to_date; } } else { // RocketWeb_GoogleBaseFeedGenerator_Model_Source_Pricegroupedmode::PRICE_START_AT $minAssocMap = $this->findMinimalPriceProduct($assocMapArr); if ($minAssocMap === false) { return $cell; } $associatedProduct = $minAssocMap->getProduct(); $product_from_date = $associatedProduct->getSpecialFromDate(); $product_to_date = $associatedProduct->getSpecialToDate(); } $fromDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if ($timezone) { $fromDate->setTimezone($timezone); } if ($product_from_date) { $fromDate->setDate(substr($product_from_date, 0, 10), 'yyyy-MM-dd'); $fromDate->setTime(substr($product_from_date, 11, 8), 'HH:mm:ss'); } $toDate = new Zend_Date(null, null, Mage::app()->getLocale()->getDefaultLocale()); if (!is_empty_date($product_to_date)) { if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate(substr($product_to_date, 0, 10), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); } else { if ($timezone) { $toDate->setTimezone($timezone); } $toDate->setDate($cDate->toString('yyyy-MM-dd'), 'yyyy-MM-dd'); $toDate->setTime('23:59:59', 'HH:mm:ss'); $toDate->add((int) $this->getConfigVar('ttl', 'columns'), Zend_Date::DAY); } $cell = $fromDate->toString(Zend_Date::ISO_8601) . "/" . $toDate->toString(Zend_Date::ISO_8601); return $cell; }
/** * @param $dataTime * * @return string */ protected function _getEstimatedDate($dataTime) { $current = new \Zend_Date(); $current->setTime(0); $nextNotificationDate = $current->add($dataTime['shipping'], \Zend_Date::HOUR); return $this->_timezone->formatDate('@' . $nextNotificationDate->getTimestamp()); }
public function chartAction() { // Disable layout and viewrenderer $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $viewer = Engine_Api::_()->user()->getViewer(); // Get params $start = $this->_getParam('start'); $offset = $this->_getParam('offset', 0); $type = $this->_getParam('type', 'all'); $mode = $this->_getParam('mode'); $chunk = $this->_getParam('chunk'); $period = $this->_getParam('period'); $periodCount = $this->_getParam('periodCount', 1); $campaign_ids = $this->_getParam('campaign_ids'); // Validate chunk/period if (!$chunk || !in_array($chunk, $this->_periods)) { $chunk = Zend_Date::DAY; } if (!$period || !in_array($period, $this->_periods)) { $period = Zend_Date::MONTH; } if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) { die('whoops'); return; } // Validate start if ($start && !is_numeric($start)) { $start = strtotime($start); } if (!$start) { $start = time(); } // Fixes issues with month view Zend_Date::setOptions(array('extend_month' => true)); // Get timezone $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'); if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) { $timezone = $viewer->timezone; } // Make start fit to period? $startObject = new Zend_Date($start); $startObject->setTimezone($timezone); $partMaps = $this->_periodMap[$period]; foreach ($partMaps as $partType => $partValue) { $startObject->set($partValue, $partType); } // Do offset if ($offset != 0) { $startObject->add($offset, $period); } $arr_campaigns = array(); if ($campaign_ids) { $arr_campaigns = explode(',', $campaign_ids); } // Get end time $endObject = new Zend_Date($startObject->getTimestamp()); $endObject->setTimezone($timezone); $endObject->add($periodCount, $period); $endObject->sub(1, Zend_Date::SECOND); // Subtract one second $adTbl = Engine_Api::_()->getDbtable('ads', 'ynsocialads'); if (count($arr_campaigns)) { $adList = $adTbl->fetchAll($adTbl->select()->from($adTbl->info("name"), 'ad_id')->where('campaign_id IN (?)', $arr_campaigns)); $adList = $adList->toArray(); } else { $adList = array(); } // Get data $staTable = Engine_Api::_()->getDbtable('statistics', 'ynsocialads'); $staName = $staTable->info('name'); if ($type != "all") { $select = $staTable->select(); // Get data if (count($adList)) { $select->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC'); if ($type != "all") { $select->where('type = ?', $type); } $rawData = $staTable->fetchAll($select); } else { $rawData = array(); } // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $data = array(); $dataLabels = array(); $cumulative = 0; $previous = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative; // Get everything that matches $currentPeriodCount = 0; foreach ($rawData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->timestamp); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCount += 1; } } // Now do stuff with it switch ($mode) { default: case 'normal': $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount; break; case 'cumulative': $cumulative += $currentPeriodCount; $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulative; break; case 'delta': $data[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCount - $previous; $previous = $currentPeriodCount; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Remove some grid lines if there are too many $xsteps = 1; if (count($data) > 100) { $xsteps = ceil(count($data) / 100); } $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject); echo Zend_Json::encode(array('json' => $data, 'title' => $title)); } else { $selectClick = $staTable->select(); // Get data if (count($adList)) { $selectClick->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC'); $selectClick->where("type = 'click'"); $clickData = $staTable->fetchAll($selectClick); } else { $clickData = array(); } $selectImpression = $staTable->select(); // Get data if (count($adList)) { $selectImpression->where('ad_id IN (?)', $adList)->where('timestamp >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('timestamp < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('timestamp ASC'); $selectImpression->where("type = 'impression'"); $impressionData = $staTable->fetchAll($selectImpression); } else { $impressionData = array(); } // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $dataClick = array(); $dataImpression = array(); $dataLabels = array(); $cumulativeClick = 0; $cumulativeIm = 0; $previousClick = 0; $previousIm = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm; // Get everything that matches $currentPeriodCountClick = 0; foreach ($clickData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->timestamp); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCountClick += 1; } } $currentPeriodCountIm = 0; foreach ($impressionData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->timestamp); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCountIm += 1; } } // Now do stuff with it switch ($mode) { default: case 'normal': $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm; break; case 'cumulative': $cumulativeClick += $currentPeriodCountClick; $cumulativeIm += $currentPeriodCountIm; $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $cumulativeIm; break; case 'delta': $dataClick[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountClick - $previousClick; $dataImpression[$this->view->locale()->toDate($currentObjectTimestamp)] = $currentPeriodCountIm - $previousIm; $previousClick = $currentPeriodCountClick; $previousIm = $currentPeriodCountIm; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Remove some grid lines if there are too many $xsteps = 1; if (count($dataClick) > 100) { $xsteps = ceil(count($dataClick) / 100); } $title = $this->view->locale()->toDate($startObject) . ' to ' . $this->view->locale()->toDate($endObject); echo Zend_Json::encode(array('json' => $dataClick, 'title' => $title, 'json2' => $dataImpression)); } return true; }
/** * @param $date * @param $relativeDate * @return float|int|string */ protected function calcDate($date, $relativeDate) { if (strpos($relativeDate, '-') !== false || strpos($relativeDate, '+') !== false) { $modifiers = explode(' ', str_replace(' ', ' ', $relativeDate)); $applyModifiers = array(); foreach ($modifiers as $modifier) { $modifier = trim($modifier); if (preg_match('/^([+-])(\\d+)([dmy])$/', $modifier, $matches)) { if (in_array($matches[1], array('+', '-')) && is_numeric($matches[2]) && in_array($matches[3], array('d', 'm', 'y'))) { $applyModifiers[] = array('sign' => $matches[1], 'number' => $matches[2], 'type' => $matches[3]); } } } if (sizeof($applyModifiers)) { $date = new \Zend_Date(); foreach ($applyModifiers as $modifier) { if ($modifier['sign'] == '-') { $modifier['number'] *= -1; } $typeMap = array('d' => \Zend_Date::DAY, 'm' => \Zend_Date::MONTH, 'y' => \Zend_Date::YEAR); $date->add($modifier['number'], $typeMap[$modifier['type']]); } return $date->getTimestamp(); } } return $date / 1000; }
public function chartDataAction() { // Disable layout and viewrenderer $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); // Get params $type = $this->_getParam('type'); $start = $this->_getParam('start'); $offset = $this->_getParam('offset', 0); $mode = $this->_getParam('mode'); $chunk = $this->_getParam('chunk'); $period = $this->_getParam('period'); $periodCount = $this->_getParam('periodCount', 1); //$end = $this->_getParam('end'); // Validate chunk/period if (!$chunk || !in_array($chunk, $this->_periods)) { $chunk = Zend_Date::DAY; } if (!$period || !in_array($period, $this->_periods)) { $period = Zend_Date::MONTH; } if (array_search($chunk, $this->_periods) >= array_search($period, $this->_periods)) { die('whoops'); return; } // Validate start if ($start && !is_numeric($start)) { $start = strtotime($start); } if (!$start) { $start = time(); } // Fixes issues with month view Zend_Date::setOptions(array('extend_month' => true)); // Get timezone $timezone = Engine_Api::_()->getApi('settings', 'core')->getSetting('core_locale_timezone', 'GMT'); $viewer = Engine_Api::_()->user()->getViewer(); if ($viewer && $viewer->getIdentity() && !empty($viewer->timezone)) { $timezone = $viewer->timezone; } // Make start fit to period? $startObject = new Zend_Date($start); $startObject->setTimezone($timezone); $partMaps = $this->_periodMap[$period]; foreach ($partMaps as $partType => $partValue) { $startObject->set($partValue, $partType); } // Do offset if ($offset != 0) { $startObject->add($offset, $period); } // Get end time $endObject = new Zend_Date($startObject->getTimestamp()); $endObject->setTimezone($timezone); $endObject->add($periodCount, $period); $endObject->sub(1, Zend_Date::SECOND); // Subtract one second // Get data $statsTable = Engine_Api::_()->getDbtable('statistics', 'core'); $statsSelect = $statsTable->select()->where('type = ?', $type)->where('date >= ?', gmdate('Y-m-d H:i:s', $startObject->getTimestamp()))->where('date < ?', gmdate('Y-m-d H:i:s', $endObject->getTimestamp()))->order('date ASC'); $rawData = $statsTable->fetchAll($statsSelect); // Now create data structure $currentObject = clone $startObject; $nextObject = clone $startObject; $data = array(); $dataLabels = array(); $cumulative = 0; $previous = 0; do { $nextObject->add(1, $chunk); $currentObjectTimestamp = $currentObject->getTimestamp(); $nextObjectTimestamp = $nextObject->getTimestamp(); $data[$currentObjectTimestamp] = $cumulative; // Get everything that matches $currentPeriodCount = 0; foreach ($rawData as $rawDatum) { $rawDatumDate = strtotime($rawDatum->date); if ($rawDatumDate >= $currentObjectTimestamp && $rawDatumDate < $nextObjectTimestamp) { $currentPeriodCount += $rawDatum->value; } } // Now do stuff with it switch ($mode) { default: case 'normal': $data[$currentObjectTimestamp] = $currentPeriodCount; break; case 'cumulative': $cumulative += $currentPeriodCount; $data[$currentObjectTimestamp] = $cumulative; break; case 'delta': $data[$currentObjectTimestamp] = $currentPeriodCount - $previous; $previous = $currentPeriodCount; break; } $currentObject->add(1, $chunk); } while ($currentObject->getTimestamp() < $endObject->getTimestamp()); // Reprocess label $labelStrings = array(); $labelDate = new Zend_Date(); foreach ($data as $key => $value) { $labelDate->set($key); $labelStrings[] = $this->view->locale()->toDate($labelDate, array('size' => 'short')); //date('D M d Y', $key); } // Let's expand them by 1.1 just for some nice spacing $minVal = min($data); $maxVal = max($data); $minVal = floor($minVal * ($minVal < 0 ? 1.1 : 1 / 1.1) / 10) * 10; $maxVal = ceil($maxVal * ($maxVal > 0 ? 1.1 : 1 / 1.1) / 10) * 10; // Remove some labels if there are too many $xlabelsteps = 1; if (count($data) > 10) { $xlabelsteps = ceil(count($data) / 10); } // Remove some grid lines if there are too many $xsteps = 1; if (count($data) > 100) { $xsteps = ceil(count($data) / 100); } // Create base chart require_once 'OFC/OFC_Chart.php'; // Make x axis labels $x_axis_labels = new OFC_Elements_Axis_X_Label_Set(); $x_axis_labels->set_steps($xlabelsteps); $x_axis_labels->set_labels($labelStrings); // Make x axis $labels = new OFC_Elements_Axis_X(); $labels->set_labels($x_axis_labels); $labels->set_colour("#416b86"); $labels->set_grid_colour("#dddddd"); $labels->set_steps($xsteps); // Make y axis $yaxis = new OFC_Elements_Axis_Y(); $yaxis->set_range($minVal, $maxVal); $yaxis->set_colour("#416b86"); $yaxis->set_grid_colour("#dddddd"); // Make data $graph = new OFC_Charts_Line(); $graph->set_values(array_values($data)); $graph->set_colour("#5ba1cd"); // Make title $locale = Zend_Registry::get('Locale'); $translate = Zend_Registry::get('Zend_Translate'); $titleStr = $translate->_('_CORE_ADMIN_STATS_' . strtoupper(trim(preg_replace('/[^a-zA-Z0-9]+/', '_', $type), '_'))); $title = new OFC_Elements_Title($titleStr . ': ' . $this->view->locale()->toDateTime($startObject) . ' to ' . $this->view->locale()->toDateTime($endObject)); $title->set_style("{font-size: 14px;font-weight: bold;margin-bottom: 10px; color: #777777;}"); // Make full chart $chart = new OFC_Chart(); $chart->set_bg_colour('#ffffff'); $chart->set_x_axis($labels); $chart->add_y_axis($yaxis); $chart->add_element($graph); $chart->set_title($title); // Send $this->getResponse()->setBody($chart->toPrettyString()); }
/** * Atualiza a situação das guias conforme uma coleção de numpre e numpar informados * * @param array $aGuias * @return array * @throws Exception */ public static function atualizaSituacaoGuias(array $aGuias) { $aResultado = array(); // Agrupa os Numpres e Numpars do Contribuinte foreach ($aGuias as $oGuia) { $sChaveNumpreNumpar = "{$oGuia->getNumpre()}/{$oGuia->getMesComp()}"; $aDadosSituacao[$sChaveNumpreNumpar]['iNumpre'] = $oGuia->getNumpre(); $aDadosSituacao[$sChaveNumpreNumpar]['iNumpar'] = $oGuia->getMesComp(); } if (isset($aDadosSituacao)) { $aSitucao = Contribuinte_Model_GuiaEcidade::pesquisaSituacaoGuias($aDadosSituacao); // Altera a situacao da guia conforme as situacoes encontradas na pesquisa foreach ($aGuias as $oGuia) { $sChaveNumpreNumpar = "{$oGuia->getNumpre()}/{$oGuia->getMesComp()}"; $sSituacao = $aSitucao[$sChaveNumpreNumpar]; if (!isset(self::$WS_NFSE_SITUACAO[$sSituacao])) { throw new Exception("Situação de débito {$sSituacao} não mapeada para o modelo Guia"); } $oGuia->setSituacao(self::$WS_NFSE_SITUACAO[$sSituacao]); $oComparaData = new Zend_Date("01-{$oGuia->getMesComp()}-{$oGuia->getAnoComp()}"); $oComparaData->add(1, 'MM'); // Verifica se a guia de débito foi cancelada no E-cidade remove o vinculo da guia, caso seja NFSE e não // estiver um mês retroativo apenas exibe como "Quitada Manualmente" if ($oComparaData->compare(new Zend_Date(), 'MM/yyyy') == 0 && $oGuia->getTipoDocumentoOrigem() == self::$DOCUMENTO_ORIGEM_NFSE || $oGuia->getTipoDocumentoOrigem() == self::$DOCUMENTO_ORIGEM_DMS) { if (!empty($sSituacao) && $sSituacao == 'CANCELADO') { $aAtributos = array('set' => array('guia' => NULL), 'where' => array('guia' => $oGuia->getEntity())); Contribuinte_Model_DesifContaGuia::update($aAtributos['set'], $aAtributos['where']); Contribuinte_Model_Guia::removeGuiaCancelada($oGuia); } else { $aResultado[] = $oGuia; } } else { $aResultado[] = $oGuia; } } } return $aResultado; }
public function testRespondsToValidConfirmationWithBodyContainingHubChallenge() { $this->_tableGateway->expects($this->any())->method('find')->with($this->equalTo('verifytokenkey'))->will($this->returnValue($this->_rowset)); $rowdata = new stdClass(); $rowdata->id = 'verifytokenkey'; $rowdata->verify_token = hash('sha256', 'cba'); $t = new Zend_Date(); $rowdata->created_time = $t->get(Zend_Date::TIMESTAMP); $rowdata->lease_seconds = 10000; $this->_rowset->expects($this->any())->method('current')->will($this->returnValue($rowdata)); $this->_tableGateway->expects($this->once())->method('update')->with($this->equalTo(array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Zend_Date::TIMESTAMP), 'lease_seconds' => 1234567, 'subscription_state' => 'verified', 'expiration_time' => $t->add(1234567, Zend_Date::SECOND)->get('yyyy-MM-dd HH:mm:ss'))), $this->equalTo('id = \'verifytokenkey\'')); $this->_adapter->expects($this->once())->method('quoteInto')->with($this->equalTo('id = ?'), $this->equalTo('verifytokenkey'))->will($this->returnValue('id = \'verifytokenkey\'')); $this->_callback->handle($this->_get); $this->assertTrue($this->_callback->getHttpResponse()->getBody() == 'abc'); }
public function testRespondsToValidConfirmationWithBodyContainingHubChallenge() { if (getenv('TRAVIS')) { $this->markTestSkipped('Test randomly fail on Travis CI.'); } $this->_tableGateway->expects($this->any())->method('find')->with($this->equalTo('verifytokenkey'))->will($this->returnValue($this->_rowset)); $t = new Zend_Date(); $rowdata = array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Zend_Date::TIMESTAMP), 'lease_seconds' => 10000); $row = new Zend_Db_Table_Row(array('data' => $rowdata)); $this->_rowset->expects($this->any())->method('current')->will($this->returnValue($row)); // require for the count call on the rowset in Model/Subscription $this->_rowset->expects($this->any())->method('count')->will($this->returnValue(1)); $this->_tableGateway->expects($this->once())->method('update')->with($this->equalTo(array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Zend_Date::TIMESTAMP), 'lease_seconds' => 1234567, 'subscription_state' => 'verified', 'expiration_time' => $t->add(1234567, Zend_Date::SECOND)->get('yyyy-MM-dd HH:mm:ss'))), $this->equalTo('id = \'verifytokenkey\'')); $this->_adapter->expects($this->once())->method('quoteInto')->with($this->equalTo('id = ?'), $this->equalTo('verifytokenkey'))->will($this->returnValue('id = \'verifytokenkey\'')); $this->_callback->handle($this->_get); $this->assertTrue($this->_callback->getHttpResponse()->getBody() == 'abc'); }
/** * @ZF-8650 */ public function testFractionalPrecision() { $date = new Zend_Date(); $date->set('012345', Zend_Date::MILLISECOND); $this->assertEquals(3, $date->getFractionalPrecision()); $this->assertEquals('345', $date->toString('S')); $date->setFractionalPrecision(6); $this->assertEquals(6, $date->getFractionalPrecision()); $this->assertEquals('345000', $date->toString('S')); $date->add(200, Zend_Date::MILLISECOND); $this->assertEquals(6, $date->getFractionalPrecision()); $this->assertEquals('345200', $date->toString('S')); }
/** * test looseBehaviour */ public function testLoose() { $date = new Zend_Date(0, 'de'); try { $date->set(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set(10, 'de'); $this->assertEquals($date->getTimestamp(), 10); try { $date->add(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->add(10, 'de'); $this->assertEquals($date->getTimestamp(), 20); try { $date->sub(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->sub(10, 'de'); $this->assertEquals($date->getTimestamp(), 10); try { $date->compare(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->equals(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isEarlier(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isLater(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } }
/** * Return a list of standard protocol/optional parameters for addition to * client's POST body that are specific to the current Hub Server URL * * @param string $hubUrl * @param mode $hubUrl * @return string */ protected function _getRequestParameters($hubUrl, $mode) { if (!in_array($mode, array('subscribe', 'unsubscribe'))) { require_once 'Zend/Feed/Pubsubhubbub/Exception.php'; throw new Zend_Feed_Pubsubhubbub_Exception('Invalid mode specified: "' . $mode . '" which should have been "subscribe" or "unsubscribe"'); } $params = array('hub.mode' => $mode, 'hub.topic' => $this->getTopicUrl()); if ($this->getPreferredVerificationMode() == Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC) { $vmodes = array(Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC, Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC); } else { $vmodes = array(Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_ASYNC, Zend_Feed_Pubsubhubbub::VERIFICATION_MODE_SYNC); } $params['hub.verify'] = array(); foreach ($vmodes as $vmode) { $params['hub.verify'][] = $vmode; } /** * Establish a persistent verify_token and attach key to callback * URL's path/querystring */ $key = $this->_generateSubscriptionKey($params, $hubUrl); $token = $this->_generateVerifyToken(); $params['hub.verify_token'] = $token; // Note: query string only usable with PuSH 0.2 Hubs if (!$this->_usePathParameter) { $params['hub.callback'] = $this->getCallbackUrl() . '?xhub.subscription=' . Zend_Feed_Pubsubhubbub::urlencode($key); } else { $params['hub.callback'] = rtrim($this->getCallbackUrl(), '/') . '/' . Zend_Feed_Pubsubhubbub::urlencode($key); } if ($mode == 'subscribe' && $this->getLeaseSeconds() !== null) { $params['hub.lease_seconds'] = $this->getLeaseSeconds(); } // hub.secret not currently supported $optParams = $this->getParameters(); foreach ($optParams as $name => $value) { $params[$name] = $value; } // store subscription to storage $now = new Zend_Date(); $expires = null; if (isset($params['hub.lease_seconds'])) { $expires = $now->add($params['hub.lease_seconds'], Zend_Date::SECOND)->get('yyyy-MM-dd HH:mm:ss'); } $data = array('id' => $key, 'topic_url' => $params['hub.topic'], 'hub_url' => $hubUrl, 'created_time' => $now->get('yyyy-MM-dd HH:mm:ss'), 'lease_seconds' => $expires, 'verify_token' => hash('sha256', $params['hub.verify_token']), 'secret' => null, 'expiration_time' => $expires, 'subscription_state' => Zend_Feed_Pubsubhubbub::SUBSCRIPTION_NOTVERIFIED); $this->getStorage()->setSubscription($data); return $this->_toByteValueOrderedString($this->_urlEncode($params)); }
/** * Test for add */ public function testAdd() { $locale = new Zend_Locale('de_AT'); $date = new Zend_Date(0, null, $locale); $d2 = new Zend_Date(1010101010, null, $locale); $retour = $date->set(1234567890); $this->assertSame((string) $retour, '1234567890'); $this->assertSame((string) $date->add(10), '1234567900'); $this->assertSame((string) $date->add(-10), '1234567890'); $this->assertSame((string) $date->add(0), '1234567890'); $date->set($d2); $date->add(10, Zend_Date::DAY); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-14T00:36:50+01:00'); $date->add(-10, Zend_Date::DAY); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add('Mon', Zend_Date::WEEKDAY_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::DAY_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-14T00:36:50+01:00'); $date->add(-10, Zend_Date::DAY_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add('Montag', Zend_Date::WEEKDAY); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); $date->add(1, Zend_Date::WEEKDAY_8601); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); try { $date->add($d2, Zend_Date::DAY_SUFFIX); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add(1, Zend_Date::WEEKDAY_DIGIT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-06T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::DAY_OF_YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-14T00:36:50+01:00'); $date->add(-10, Zend_Date::DAY_OF_YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add('M', Zend_Date::WEEKDAY_NARROW); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); $date->add('Mo', Zend_Date::WEEKDAY_NAME); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-05T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::WEEK); $this->assertSame($date->get(Zend_Date::W3C), '2002-03-15T00:36:50+01:00'); $date->add(-10, Zend_Date::WEEK); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add('April', Zend_Date::MONTH); $this->assertSame($date->get(Zend_Date::W3C), '2002-05-04T01:36:50+02:00'); $date->set($d2); $date->add(10, Zend_Date::MONTH_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-11-04T00:36:50+01:00'); $date->add(-10, Zend_Date::MONTH_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-02T00:36:50+01:00'); $date->set($d2); $date->add('Apr', Zend_Date::MONTH_NAME); $this->assertSame($date->get(Zend_Date::W3C), '2002-05-04T01:36:50+02:00'); $date->set($d2); $date->add(10, Zend_Date::MONTH_DIGIT); $this->assertSame($date->get(Zend_Date::W3C), '2002-11-04T00:36:50+01:00'); $date->add(-10, Zend_Date::MONTH_DIGIT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-02T00:36:50+01:00'); $date->set($d2); try { $date->add($d2, Zend_Date::MONTH_DAYS); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add('M', Zend_Date::MONTH_NARROW); $this->assertSame($date->get(Zend_Date::W3C), '2002-04-04T01:36:50+02:00'); $date->set($d2); try { $date->add($d2, Zend_Date::LEAPYEAR); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add(10, Zend_Date::YEAR_8601); $this->assertSame($date->get(Zend_Date::W3C), '2012-01-04T00:36:50+01:00'); $date->add(-10, Zend_Date::YEAR_8601); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2012-01-04T00:36:50+01:00'); $date->add(-10, Zend_Date::YEAR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-03T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::YEAR_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '4012-01-04T00:36:50+01:00'); try { $date->add(-10, Zend_Date::YEAR_SHORT); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add(10, Zend_Date::YEAR_SHORT_8601); $this->assertSame($date->get(Zend_Date::W3C), '4012-01-04T00:36:50+01:00'); try { $date->add(-10, Zend_Date::YEAR_SHORT_8601); $this->fail('exception expected'); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::MERIDIEM); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add(10, Zend_Date::SWATCH); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:51:14+01:00'); $date->add(-10, Zend_Date::SWATCH); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:49+01:00'); $date->set($d2); $date->add(10, Zend_Date::HOUR_SHORT_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->add(-10, Zend_Date::HOUR_SHORT_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::HOUR_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->add(-10, Zend_Date::HOUR_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::HOUR_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->add(-10, Zend_Date::HOUR_AM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::HOUR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:36:50+01:00'); $date->add(-10, Zend_Date::HOUR); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::MINUTE); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:46:50+01:00'); $date->add(-10, Zend_Date::MINUTE); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::MINUTE_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:46:50+01:00'); $date->add(-10, Zend_Date::MINUTE_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::SECOND); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:37:00+01:00'); $date->add(-10, Zend_Date::SECOND); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::SECOND_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:37:00+01:00'); $date->add(-10, Zend_Date::SECOND_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:36:50+01:00'); $date->set($d2); $date->add(10, Zend_Date::MILLISECOND); $this->assertSame($date->get(Zend_Date::MILLISECOND), 10); $date->add(-10, Zend_Date::MILLISECOND); $this->assertSame($date->get(Zend_Date::MILLISECOND), 0); $date->set($d2); try { $date->add('noday', Zend_Date::TIMEZONE_NAME); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::DAYLIGHT); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::GMT_DIFF); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::GMT_DIFF_SEP); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::TIMEZONE); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::TIMEZONE_SECS); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add('1000-01-02 20:05:12', Zend_Date::ISO_8601); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add('Thu, 02 Jan 1000 20:05:12 +0100', Zend_Date::RFC_2822); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add(10, Zend_Date::TIMESTAMP); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:37:00+01:00'); $date->set($d2); try { $date->add('noday', Zend_Date::ERA); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); try { $date->add('noday', Zend_Date::ERA_NAME); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set($d2); $date->add('10.02.0005', Zend_Date::DATES); $this->assertSame($date->get(Zend_Date::W3C), '2007-03-14T00:36:50+01:00'); $date->set($d2); $date->add('Samstag, 10. Februar 0005', Zend_Date::DATE_FULL); $this->assertSame($date->get(Zend_Date::W3C), '2007-03-14T00:36:50+01:00'); $date->set($d2); $date->add('10. Februar 0005', Zend_Date::DATE_LONG); $this->assertSame($date->get(Zend_Date::W3C), '2007-03-14T00:36:50+01:00'); $date->set($d2); $date->add('10.02.0005', Zend_Date::DATE_MEDIUM); $this->assertSame($date->get(Zend_Date::W3C), '2007-03-14T00:36:50+01:00'); $date->set($d2); $date->add('10.02.05', Zend_Date::DATE_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '4007-03-14T00:36:50+01:00'); $date->set($d2); $date->add('10:05:05', Zend_Date::TIMES); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:41:55+01:00'); $date->set($d2); $date->add('10:05 Uhr CET', Zend_Date::TIME_FULL); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:41:50+01:00'); $date->set($d2); $date->add('10:05:05 CET', Zend_Date::TIME_LONG); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:41:55+01:00'); $date->set($d2); $date->add('10:05:05', Zend_Date::TIME_MEDIUM); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:41:55+01:00'); $date->set($d2); $date->add('10:05', Zend_Date::TIME_SHORT); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T10:41:50+01:00'); $date->set($d2); $date->add('1000-01-02T20:05:12+01:00', Zend_Date::ATOM); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Zend_Date::COOKIE); $this->assertSame($date->get(Zend_Date::W3C), '4002-02-06T20:42:02+01:00'); $date->set($d2); $date->add('Sat, 02 Jan 00 20:05:12 +0100', Zend_Date::RFC_822); $this->assertSame($date->get(Zend_Date::W3C), '4002-02-06T20:42:02+01:00'); $date->set($d2); $date->add('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Zend_Date::RFC_850); $this->assertSame($date->get(Zend_Date::W3C), '4002-02-06T20:42:02+01:00'); $date->set($d2); $date->add('Sat, 02 Jan 00 20:05:12 +0100', Zend_Date::RFC_1036); $this->assertSame($date->get(Zend_Date::W3C), '4002-02-06T20:42:02+01:00'); $date->set($d2); $date->add('Sat, 02 Jan 1000 20:05:12 +0100', Zend_Date::RFC_1123); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add('1000-01-02T20:05:12+01:00', Zend_Date::RFC_3339); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add('Sat, 02 Jan 1000 20:05:12 +0100', Zend_Date::RSS); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add('1000-01-02T20:05:12+01:00', Zend_Date::W3C); $this->assertSame($date->get(Zend_Date::W3C), '3002-02-07T20:42:02+01:00'); $date->set($d2); $date->add('1000', 'xx'); $this->assertSame($date->get(Zend_Date::W3C), '2002-01-04T00:53:30+01:00'); }