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


PHP TimeHelper::getDaysInMonth方法代码示例

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


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

示例1: testGetDaysInMonth

 public function testGetDaysInMonth()
 {
     $this->assertEqual(TimeHelper::getDaysInMonth(2014, 2), 28);
     $this->assertEqual(TimeHelper::getDaysInMonth(2013, 2), 28);
     $this->assertEqual(TimeHelper::getDaysInMonth(2012, 2), 29);
     $this->assertEqual(TimeHelper::getDaysInMonth(2014, 1), 31);
     $this->assertEqual(TimeHelper::getDaysInMonth(2014, 3), 31);
     $this->assertEqual(TimeHelper::getDaysInMonth(2014, 4), 30);
     $this->assertEqual(TimeHelper::getDaysInMonth(2014, 5), 31);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:10,代码来源:TestOfTimeHelper.php

示例2: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     //Monthly
     $did_monthly = false;
     $should_generate_insight = $this->shouldGenerateMonthlyInsight($slug = 'monthly_best', $instance, $this->insight_date, $regenerate_existing_insight = false, $day_of_month = 1, $count_related_posts = null, $excluded_networks = null, $enable_bonus_alternate_day = false);
     if ($should_generate_insight) {
         $most_popular_post = null;
         $best_popularity_params = array('index' => 0, 'reply' => 0, 'retweet' => 0, 'like' => 0);
         $insight_text = '';
         $post_dao = DAOFactory::getDAO('PostDAO');
         //There's probably a better way to get the number of days in last month
         $last_month_time = strtotime('first day of last month');
         $last_month_year = date('Y', $last_month_time);
         $last_month_month = date('m', $last_month_time);
         $days_of_posts_to_retrieve = TimeHelper::getDaysInMonth($last_month_year, $last_month_month);
         $last_months_posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = $days_of_posts_to_retrieve, $iterator = false, $is_public = false);
         foreach ($last_months_posts as $post) {
             if ($post->network == 'instagram') {
                 $photo_dao = DAOFactory::getDAO('PhotoDAO');
                 $post = $photo_dao->getPhoto($post->post_id, 'instagram');
             }
             $reply_count = $post->reply_count_cache;
             $retweet_count = $post->retweet_count_cache;
             $fav_count = $post->favlike_count_cache;
             $popularity_index = 5 * $reply_count + 3 * $retweet_count + 2 * $fav_count;
             if ($popularity_index > $best_popularity_params['index']) {
                 $best_popularity_params['index'] = $popularity_index;
                 $best_popularity_params['reply'] = $reply_count;
                 $best_popularity_params['retweet'] = $retweet_count;
                 $best_popularity_params['like'] = $fav_count;
                 $most_popular_post = $post;
             }
         }
         if (isset($most_popular_post)) {
             $my_insight = new Insight();
             $my_insight->headline = $this->getVariableCopy(array('%username\'s best of %last_month'), array('last_month' => date('F', $last_month_time)));
             if ($instance->network == 'instagram' && $most_popular_post->is_short_video) {
                 $my_insight->text = $this->getVariableCopy(array("Happy %new_month! %username's most popular Instagram post of %last_month %month_year was a video.", "Welcome to %new_month! This video was %username's most popular Instagram post " . "of %last_month %month_year."), array('last_month' => date('F', $last_month_time), 'month_year' => date('Y', $last_month_time), 'new_month' => date('F')));
             } else {
                 $my_insight->text = $this->getVariableCopy(array("Happy %new_month! This was %username's most popular %post of %last_month %month_year.", "Welcome to %new_month! Take a quick look back at %username's most popular %post " . "of %last_month %month_year."), array('last_month' => date('F', $last_month_time), 'month_year' => date('Y', $last_month_time), 'new_month' => date('F')));
             }
             $my_insight->slug = 'monthly_best';
             //slug to label this insight's content
             $my_insight->instance_id = $instance->id;
             $my_insight->date = $this->insight_date;
             //date is often this or $simplified_post_date
             $my_insight->filename = basename(__FILE__, ".php");
             $my_insight->emphasis = Insight::EMPHASIS_HIGH;
             $my_insight->setPosts(array($most_popular_post));
             $this->insight_dao->insertInsight($my_insight);
             $did_monthly = true;
         }
     }
     //Weekly
     if ($instance->network == 'twitter') {
         $day_of_week = 4;
     } elseif ($instance->network == 'instagram') {
         $day_of_week = 2;
     } else {
         $day_of_week = 0;
     }
     $should_generate_insight = self::shouldGenerateWeeklyInsight('weekly_best', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $day_of_week, count($last_week_of_posts));
     if (!$did_monthly && $should_generate_insight) {
         $most_popular_post = null;
         $best_popularity_params = array('index' => 0, 'reply' => 0, 'retweet' => 0, 'like' => 0);
         $insight_text = '';
         foreach ($last_week_of_posts as $post) {
             if ($post->network == 'instagram') {
                 $photo_dao = DAOFactory::getDAO('PhotoDAO');
                 $post = $photo_dao->getPhoto($post->post_id, 'instagram');
             }
             $reply_count = $post->reply_count_cache;
             $retweet_count = $post->retweet_count_cache;
             $fav_count = $post->favlike_count_cache;
             $popularity_index = 5 * $reply_count + 3 * $retweet_count + 2 * $fav_count;
             if ($popularity_index > $best_popularity_params['index']) {
                 $best_popularity_params['index'] = $popularity_index;
                 $best_popularity_params['reply'] = $reply_count;
                 $best_popularity_params['retweet'] = $retweet_count;
                 $best_popularity_params['like'] = $fav_count;
                 $most_popular_post = $post;
             }
         }
         if (isset($most_popular_post)) {
             if ($instance->network !== 'instagram') {
                 $headlines = array("{$this->username}'s biggest %post last week", "{$this->username}'s most popular %post last week");
             } else {
                 //Instagram: Be video-aware
                 if ($most_popular_post->is_short_video) {
                     $headlines = array("{$this->username}'s biggest post last week was a video", "{$this->username}'s most popular post last week was a video");
                 } else {
                     $headlines = array("{$this->username}'s biggest %post last week", "{$this->username}'s most popular %post last week");
                 }
             }
             $insight_text = $this->username . " earned ";
             foreach ($best_popularity_params as $key => $value) {
                 if ($value && $key != 'index') {
                     $insight_text .= "<strong>" . $value . " " . $this->terms->getNoun($key, $value > 1) . "</strong>, ";
//.........这里部分代码省略.........
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:101,代码来源:weeklybests.php


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