private static function get_reference_date() { $reference_date = new Date(); $life_time = self::get_life_time(); $reference_date->set_day($reference_date->get_day() - $life_time); return $reference_date; }
function __construct() { // Check auto-maintenance settings $aConf = $GLOBALS['_MAX']['CONF']; $this->isAutoMaintenanceEnabled = !empty($aConf['maintenance']['autoMaintenance']); // Get time 1 hour ago $oServiceLocator =& OA_ServiceLocator::instance(); $oNow = $oServiceLocator->get('now'); if ($oNow) { $oOneHourAgo = new Date($oNow); } else { $oOneHourAgo = new Date(); } $oOneHourAgo->subtractSpan(new Date_Span('0-1-0-0')); // Get last runs $oLastCronRun = OX_Maintenance::getLastScheduledRun(); $oLastRun = OX_Maintenance::getLastRun(); // Reset minutes and seconds if (isset($oLastCronRun)) { $oLastCronRun->setMinute(0); $oLastCronRun->setSecond(0); } if (isset($oLastRun)) { $oLastRun->setMinute(0); $oLastRun->setSecond(0); } // Check if any kind of maintenance was run if (isset($oLastCronRun) && !$oOneHourAgo->after($oLastCronRun)) { $this->isScheduledMaintenanceRunning = true; } elseif (isset($oLastRun) && !$oOneHourAgo->after($oLastRun)) { $this->isAutoMaintenanceRunning = true; } }
/** * Gets a list of all the items in the RSS feed given a user-provided URL, limit, and date format * * @return ArrayList */ public function RSSItems() { if (!$this->FeedURL) { return false; } $doc = new DOMDocument(); @$doc->load($this->FeedURL); $items = $doc->getElementsByTagName('item'); $feeds = array(); foreach ($items as $node) { $itemRSS = array('title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue); $feeds[] = $itemRSS; } $output = ArrayList::create(array()); $count = 0; foreach ($feeds as $item) { if ($count >= $this->Count) { break; } // Cast the Date $date = new Date('Date'); $date->setValue($item['date']); // Cast the Title $title = new Text('Title'); $title->setValue($item['title']); $output->push(new ArrayData(array('Title' => $title, 'Date' => $date->Format($this->DateFormat), 'Link' => $item['link']))); $count++; } return $output; }
public function __construct($oStart, $oEnd, $aEntityParams) { $oNow = new Date(); $this->oStart = $oNow->before($oStart) ? $oNow : $oStart; $this->oEnd = $oNow->before($oEnd) ? $oNow : $oEnd; $this->parseEntityParams($aEntityParams); }
function MAX_getDatesByPeriodLimitStart($period, $limit, $start) { $begin = $limit + $start - 1; $end = $start; switch ($period) { case 'daily': $dayBegin = new Date(); $dayBegin->subtractSpan(new Date_Span("{$begin}, 0, 0, 0")); $dayEnd = new Date(); $dayBegin->subtractSpan(new Date_Span("{$end}, 0, 0, 0")); break; case 'weekly': $dayBegin = new Date(Date_Calc::prevDay()); $dayEnd = new Date(Date_Calc::prevDay()); break; case 'monthly': $dayBegin = new Date(); $dayBegin->subtractSpan(new Date_Span('6, 0, 0, 0')); $dayEnd = new Date(); break; case 'allstats': default: $dayBegin = null; $dayEnd = null; } $aDates = array(); $aDates['day_begin'] = is_object($dayBegin) ? $dayBegin->format('%Y-%m-%d') : ''; $aDates['day_end'] = is_object($dayEnd) ? $dayEnd->format('%Y-%m-%d') : ''; return $aDates; }
/** * A method to test the deliveryBlocked() method. */ function testDeliveryBlocked() { OA_setTimeZoneUTC(); $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '1,5,7,20', 'executionorder' => 1); $oLimitationHour = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation); $oDate = new Date('2006-02-07 23:15:45'); for ($i = 0; $i < 24; $i++) { $oDate->addSeconds(SECONDS_PER_HOUR); if ($i == 1 || $i == 5 || $i == 7 || $i == 20) { $this->assertFalse($oLimitationHour->deliveryBlocked($oDate)); } else { $this->assertTrue($oLimitationHour->deliveryBlocked($oDate)); } } // Test timezone $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '1,5,7,20@Europe/Rome', 'executionorder' => 1); $oLimitationHour = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation); $oDate = new Date('2006-02-07 23:15:45'); for ($i = 0; $i < 24; $i++) { $oDate->addSeconds(SECONDS_PER_HOUR); if ($i == 0 || $i == 4 || $i == 6 || $i == 19) { $this->assertFalse($oLimitationHour->deliveryBlocked($oDate)); } else { $this->assertTrue($oLimitationHour->deliveryBlocked($oDate)); } } OA_setTimeZoneLocal(); }
public function build_view() { $now = new Date(); $authorized_categories = NewsService::get_authorized_categories(Category::ROOT_CATEGORY); $news_config = NewsConfig::load(); $condition = 'WHERE id_category IN :authorized_categories ' . (!NewsAuthorizationsService::check_authorizations()->moderation() ? ' AND author_user_id = :user_id' : '') . ' AND (approbation_type = 0 OR (approbation_type = 2 AND (start_date > :timestamp_now OR (end_date != 0 AND end_date < :timestamp_now))))'; $parameters = array('authorized_categories' => $authorized_categories, 'user_id' => AppContext::get_current_user()->get_id(), 'timestamp_now' => $now->get_timestamp()); $page = AppContext::get_request()->get_getint('page', 1); $pagination = $this->get_pagination($condition, $parameters, $page); $result = PersistenceContext::get_querier()->select('SELECT news.*, member.* FROM ' . NewsSetup::$news_table . ' news LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = news.author_user_id ' . $condition . ' ORDER BY top_list_enabled DESC, news.creation_date DESC LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from()))); $number_columns_display_news = $news_config->get_number_columns_display_news(); $this->tpl->put_all(array('C_DISPLAY_BLOCK_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_BLOCK, 'C_DISPLAY_LIST_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_LIST, 'C_DISPLAY_CONDENSED_CONTENT' => $news_config->get_display_condensed_enabled(), 'C_COMMENTS_ENABLED' => $news_config->get_comments_enabled(), 'C_NEWS_NO_AVAILABLE' => $result->get_rows_count() == 0, 'C_PENDING_NEWS' => true, 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display(), 'C_SEVERAL_COLUMNS' => $number_columns_display_news > 1, 'NUMBER_COLUMNS' => $number_columns_display_news)); while ($row = $result->fetch()) { $news = new News(); $news->set_properties($row); $this->tpl->assign_block_vars('news', $news->get_array_tpl_vars()); $this->build_sources_view($news); } $result->dispose(); }
public function startUserSession($row) { $login_key = $_SESSION['login_key']; # Unset all session variable $_SESSION = array(); # Destroy session session_destroy(); # New session name session_name(SESS_NAME); # New session id session_id($login_key); # Start Session session_start(); $ts = new Date(); # Initialize session $_SESSION['start_ts'] = $ts->getTs(); $_SESSION['start_ts_str'] = $ts->getDate(); $_SESSION['auth_state'] = 'user'; $_SESSION['user_id'] = $row['id']; $_SESSION['login_key'] = $login_key; # Destroy old User object $this->user->__destruct(); # Initialize new User object $this->user = User::getInstance($_SESSION['user_id']); }
public function getCMSFields() { $fields = parent::getCMSFields(); $createdDate = new Date(); $createdDate->setValue($this->Created); $reviewer = $this->Member()->Name; $email = $this->Member()->Email; $star = "★"; $emptyStar = "☆"; $fields->insertBefore(LiteralField::create('reviewer', '<p>Written by <strong>' . $this->getMemberDetails() . '</strong><br />' . $createdDate->Format('l F jS Y h:i:s A') . '</p>'), 'Title'); $fields->insertBefore(CheckboxField::create('Approved'), 'Title'); $starRatings = $this->StarRatings(); foreach ($starRatings as $starRating) { $cat = $starRating->StarRatingCategory; $stars = str_repeat($star, $starRating->Rating); $ratingStars = $stars; $maxRating = $starRating->MaxRating - $starRating->Rating; $emptyStarRepeat = str_repeat($emptyStar, $maxRating); $emptyStars = $emptyStarRepeat; /* 4/5 Stars */ $ratingInfo = $ratingStars . $emptyStars . ' (' . $starRating->Rating . ' of ' . $starRating->MaxRating . ' Stars)'; $fields->insertBefore(ReadonlyField::create('rating_' . $cat, $cat, html_entity_decode($ratingInfo, ENT_COMPAT, 'UTF-8')), 'Title'); } $fields->removeByName('StarRatings'); $fields->removeByName('MemberID'); $fields->removeByName('ProductID'); return $fields; }
public function testConvertingDateIntoString() { $ts = mktime(12, 30, 0, 7, 4, 1983); $date = new Date($ts); $date->setFormat('d.m.Y H:i:s'); return $this->assertEqual((string) $date, '04.07.1983 12:30:00'); }
/** * The method to generate a plugin-style report XLS from an already * prepared statistics page OA_Admin_Statistics_Common object. */ function export() { // Prepare the report name // Get system navigation $oMenu = OA_Admin_Menu::singleton(); // Get section by pageId $oCurrentSection = $oMenu->get($this->oStatsController->pageId); if ($oCurrentSection == null) { phpAds_Die($GLOBALS['strErrorOccurred'], 'Menu system error: <strong>' . OA_Permission::getAccountType(true) . '::' . htmlspecialchars($ID) . '</strong> not found for the current user'); } // Get name $reportName = $oCurrentSection->getName(); $this->_name = $reportName; // Prepare the output writer for generation $reportFileName = 'Exported Statistics - ' . $reportName; if (!empty($this->oStatsController->aDates['day_begin'])) { $oStartDate = new Date($this->oStatsController->aDates['day_begin']); $reportFileName .= ' from ' . $oStartDate->format($GLOBALS['date_format']); } if (!empty($this->oStatsController->aDates['day_end'])) { $oEndDate = new Date($this->oStatsController->aDates['day_end']); $reportFileName .= ' to ' . $oEndDate->format($GLOBALS['date_format']); } $reportFileName .= '.xls'; $this->_oReportWriter->openWithFilename($reportFileName); // Get the header and data arrays from the same statistics controllers // that prepare stats for the user interface stats pages list($aHeaders, $aData) = $this->getHeadersAndDataFromStatsController(null, $this->oStatsController); // Add the worksheet $name = ucfirst($this->oStatsController->entity) . ' ' . ucfirst($this->oStatsController->breakdown); $this->createSubReport($reportName, $aHeaders, $aData); // Close the report writer and send the report to the user $this->_oReportWriter->closeAndSend(); }
/** Diff two date objects. Only full units are returned */ public static function diff(TimeInterval $interval, Date $date1, Date $date2) : int { if ($date1->getOffsetInSeconds() != $date2->getOffsetInSeconds()) { // Convert date2 to same timezone as date1. To work around PHP bug #45038, // not just take the timezone of date1, but construct a new one which will // have a timezone ID - which is required for this kind of computation. $tz = new TimeZone(timezone_name_from_abbr('', $date1->getOffsetInSeconds(), $date1->toString('I'))); // Now, convert both dates to the same time (actually we only need to convert the // second one, as the first will remain in the same timezone) $date2 = $tz->translate($date2); } // Then cut off timezone, by setting both to GMT $date1 = DateUtil::setTimeZone($date1, new TimeZone('GMT')); $date2 = DateUtil::setTimeZone($date2, new TimeZone('GMT')); switch ($interval) { case TimeInterval::$YEAR: return -($date1->getYear() - $date2->getYear()); case TimeInterval::$MONTH: return -(($date1->getYear() - $date2->getYear()) * 12 + ($date1->getMonth() - $date2->getMonth())); case TimeInterval::$DAY: return -(intval($date1->getTime() / 86400) - intval($date2->getTime() / 86400)); case TimeInterval::$HOURS: return -(intval($date1->getTime() / 3600) - intval($date2->getTime() / 3600)); case TimeInterval::$MINUTES: return -(intval($date1->getTime() / 60) - intval($date2->getTime() / 60)); case TimeInterval::$SECONDS: return -($date1->getTime() - $date2->getTime()); } }
public function get_search_request($args) { $now = new Date(); $authorized_categories = ArticlesService::get_authorized_categories(Category::ROOT_CATEGORY); $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1; return "SELECT " . $args['id_search'] . " AS id_search,\n\t\t\tarticles.id AS id_content,\n\t\t\tarticles.title AS title,\n\t\t\t(2 * FT_SEARCH_RELEVANCE(articles.title, '" . $args['search'] . "') + (FT_SEARCH_RELEVANCE(articles.contents, '" . $args['search'] . "') +\n\t\t\tFT_SEARCH_RELEVANCE(articles.description, '" . $args['search'] . "')) / 2 ) / 3 * " . $weight . " AS relevance,\n\t\t\tCONCAT('" . PATH_TO_ROOT . "/articles/index.php?url=/', id_category, '-', IF(id_category != 0, cat.rewrited_name, 'root'), '/', articles.id, '-', articles.rewrited_title) AS link\n\t\t\tFROM " . ArticlesSetup::$articles_table . " articles\n\t\t\tLEFT JOIN " . ArticlesSetup::$articles_cats_table . " cat ON cat.id = articles.id_category\n\t\t\tWHERE ( FT_SEARCH(articles.title, '" . $args['search'] . "') OR FT_SEARCH(articles.contents, '" . $args['search'] . "') OR FT_SEARCH_RELEVANCE(articles.description, '" . $args['search'] . "') )\n\t\t\tAND id_category IN(" . implode(", ", $authorized_categories) . ")\n\t\t\tAND (published = 1 OR (published = 2 AND publishing_start_date < '" . $now->get_timestamp() . "' AND (publishing_end_date > '" . $now->get_timestamp() . "' OR publishing_end_date = 0)))\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT 100 OFFSET 0"; }
public function build_view() { $now = new Date(); $authorized_categories = NewsService::get_authorized_categories(Category::ROOT_CATEGORY); $news_config = NewsConfig::load(); $condition = 'WHERE relation.id_keyword = :id_keyword AND id_category IN :authorized_categories AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0)))'; $parameters = array('id_keyword' => $this->get_keyword()->get_id(), 'authorized_categories' => $authorized_categories, 'timestamp_now' => $now->get_timestamp()); $page = AppContext::get_request()->get_getint('page', 1); $pagination = $this->get_pagination($condition, $parameters, $page); $result = PersistenceContext::get_querier()->select('SELECT news.*, member.* FROM ' . NewsSetup::$news_table . ' news LEFT JOIN ' . DB_TABLE_KEYWORDS_RELATIONS . ' relation ON relation.module_id = \'news\' AND relation.id_in_module = news.id LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = news.author_user_id ' . $condition . ' ORDER BY top_list_enabled DESC, news.creation_date DESC LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from()))); $number_columns_display_news = $news_config->get_number_columns_display_news(); $this->tpl->put_all(array('C_DISPLAY_BLOCK_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_BLOCK, 'C_DISPLAY_LIST_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_LIST, 'C_DISPLAY_CONDENSED_CONTENT' => $news_config->get_display_condensed_enabled(), 'C_COMMENTS_ENABLED' => $news_config->get_comments_enabled(), 'C_NEWS_NO_AVAILABLE' => $result->get_rows_count() == 0, 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display(), 'C_SEVERAL_COLUMNS' => $number_columns_display_news > 1, 'NUMBER_COLUMNS' => $number_columns_display_news, 'CATEGORY_NAME' => $this->get_keyword()->get_name())); while ($row = $result->fetch()) { $news = new News(); $news->set_properties($row); $this->tpl->assign_block_vars('news', array_merge($news->get_array_tpl_vars(), array('L_COMMENTS' => CommentsService::get_number_and_lang_comments('news', $row['id']), 'NUMBER_COM' => !empty($row['number_comments']) ? $row['number_comments'] : 0))); $this->build_sources_view($news); } $result->dispose(); }
/** * Find one by hours event * * @param integer $hours * @param Date $date * @return Cursor */ public function findOneByHoursEvent($hours = null, $date = null) { if (!$date) { $currentDatetime = new \DateTime("now"); $hoursDatetime = new \DateTime("now"); $startDay = new \DateTime("now"); $finishDay = new \DateTime("now"); } else { $currentDatetime = new \DateTime($date->format('Y-m-d H:s:i')); $hoursDatetime = new \DateTime($date->format('Y-m-d H:s:i')); $startDay = new \DateTime($date->format('Y-m-d H:s:i')); $finishDay = new \DateTime($date->format('Y-m-d H:s:i')); } $hoursDatetime->add(new \DateInterval('PT' . $hours . 'H')); $startDay->setTime(0, 0, 0); $finishDay->setTime(23, 59, 59); $currentDayEvents = $this->createQueryBuilder()->field('display')->equals(true)->field('date')->gte($startDay)->field('date')->lte($finishDay)->sort('date', 1)->getQuery()->execute(); $duration = 0; foreach ($currentDayEvents as $event) { $eventDate = new \DateTime($event->getDate()->format("Y-m-d H:i:s")); if ($eventDate <= $hoursDatetime && $currentDatetime <= $eventDate->add(new \DateInterval('PT' . $event->getDuration() . 'M'))) { return $event; } } return null; }
private function build_form($user_id) { $form = new HTMLForm('member-view-profile', '', false); $fieldset = new FormFieldsetHTML('profile', $this->lang['profile']); $form->add_fieldset($fieldset); if (AppContext::get_current_user()->check_level(User::ADMIN_LEVEL)) { $link_edit = '<a href="' . UserUrlBuilder::edit_profile($user_id)->rel() . '" title="' . $this->lang['profile.edit'] . '" class="fa fa-edit"></a>'; $fieldset->add_field(new FormFieldFree('profile_edit', $this->lang['profile.edit'], $link_edit)); } $fieldset->add_field(new FormFieldFree('display_name', $this->lang['display_name'], $this->user_infos['display_name'])); $fieldset->add_field(new FormFieldFree('level', $this->lang['level'], '<a class="' . UserService::get_level_class($this->user_infos['level']) . '">' . $this->get_level_lang() . '</a>')); $fieldset->add_field(new FormFieldFree('groups', $this->lang['groups'], $this->build_groups($this->user_infos['groups']))); $registration_date = new Date($this->user_infos['registration_date']); $fieldset->add_field(new FormFieldFree('registered_on', $this->lang['registration_date'], $registration_date ? $registration_date->format(Date::FORMAT_DAY_MONTH_YEAR) : '')); $fieldset->add_field(new FormFieldFree('nbr_msg', $this->lang['number-messages'], $this->user_infos['posted_msg'] . '<br>' . '<a href="' . UserUrlBuilder::messages($user_id)->rel() . '">' . $this->lang['messages'] . '</a>')); $last_connection_date = !empty($this->user_infos['last_connection_date']) ? Date::to_format($this->user_infos['last_connection_date'], Date::FORMAT_DAY_MONTH_YEAR) : LangLoader::get_message('never', 'main'); $fieldset->add_field(new FormFieldFree('last_connect', $this->lang['last_connection'], $last_connection_date)); if (AppContext::get_current_user()->check_auth(UserAccountsConfig::load()->get_auth_read_members(), UserAccountsConfig::AUTH_READ_MEMBERS_BIT) && $this->user_infos['show_email']) { $link_email = '<a href="mailto:' . $this->user_infos['email'] . '" class="basic-button smaller">Mail</a>'; $fieldset->add_field(new FormFieldFree('email', $this->lang['email'], $link_email)); } if (!$this->same_user_view_profile($user_id) && AppContext::get_current_user()->check_level(User::MEMBER_LEVEL)) { $link_mp = '<a href="' . UserUrlBuilder::personnal_message($user_id)->rel() . '" class="basic-button smaller">MP</a>'; $fieldset->add_field(new FormFieldFree('private_message', $this->lang['private_message'], $link_mp)); } MemberExtendedFieldsService::display_profile_fields($form, $user_id); $this->form = $form; }
public function get_search_request($args) { $now = new Date(); $authorized_categories = DownloadService::get_authorized_categories(Category::ROOT_CATEGORY); $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1; return "SELECT " . $args['id_search'] . " AS id_search,\n\t\t\td.id AS id_content,\n\t\t\td.name AS title,\n\t\t\t( 2 * FT_SEARCH_RELEVANCE(d.name, '" . $args['search'] . "') + (FT_SEARCH_RELEVANCE(d.contents, '" . $args['search'] . "') +\n\t\t\tFT_SEARCH_RELEVANCE(d.short_contents, '" . $args['search'] . "')) / 2 ) / 3 * " . $weight . " AS relevance,\n\t\t\tCONCAT('" . PATH_TO_ROOT . "/download/index.php?url=/', id_category, '-', IF(id_category != 0, cat.rewrited_name, 'root'), '/', d.id, '-', d.rewrited_name) AS link\n\t\t\tFROM " . DownloadSetup::$download_table . " d\n\t\t\tLEFT JOIN " . DownloadSetup::$download_cats_table . " cat ON d.id_category = cat.id\n\t\t\tWHERE ( FT_SEARCH(d.name, '" . $args['search'] . "') OR FT_SEARCH(d.contents, '" . $args['search'] . "') OR FT_SEARCH_RELEVANCE(d.short_contents, '" . $args['search'] . "') )\n\t\t\tAND id_category IN (" . implode(", ", $authorized_categories) . ")\n\t\t\tAND (approbation_type = 1 OR (approbation_type = 2 AND start_date < '" . $now->get_timestamp() . "' AND (end_date > '" . $now->get_timestamp() . "' OR end_date = 0)))\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT 100 OFFSET 0"; }
function FeedItems() { $output = new DataObjectSet(); include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/SimplePie.php')); $t1 = microtime(true); $this->feed = new SimplePie($this->AbsoluteRssUrl, TEMP_FOLDER); $this->feed->init(); if($items = $this->feed->get_items(0, $this->NumberToShow)) { foreach($items as $item) { // Cast the Date $date = new Date('Date'); $date->setValue($item->get_date()); // Cast the Title $title = new Text('Title'); $title->setValue($item->get_title()); $output->push(new ArrayData(array( 'Title' => $title, 'Date' => $date, 'Link' => $item->get_link() ))); } return $output; } }
/** * Returns a list of months where blog posts are present. * * @return DataList */ public function getArchive() { $query = $this->Blog()->getBlogPosts()->dataQuery(); if ($this->ArchiveType == 'Yearly') { $query->groupBy('DATE_FORMAT("PublishDate", \'%Y\')'); } else { $query->groupBy('DATE_FORMAT("PublishDate", \'%Y-%M\')'); } $posts = $this->Blog()->getBlogPosts()->setDataQuery($query); if ($this->NumberToDisplay > 0) { $posts = $posts->limit($this->NumberToDisplay); } $archive = new ArrayList(); if ($posts->count() > 0) { foreach ($posts as $post) { /** * @var BlogPost $post */ $date = new Date(); $date->setValue($post->PublishDate); if ($this->ArchiveType == 'Yearly') { $year = $date->FormatI18N("%Y"); $month = null; $title = $year; } else { $year = $date->FormatI18N("%Y"); $month = $date->FormatI18N("%m"); $title = $date->FormatI18N("%B %Y"); } $archive->push(new ArrayData(array('Title' => $title, 'Link' => Controller::join_links($this->Blog()->Link('archive'), $year, $month)))); } } return $archive; }
/** * Overloaded compare method * * The convertTZ calls are time intensive calls. When a compare call is * made in a recussive loop the lag can be significant. */ function compare($d1, $d2, $convertTZ = false) { if (!is_object($d1)) { $d1 = new Date($d1); } if (!is_object($d2)) { $d2 = new Date($d2); } if ($convertTZ) { $d1->convertTZ(new Date_TimeZone('UTC')); $d2->convertTZ(new Date_TimeZone('UTC')); } $days1 = Date_Calc::dateToDays($d1->day, $d1->month, $d1->year); $days2 = Date_Calc::dateToDays($d2->day, $d2->month, $d2->year); $comp_value = 0; if ($days1 - $days2) { $comp_value = $days1 - $days2; } else { if ($d1->hour - $d2->hour) { $comp_value = dPsgn($d1->hour - $d2->hour); } else { if ($d1->minute - $d2->minute) { $comp_value = dPsgn($d1->minute - $d2->minute); } else { if ($d1->second - $d2->second) { $comp_value = dPsgn($d1->second - $d2->second); } } } } return dPsgn($comp_value); }
function register(&$stats_request, $is_new_host = false) { $reg_date = new Date(); $time = $stats_request->getTime(); $reg_date->setByStamp($time); $record = $this->_getCounterRecord($time); $counters_date = new Date(); $counters_date->setByStamp($record['time']); $stats_ip =& $this->getStatsIp(); $is_new_host = $stats_ip->isNewToday($stats_request->getClientIp()); if ($counters_date->dateToDays() < $reg_date->dateToDays()) { $record['hosts_today'] = 0; $record['hits_today'] = 0; $this->_insertNewDayCountersRecord($time); } elseif ($counters_date->dateToDays() > $reg_date->dateToDays()) { //this shouldn't normally happen return; } if ($is_new_host) { $record['hosts_today']++; $record['hosts_all']++; } $record['hits_today']++; $record['hits_all']++; $this->_updateCountersRecord($time, $record['hits_today'], $record['hosts_today'], $record['hits_all'], $record['hosts_all']); $this->_updateDayCountersRecord($time, $record['hits_today'], $record['hosts_today'], $is_new_host, $stats_request); }
public function display_field_profile(MemberExtendedField $member_extended_field) { $fieldset = $member_extended_field->get_fieldset(); if ($member_extended_field->get_value()) { $date = new Date($member_extended_field->get_value()); $fieldset->add_field(new FormFieldFree($member_extended_field->get_field_name(), $member_extended_field->get_name(), $date->format(Date::FORMAT_DAY_MONTH_YEAR))); } }
public function testFilter() { $localeMock = $this->getMock('\\Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface'); $localeMock->expects($this->once())->method('getDateFormat')->with(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT)->will($this->returnValue('MM-dd-yyyy')); $model = new Date($localeMock); // Check that date is converted to 'yyyy-MM-dd' format $this->assertEquals('2241-12-31', $model->filter('12-31-2241')); }
public static function compare(Date $left, Date $right) { if ($left->toStamp() == $right->toStamp()) { return 0; } else { return $left->toStamp() > $right->toStamp() ? 1 : -1; } }
/** * Compares this time to the one passed in * Returns: * -1 if this time is less than the passed in time * 0 if the times are equal * 1 if this time is greater than the passed in time * @param Time $time * @param Date|null $comparisonDate date to be used for time comparison * @return int comparison result */ public function Compare(Time $time, $comparisonDate = null) { if ($comparisonDate != null) { $myDate = Date::Create($comparisonDate->Year(), $comparisonDate->Month(), $comparisonDate->Day(), $this->Hour(), $this->Minute(), $this->Second(), $this->Timezone()); $otherDate = Date::Create($comparisonDate->Year(), $comparisonDate->Month(), $comparisonDate->Day(), $time->Hour(), $time->Minute(), $time->Second(), $time->Timezone()); return $myDate->Compare($otherDate); } return $this->GetDate()->Compare($time->GetDate()); }
public static function header_cache_enable($minutes) { $seconds = $minutes * 60; $last_modified = new Date(2000, 1, 1); @header("Pragma: public"); @header("Cache-Control: max-age={$seconds}, public"); @header("User-Cache-Control: max-age={$seconds}"); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $last_modified->get_unix_time()) . ' GMT'); }
public function __construct(Date $beginDate, Date $endDate) { if ($endDate->isBefore($beginDate)) { throw new \Exception('DateInterval: the begin date must be before the end date.'); } $this->begin = $beginDate; $this->end = $endDate; $this->current = $this->begin; }
function sendSqlDump() { $result = BADGER_VERSION_TAG . "\n"; $result .= getDbDump(); $now = new Date(); header('Content-Type: text/sql'); header('Content-Disposition: attachment; filename="BADGER-' . getBadgerDbVersion() . '-DatabaseBackup-' . $now->getDate() . '.sql"'); header('Content-Length: ' . strlen($result)); echo $result; }
/** * @group shopobjects */ function testRejectCreateDateNoString() { // GIVEN $invalidTimestamp = null; // WHEN $date = new Date($invalidTimestamp); // THEN $this->assertTrue($date->error()); $this->assertEquals($date->errorNumber(), "D-1"); }
function firendlyTime($time) { if (empty($time)) { return ''; } import('@.ORG.Date'); //日期时间操作类目录与1.5不一样 $date = new Date(intval($time)); return $date->timeDiff(time(), 2); }