本文整理汇总了PHP中Timestamp::setMonth方法的典型用法代码示例。如果您正苦于以下问题:PHP Timestamp::setMonth方法的具体用法?PHP Timestamp::setMonth怎么用?PHP Timestamp::setMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timestamp
的用法示例。
在下文中一共展示了Timestamp::setMonth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Articles
/**
* calculates the array to display with the months
*
* @private
*/
function _getMonths()
{
$articles = new Articles();
$archiveStats = $articles->getNumberPostsPerMonthAdmin($this->_blogInfo->getId());
if (!$archiveStats) {
return array();
}
$result = array();
$t = new Timestamp();
$curyear = (int) $t->getYear();
$curmonth = (int) $t->getMonth();
$archiveDateFormat = $this->_locale->tr("archive_date_format");
if ($archiveDateFormat == "archive_date_format") {
$archiveDateFormat = "%B %Y";
}
foreach ($archiveStats as $yearName => $year) {
foreach ($year as $monthName => $month) {
// the next bit is so disgustingly ugly that I am ashamed of it...
// what I'm trying to do here is that the getNumberPostsPerMonthAdmin() method
// won't return the current month if there wasn't anything posted during it but
// we still should show the current month even if there's nothing in it, because otherwise
// when generating page where the posts are listed, it will end up saying "Date: All"
// but no posts at all shown (it didn't have anything to show) This is a way of
// "introducing" a month in the array without fucking it up. In fact, PHP *was*
// indeed fucking it up... it didn't just want to keep the order! Oh well, it's a very
// long and stupid story but we need this hack, ok? :)
if ($archiveStats[$curyear][$curmonth] == "" && !$alreadyAdded) {
// there goes the dirty hack :P
if ($yearName == $curyear && $monthName < $curmonth) {
$t = new Timestamp();
$name = $this->_locale->formatDate($t, $archiveDateFormat);
$monthStr = array("name" => $name, "date" => $this->_locale->formatDate($t, "%Y%m"));
array_push($result, $monthStr);
$alreadyAdded = true;
}
}
// we can use the Timestamp class to help us with this...
$t = new Timestamp("");
$t->setYear($yearName);
$t->setMonth($monthName);
$name = $this->_locale->formatDate($t, $archiveDateFormat);
$monthStr = array("name" => $name, "date" => $this->_locale->formatDate($t, "%Y%m"));
array_push($result, $monthStr);
}
}
return $result;
}
示例2: array
/**
* Fetches the stats for the archives
*
* @private
*/
function _getArchives()
{
$archiveStats = $this->articles->getNumberPostsPerMonth($this->_blogInfo->getId());
if ($archiveStats == '') {
return false;
}
$links = array();
$locale = $this->_blogInfo->getLocale();
$urls = $this->_blogInfo->getBlogRequestGenerator();
// format of dates used in the archive, but it defaults to '%B %Y' if none specified
$archiveDateFormat = $locale->tr('archive_date_format');
// need to check whether we got the same thing back, since that's the way Locale::tr() works instead of
// returning an empty string
if ($archiveDateFormat == "archive_date_format") {
$archiveDateFormat = ARCHIVE_DEFAULT_DATE_FORMAT;
}
foreach ($archiveStats as $yearName => $year) {
foreach ($year as $monthName => $month) {
// we can use the Timestamp class to help us with this...
$t = new Timestamp();
$t->setYear($yearName);
$t->setMonth($monthName);
$archiveUrl = $urls->getArchiveLink($t->getYear() . $t->getMonth());
$linkName = $locale->formatDate($t, $archiveDateFormat);
$link = new ArchiveLink($linkName, '', $archiveUrl, $this->_blogInfo->getId(), 0, $month, 0);
$links[] = $link;
}
}
return $links;
}