当前位置: 首页>>代码示例>>PHP>>正文


PHP SS_Datetime类代码示例

本文整理汇总了PHP中SS_Datetime的典型用法代码示例。如果您正苦于以下问题:PHP SS_Datetime类的具体用法?PHP SS_Datetime怎么用?PHP SS_Datetime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SS_Datetime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getChangeFrequency

 public function getChangeFrequency()
 {
     $date = date('Y-m-d H:i:s');
     $created = new SS_Datetime();
     $created->value = $this->owner->Created ? $this->owner->Created : $date;
     $now = new SS_Datetime();
     $now->value = $date;
     $versions = $this->owner->Version ? $this->owner->Version : 1;
     $timediff = $now->format('U') - $created->format('U');
     // Check how many revisions have been made over the lifetime of the
     // Page for a rough estimate of it's changing frequency.
     $period = $timediff / ($versions + 1);
     if ($period > 60 * 60 * 24 * 365) {
         $freq = GoogleSiteMapGenerator::CHANGE_FREQ_YEARLY;
     } elseif ($period > 60 * 60 * 24 * 30) {
         $freq = GoogleSiteMapGenerator::CHANGE_FREQ_MONTHLY;
     } elseif ($period > 60 * 60 * 24 * 7) {
         $freq = GoogleSiteMapGenerator::CHANGE_FREQ_WEEKLY;
     } elseif ($period > 60 * 60 * 24) {
         $freq = GoogleSiteMapGenerator::CHANGE_FREQ_DAILY;
     } elseif ($period > 60 * 60) {
         $freq = GoogleSiteMapGenerator::CHANGE_FREQ_HOURLY;
     } else {
         $freq = GoogleSiteMapGenerator::CHANGE_FREQ_ALWAYS;
     }
     return $freq;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:27,代码来源:GoogleSiteMapExtension.php

示例2: formatted_dates

 /**
  * Formatted Dates
  * Returns either the event's date or both start and end date if the event spans more than
  * one date
  *
  * Format:
  * Jun 7th - Jun 10th
  *
  * @param SS_Datetime $startObj
  * @param SS_Datetime $endObj
  * @return string
  */
 public static function formatted_dates($startObj, $endObj)
 {
     //Checking if end date is set
     $endDateIsset = true;
     if (isset($endObj->value)) {
         $endDateIsset = false;
     }
     $startTime = strtotime($startObj->value);
     $endTime = strtotime($endObj->value);
     $startMonth = date('M', $startTime);
     $startDayOfMonth = $startObj->DayOfMonth(true);
     $str = $startMonth . ' ' . $startDayOfMonth;
     if (date('Y-m-d', $startTime) == date('Y-m-d', $endTime)) {
         //one date - str. has already been written
     } else {
         //two dates
         if ($endDateIsset) {
             $endMonth = date('M', $endTime);
             $endDayOfMonth = $endObj->DayOfMonth(true);
             if ($startMonth == $endMonth) {
                 $str .= ' - ' . $endDayOfMonth;
             } else {
                 $str .= ' - ' . $endMonth . ' ' . $endDayOfMonth;
             }
         }
     }
     return $str;
 }
开发者ID:andrewandante,项目名称:silverstripe-calendar,代码行数:40,代码来源:EventHelper.php

示例3: tweet_to_array

 /**
  * This method is copied 2015-11-24 from  theplumpss/twitter module (https://github.com/plumpss/twitter/blob/master/code/PlumpTwitterFeed.php)
  * Also some other parts of this module has used theplumpss/twitter as an example, but tweet_to_array() is the
  * only direct copy - although it has some modifications too, regarding to format of the return value.
  * @param $tweet
  * @return mixed
  */
 private static function tweet_to_array($tweet)
 {
     $date = new SS_Datetime();
     $date->setValue(strtotime($tweet->created_at));
     $html = $tweet->text;
     if ($tweet->entities) {
         //url links
         if ($tweet->entities->urls) {
             foreach ($tweet->entities->urls as $url) {
                 $html = str_replace($url->url, '<a href="' . $url->url . '" target="_blank">' . $url->url . '</a>', $html);
             }
         }
         //hashtag links
         if ($tweet->entities->hashtags) {
             foreach ($tweet->entities->hashtags as $hashtag) {
                 $html = str_replace('#' . $hashtag->text, '<a target="_blank" href="https://twitter.com/search?q=%23' . $hashtag->text . '">#' . $hashtag->text . '</a>', $html);
             }
         }
         //user links
         if ($tweet->entities->user_mentions) {
             foreach ($tweet->entities->user_mentions as $mention) {
                 $html = str_replace('@' . $mention->screen_name, '<a target="_blank" href="https://twitter.com/' . $mention->screen_name . '">@' . $mention->screen_name . '</a>', $html);
             }
         }
     }
     $title = new Text();
     $title->setValue($tweet->text);
     return array('LastEdited' => (string) $date, 'Created' => (string) $date, 'Fetched' => SS_Datetime::now(), 'SoMeAuthor' => $tweet->user->screen_name, 'SoMeUsername' => self::config()->username, 'Avatar' => $tweet->user->profile_image_url, 'Content' => $html, 'Title' => preg_replace('/\\.$/', '', $title->Summary(self::config()->title_length)), 'TwitterID' => $tweet->id, 'Locale' => $tweet->lang, 'Source' => 'Twitter');
 }
开发者ID:Taitava,项目名称:silverstripe-socialmedia,代码行数:36,代码来源:SocialMediaTwitter.php

示例4: LastUpdated

 public function LastUpdated()
 {
     $elements = new DataList($this->dataClass);
     $lastUpdated = new SS_Datetime('LastUpdated');
     $lastUpdated->setValue($elements->max('LastEdited'));
     return $lastUpdated;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-registry,代码行数:7,代码来源:RegistryPage.php

示例5: getChangeFrequency

 /**
  * Returns a pages change frequency calculated by pages age and number of 
  * versions. Google expects always, hourly, daily, weekly, monthly, yearly 
  * or never as values.
  * 
  * @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic
  *
  * @return SS_Datetime
  */
 public function getChangeFrequency()
 {
     if ($freq = GoogleSitemap::get_frequency_for_class($this->owner->class)) {
         return $freq;
     }
     $date = date('Y-m-d H:i:s');
     $created = new SS_Datetime();
     $created->value = $this->owner->Created ? $this->owner->Created : $date;
     $now = new SS_Datetime();
     $now->value = $date;
     $versions = $this->owner->Version ? $this->owner->Version : 1;
     $timediff = $now->format('U') - $created->format('U');
     // Check how many revisions have been made over the lifetime of the
     // Page for a rough estimate of it's changing frequency.
     $period = $timediff / ($versions + 1);
     if ($period > 60 * 60 * 24 * 365) {
         $freq = 'yearly';
     } elseif ($period > 60 * 60 * 24 * 30) {
         $freq = 'monthly';
     } elseif ($period > 60 * 60 * 24 * 7) {
         $freq = 'weekly';
     } elseif ($period > 60 * 60 * 24) {
         $freq = 'daily';
     } elseif ($period > 60 * 60) {
         $freq = 'hourly';
     } else {
         $freq = 'always';
     }
     return $freq;
 }
开发者ID:designcity,项目名称:silverstripe-googlesitemaps,代码行数:39,代码来源:GoogleSitemapExtension.php

示例6: generate_data_for_day

 private static function generate_data_for_day(SS_Datetime $date)
 {
     $data = array('timestamp' => time(), 'searchDate' => $date->Format("Y-m-d"), 'collections' => array('events' => array(), 'galleries' => array(), 'locations' => array()));
     $galleryIDs = array();
     $locationIDs = array();
     // Get events
     $where = sprintf("DATE(`StartDate`) = '%s'", $date->Format('Y-m-d'));
     $events = Event::get()->where($where)->exclude(array("GalleryID" => 0, "Gallery.LocationID" => 0));
     foreach ($events as $event) {
         $galleryIDs[] = $event->GalleryID;
         $data['collections']['events'][] = $event->forAPI();
     }
     // Get galleries
     $galleries = Gallery::get()->byIDs(array_unique($galleryIDs));
     foreach ($galleries as $gallery) {
         $locationIDs[] = $gallery->LocationID;
         $data['collections']['galleries'][] = $gallery->forAPI();
     }
     // Get locations
     $locations = Location::get()->byIDs(array_unique($locationIDs));
     foreach ($locations as $location) {
         $data['collections']['locations'][] = $location->forAPI();
     }
     return $data;
 }
开发者ID:ehyland,项目名称:some-painter-cms,代码行数:25,代码来源:EventsDataUtil.php

示例7: parameterFields

 public function parameterFields()
 {
     $fields = new FieldList();
     // Check if any order exist
     if (Order::get()->exists()) {
         $first_order = Order::get()->sort('Created ASC')->first();
         $months = array('All');
         $statuses = Order::config()->statuses;
         array_unshift($statuses, 'All');
         for ($i = 1; $i <= 12; $i++) {
             $months[] = date("F", mktime(0, 0, 0, $i + 1, 0, 0));
         }
         // Get the first order, then count down from current year to that
         $firstyear = new SS_Datetime('FirstDate');
         $firstyear->setValue($first_order->Created);
         $years = array();
         for ($i = date('Y'); $i >= $firstyear->Year(); $i--) {
             $years[$i] = $i;
         }
         //Result Limit
         $result_limit_options = array(0 => 'All', 50 => 50, 100 => 100, 200 => 200, 500 => 500);
         $fields->push(DropdownField::create('Filter_Month', 'Filter by month', $months));
         $fields->push(DropdownField::create('Filter_Year', 'Filter by year', $years));
         $fields->push(DropdownField::create('Filter_Status', 'Filter By Status', $statuses));
         $fields->push(DropdownField::create("ResultsLimit", "Limit results to", $result_limit_options));
     }
     return $fields;
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-orders,代码行数:28,代码来源:OrdersReport.php

示例8: create_tweet

 private static function create_tweet($tweet)
 {
     $date = new SS_Datetime();
     $date->setValue(strtotime($tweet->created_at));
     $html = $tweet->text;
     if ($tweet->entities) {
         //url links
         if ($tweet->entities->urls) {
             foreach ($tweet->entities->urls as $url) {
                 $html = str_replace($url->url, '<a href="' . $url->url . '" target="_blank">' . $url->url . '</a>', $html);
             }
         }
         //hashtag links
         if ($tweet->entities->hashtags) {
             foreach ($tweet->entities->hashtags as $hashtag) {
                 $html = str_replace('#' . $hashtag->text, '<a target="_blank" href="https://twitter.com/search?q=%23' . $hashtag->text . '">#' . $hashtag->text . '</a>', $html);
             }
         }
         //user links
         if ($tweet->entities->user_mentions) {
             foreach ($tweet->entities->user_mentions as $mention) {
                 $html = str_replace('@' . $mention->screen_name, '<a target="_blank" href="https://twitter.com/' . $mention->screen_name . '">@' . $mention->screen_name . '</a>', $html);
             }
         }
     }
     return new ArrayData(array('Date' => $date, 'Username' => $tweet->user->screen_name, 'Avatar' => $tweet->user->profile_image_url, 'Text' => $tweet->text, 'Html' => $html));
 }
开发者ID:helpfulrobot,项目名称:plumpss-twitter,代码行数:27,代码来源:PlumpTwitterFeed.php

示例9: Items

 public function Items()
 {
     $filter = '';
     $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
     if (self::$use_show_in_search) {
         $filter = "{$bt}ShowInSearch{$bt} = 1";
     }
     $this->Pages = Versioned::get_by_stage('SiteTree', 'Live', $filter);
     $newPages = new DataObjectSet();
     if ($this->Pages) {
         foreach ($this->Pages as $page) {
             // Only include pages from this host and pages which are not an instance of ErrorPage
             // We prefix $_SERVER['HTTP_HOST'] with 'http://' so that parse_url to help parse_url identify the host name component; we could use another protocol (like
             // 'ftp://' as the prefix and the code would work the same.
             if (parse_url($page->AbsoluteLink(), PHP_URL_HOST) == parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST) && !$page instanceof ErrorPage) {
                 // If the page has been set to 0 priority, we set a flag so it won't be included
                 if ($page->canView() && (!isset($page->Priority) || $page->Priority > 0)) {
                     // The one field that isn't easy to deal with in the template is
                     // Change frequency, so we set that here.
                     $properties = $page->toMap();
                     $created = new SS_Datetime();
                     $created->value = $properties['Created'];
                     $now = new SS_Datetime();
                     $now->value = date('Y-m-d H:i:s');
                     $versions = $properties['Version'];
                     $timediff = $now->format('U') - $created->format('U');
                     // Check how many revisions have been made over the lifetime of the
                     // Page for a rough estimate of it's changing frequency.
                     $period = $timediff / ($versions + 1);
                     if ($period > 60 * 60 * 24 * 365) {
                         // > 1 year
                         $page->ChangeFreq = 'yearly';
                     } elseif ($period > 60 * 60 * 24 * 30) {
                         // > ~1 month
                         $page->ChangeFreq = 'monthly';
                     } elseif ($period > 60 * 60 * 24 * 7) {
                         // > 1 week
                         $page->ChangeFreq = 'weekly';
                     } elseif ($period > 60 * 60 * 24) {
                         // > 1 day
                         $page->ChangeFreq = 'daily';
                     } elseif ($period > 60 * 60) {
                         // > 1 hour
                         $page->ChangeFreq = 'hourly';
                     } else {
                         // < 1 hour
                         $page->ChangeFreq = 'always';
                     }
                     $newPages->push($page);
                 }
             }
         }
         return $newPages;
     }
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:55,代码来源:GoogleSitemap.php

示例10: Created

 /**
  * @return SS_Datetime
  */
 public function Created()
 {
     $created = $this->tag->getCommit()->getCommitterDate();
     // gitonomy sets the time to UTC, so now we set the timezone to
     // whatever PHP is set to (date.timezone). This will change in the future if each
     // deploynaut user has their own timezone
     $created->setTimezone(new DateTimeZone(date_default_timezone_get()));
     $d = new SS_Datetime();
     $d->setValue($created->format('Y-m-d H:i:s'));
     return $d;
 }
开发者ID:emilhakobian,项目名称:deploynaut,代码行数:14,代码来源:DNTag.php

示例11: testRunTask

 /**
  * Test CronTaskController::runTask
  */
 public function testRunTask()
 {
     $runner = CronTaskController::create();
     $runner->setQuiet(true);
     $task = new CronTaskTest_TestCron();
     // Assuming first run, match the exact time (seconds are ignored)
     $this->assertEquals(0, CronTaskTest_TestCron::$times_run);
     SS_Datetime::set_mock_now('2010-06-20 13:00:10');
     $runner->runTask($task);
     $this->assertEquals(1, CronTaskTest_TestCron::$times_run);
     // Test that re-requsting the task in the same minute do not retrigger another run
     SS_Datetime::set_mock_now('2010-06-20 13:00:40');
     $runner->runTask($task);
     $this->assertEquals(1, CronTaskTest_TestCron::$times_run);
     // Job prior to next hour mark should not run
     SS_Datetime::set_mock_now('2010-06-20 13:40:00');
     $runner->runTask($task);
     $this->assertEquals(1, CronTaskTest_TestCron::$times_run);
     // Jobs just after the next hour mark should run
     SS_Datetime::set_mock_now('2010-06-20 14:10:00');
     $runner->runTask($task);
     $this->assertEquals(2, CronTaskTest_TestCron::$times_run);
     // Jobs run on the exact next expected date should run
     SS_Datetime::set_mock_now('2010-06-20 15:00:00');
     $runner->runTask($task);
     $this->assertEquals(3, CronTaskTest_TestCron::$times_run);
     // Jobs somehow delayed a whole day should be run
     SS_Datetime::set_mock_now('2010-06-21 13:40:00');
     $runner->runTask($task);
     $this->assertEquals(4, CronTaskTest_TestCron::$times_run);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-crontask,代码行数:34,代码来源:CronTaskControllerTest.php

示例12: getFormField

 /**
  * Return the form field
  *
  */
 public function getFormField()
 {
     $defaultValue = $this->DefaultToToday ? SS_Datetime::now()->Format('Y-m-d') : $this->Default;
     $field = EditableDateField_FormField::create($this->Name, $this->EscapedTitle, $defaultValue)->setConfig('showcalendar', true)->setFieldHolderTemplate('UserFormsField_holder')->setTemplate('UserFormsField');
     $this->doUpdateFormField($field);
     return $field;
 }
开发者ID:camfindlay,项目名称:silverstripe-userforms,代码行数:11,代码来源:EditableDateField.php

示例13: LatestTweetsList

 public function LatestTweetsList($limit = '5')
 {
     $conf = SiteConfig::current_site_config();
     if (empty($conf->TwitterName) || empty($conf->TwitterConsumerKey) || empty($conf->TwitterConsumerSecret) || empty($conf->TwitterAccessToken) || empty($conf->TwitterAccessTokenSecret)) {
         return new ArrayList();
     }
     $cache = SS_Cache::factory('LatestTweets_cache');
     if (!($results = unserialize($cache->load(__FUNCTION__)))) {
         $results = new ArrayList();
         require_once dirname(__FILE__) . '/tmhOAuth/tmhOAuth.php';
         require_once dirname(__FILE__) . '/tmhOAuth/tmhUtilities.php';
         $tmhOAuth = new tmhOAuth(array('consumer_key' => $conf->TwitterConsumerKey, 'consumer_secret' => $conf->TwitterConsumerSecret, 'user_token' => $conf->TwitterAccessToken, 'user_secret' => $conf->TwitterAccessTokenSecret, 'curl_ssl_verifypeer' => false));
         $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $conf->TwitterName, 'count' => $limit));
         $tweets = $tmhOAuth->response['response'];
         $json = new JSONDataFormatter();
         if (($arr = $json->convertStringToArray($tweets)) && is_array($arr) && isset($arr[0]['text'])) {
             foreach ($arr as $tweet) {
                 try {
                     $here = new DateTime(SS_Datetime::now()->getValue());
                     $there = new DateTime($tweet['created_at']);
                     $there->setTimezone($here->getTimezone());
                     $date = $there->Format('Y-m-d H:i:s');
                 } catch (Exception $e) {
                     $date = 0;
                 }
                 $results->push(new ArrayData(array('Text' => nl2br(tmhUtilities::entify_with_options($tweet, array('target' => '_blank'))), 'Date' => SS_Datetime::create_field('SS_Datetime', $date))));
             }
         }
         $cache->save(serialize($results), __FUNCTION__);
     }
     return $results;
 }
开发者ID:unisolutions,项目名称:silverstripe-latesttweets,代码行数:32,代码来源:LaTw_Page_Controller_Extension.php

示例14: generatePrintData

 /**
  * Export core
  *
  * Replaces definition in GridFieldPrintButton
  * same as original except sources data from $gridField->getList() instead of $gridField->getManipulatedList()
  *
  * @param GridField
  */
 public function generatePrintData(GridField $gridField)
 {
     $printColumns = $this->getPrintColumnsForGridField($gridField);
     $header = null;
     if ($this->printHasHeader) {
         $header = new ArrayList();
         foreach ($printColumns as $field => $label) {
             $header->push(new ArrayData(array("CellString" => $label)));
         }
     }
     // The is the only variation from the parent class, using getList() instead of getManipulatedList()
     $items = $gridField->getList();
     $itemRows = new ArrayList();
     foreach ($items as $item) {
         $itemRow = new ArrayList();
         foreach ($printColumns as $field => $label) {
             $value = $gridField->getDataFieldValue($item, $field);
             $itemRow->push(new ArrayData(array("CellString" => $value)));
         }
         $itemRows->push(new ArrayData(array("ItemRow" => $itemRow)));
         $item->destroy();
     }
     $ret = new ArrayData(array("Title" => $this->getTitle($gridField), "Header" => $header, "ItemRows" => $itemRows, "Datetime" => SS_Datetime::now(), "Member" => Member::currentUser()));
     return $ret;
 }
开发者ID:mandrew,项目名称:silverstripe-securityreport,代码行数:33,代码来源:GridFieldPrintReportButton.php

示例15: getEventsAction

 public function getEventsAction(SS_HTTPRequest $request)
 {
     // Search date
     $date = DBField::create_field("SS_Datetime", $request->param("SearchDate"));
     if (!$date->getValue()) {
         $date = SS_Datetime::now();
     }
     // Get event data
     $cache = SS_Cache::factory(self::EVENTS_CACHE_NAME);
     $cacheKey = $date->Format('Y_m_d');
     if ($result = $cache->load($cacheKey)) {
         $data = unserialize($result);
     } else {
         $data = EventsDataUtil::get_events_data_for_day($date);
         $cache->save(serialize($data), $cacheKey);
     }
     // Get init data
     if ($request->param("GetAppConfig")) {
         $cache = SS_Cache::factory(self::CONFIG_CACHE_NAME);
         $cacheKey = 'APP_CONFIG';
         if ($result = $cache->load($cacheKey)) {
             $configData = unserialize($result);
         } else {
             $configData = AppConfigDataUtil::get_config_data();
             $cache->save(serialize($configData), $cacheKey);
         }
         $data['appConfig'] = $configData;
     }
     return $this->sendResponse($data);
 }
开发者ID:ehyland,项目名称:some-painter-cms,代码行数:30,代码来源:EventsController.php


注:本文中的SS_Datetime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。