本文整理汇总了PHP中Contao\Date类的典型用法代码示例。如果您正苦于以下问题:PHP Date类的具体用法?PHP Date怎么用?PHP Date使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$arrJumpTo = array();
$arrNewsletter = array();
$strRequest = ampersand(\Environment::get('request'), true);
$objNewsletter = \NewsletterModel::findSentByPids($this->nl_channels);
if ($objNewsletter !== null) {
while ($objNewsletter->next()) {
/** @var NewsletterChannelModel $objTarget */
if (!($objTarget = $objNewsletter->getRelated('pid')) instanceof NewsletterChannelModel) {
continue;
}
$jumpTo = intval($objTarget->jumpTo);
// A jumpTo page is not mandatory for newsletter channels (see #6521) but required for the list module
if ($jumpTo < 1) {
throw new \Exception("Newsletter channels without redirect page cannot be used in a newsletter list");
}
$strUrl = $strRequest;
if (!isset($arrJumpTo[$objTarget->jumpTo])) {
if (($objJumpTo = $objTarget->getRelated('jumpTo')) instanceof PageModel) {
/** @var PageModel $objJumpTo */
$arrJumpTo[$objTarget->jumpTo] = $objJumpTo->getFrontendUrl(\Config::get('useAutoItem') ? '/%s' : '/items/%s');
} else {
$arrJumpTo[$objTarget->jumpTo] = $strUrl;
}
}
$strUrl = $arrJumpTo[$objTarget->jumpTo];
$strAlias = $objNewsletter->alias ?: $objNewsletter->id;
$arrNewsletter[] = array('subject' => $objNewsletter->subject, 'title' => \StringUtil::stripInsertTags($objNewsletter->subject), 'href' => sprintf($strUrl, $strAlias), 'date' => \Date::parse($objPage->dateFormat, $objNewsletter->date), 'datim' => \Date::parse($objPage->datimFormat, $objNewsletter->date), 'time' => \Date::parse($objPage->timeFormat, $objNewsletter->date), 'channel' => $objNewsletter->pid);
}
}
$this->Template->newsletters = $arrNewsletter;
}
示例2: determineDateFormat
/**
* Obtain the correct date/time string.
*
* @return string
*/
private function determineDateFormat()
{
if ($format = trim($this->get('dateformat'))) {
return $format;
}
return Date::getFormatFromRgxp($this->get('timetype'));
}
示例3: compile
/**
* Generate the module
*/
protected function compile()
{
// Create the date object
try {
if (\Input::get('month')) {
$this->Date = new \Date(\Input::get('month'), 'Ym');
} elseif (\Input::get('day')) {
$this->Date = new \Date(\Input::get('day'), 'Ymd');
} else {
$this->Date = new \Date();
}
} catch (\OutOfBoundsException $e) {
throw new PageNotFoundException('Page not found');
}
$time = \Date::floorToMinute();
// Find the boundaries
$objMinMax = $this->Database->query("SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN(" . implode(',', array_map('intval', $this->cal_calendar)) . ")" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'" : ""));
/** @var FrontendTemplate|object $objTemplate */
$objTemplate = new \FrontendTemplate($this->cal_ctemplate);
// Store year and month
$intYear = date('Y', $this->Date->tstamp);
$intMonth = date('m', $this->Date->tstamp);
$objTemplate->intYear = $intYear;
$objTemplate->intMonth = $intMonth;
// Previous month
$prevMonth = $intMonth == 1 ? 12 : $intMonth - 1;
$prevYear = $intMonth == 1 ? $intYear - 1 : $intYear;
$lblPrevious = $GLOBALS['TL_LANG']['MONTHS'][$prevMonth - 1] . ' ' . $prevYear;
$intPrevYm = intval($prevYear . str_pad($prevMonth, 2, 0, STR_PAD_LEFT));
// Only generate a link if there are events (see #4160)
if ($objMinMax->dateFrom !== null && $intPrevYm >= date('Ym', $objMinMax->dateFrom)) {
$objTemplate->prevHref = $this->strUrl . '?month=' . $intPrevYm;
$objTemplate->prevTitle = specialchars($lblPrevious);
$objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
$objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
}
// Current month
$objTemplate->current = $GLOBALS['TL_LANG']['MONTHS'][date('m', $this->Date->tstamp) - 1] . ' ' . date('Y', $this->Date->tstamp);
// Next month
$nextMonth = $intMonth == 12 ? 1 : $intMonth + 1;
$nextYear = $intMonth == 12 ? $intYear + 1 : $intYear;
$lblNext = $GLOBALS['TL_LANG']['MONTHS'][$nextMonth - 1] . ' ' . $nextYear;
$intNextYm = $nextYear . str_pad($nextMonth, 2, 0, STR_PAD_LEFT);
// Only generate a link if there are events (see #4160)
if ($objMinMax->dateTo !== null && $intNextYm <= date('Ym', max($objMinMax->dateTo, $objMinMax->repeatUntil))) {
$objTemplate->nextHref = $this->strUrl . '?month=' . $intNextYm;
$objTemplate->nextTitle = specialchars($lblNext);
$objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
$objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
}
// Set the week start day
if (!$this->cal_startDay) {
$this->cal_startDay = 0;
}
$objTemplate->days = $this->compileDays();
$objTemplate->weeks = $this->compileWeeks();
$objTemplate->substr = $GLOBALS['TL_LANG']['MSC']['dayShortLength'];
$this->Template->calendar = $objTemplate->parse();
}
示例4: formatOptions
/**
* @inheritdoc
*
* @param CalendarEventsModel $current
* @param CalendarEventsModel[] $models
*/
protected function formatOptions(Model $current, Model\Collection $models)
{
$options = [];
foreach ($models as $model) {
$options[$model->id] = sprintf('%s [%s]', $model->title, Date::parse($GLOBALS['TL_CONFIG']['datimFormat'], $model->startTime));
}
return $options;
}
示例5: addTypeIcon
public function addTypeIcon($row, $label, DataContainer $dc, $args = null)
{
$args[0] = \Image::getHtml(\Image::get('system/modules/mail_to/assets/mail-open-image.png', 16, 16));
$objFile = FilesModel::findByUuid($row['folder']);
$args[2] = $objFile !== null ? $objFile->path : '-';
$args[5] = Date::parse(Date::getFormatFromRgxp('datim'), $row['lastrun']);
return $args;
}
示例6: scopeActive
public function scopeActive(Builder $query)
{
$time = Date::floorToMinute();
return $query->where('disable', '')->where(function (Builder $query) use($time) {
return $query->where('start', '')->orWhere('start', '<=', $time);
})->where(function (Builder $query) use($time) {
return $query->where('stop', '')->orWhere('stop', '>', $time + 60);
});
}
示例7: formatOptions
/**
* @inheritdoc
*
* @param NewsModel $current
* @param NewsModel[] $models
*/
protected function formatOptions(Model $current, Model\Collection $models)
{
$sameDay = $GLOBALS['TL_LANG']['tl_product']['sameDay'];
$otherDay = $GLOBALS['TL_LANG']['tl_product']['otherDay'];
$dayBegin = strtotime('0:00', $current->date);
$options = [$sameDay => [], $otherDay => []];
foreach ($models as $model) {
$group = strtotime('0:00', $model->date) === $dayBegin ? $sameDay : $otherDay;
$options[$group][$model->id] = sprintf('%s (%s) [%s]', $model->title, $model->code, Date::parse($GLOBALS['TL_CONFIG']['dateFormat'], $model->date));
}
return $options;
}
示例8: scopePublished
public function scopePublished(Builder $query, $ignoreFePreview = false)
{
// mimic behavior of contao models who never apply the pusblished filter when Backenduser is logged in
if ($ignoreFePreview || BE_USER_LOGGED_IN) {
return $query;
}
$time = Date::floorToMinute();
return $query->where('published', 1)->where(function (Builder $query) use($time) {
return $query->where('start', '')->orWhere('start', '<=', $time);
})->where(function (Builder $query) use($time) {
return $query->where('stop', '')->orWhere('stop', '>', $time + 60);
});
}
示例9: run
/**
* Run the test
*
* @param array $data
* @param string $table
*
* @throws ErrorException
* @throws WarningException
*/
public function run(array $data, $table)
{
switch ($table) {
case 'tl_calendar_events':
case 'tl_news':
$this->check($data['teaser']);
break;
case 'tl_page':
$time = Date::floorToMinute();
if ($data['type'] === 'regular' && $data['robots'] !== 'noindex,nofollow' && $data['published'] && (!$data['start'] || $data['start'] <= $time) && (!$data['stop'] || $data['stop'] > $time)) {
$this->check($data['description']);
}
break;
}
}
示例10: processCustomDateRegexp
/**
* Process a custom date regexp on a widget.
*
* @param string $rgxp The rgxp being evaluated.
*
* @param string $value The value to check.
*
* @param Widget $widget The widget to process.
*
* @return void
*
* @SuppressWarnings(PHPMD.Superglobals)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
public static function processCustomDateRegexp($rgxp, $value, $widget)
{
if ('MetaModelsFilterRangeDateRgXp' !== $rgxp) {
return;
}
$format = $widget->dateformat;
if (!preg_match('~^' . Date::getRegexp($format) . '$~i', $value)) {
$widget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['date'], Date::getInputFormat($format)));
} else {
// Validate the date (see https://github.com/contao/core/issues/5086)
try {
new Date($value, $format);
} catch (\OutOfBoundsException $e) {
$widget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $value));
}
}
}
示例11: getSeparatedNumericDateTimeInterval
public static function getSeparatedNumericDateTimeInterval($intStartDate = null, $intEndDate = null, $intStartTime = null, $intEndTime = null, $strIntervalDelimiter = ' – ', $strDelimiter = ', ')
{
$strStartDate = \Contao\Date::parse(\Contao\Date::getNumericDateFormat(), $intStartDate);
$strEndDate = \Contao\Date::parse(\Contao\Date::getNumericDateFormat(), $intEndDate);
$strStartTime = \Contao\Date::parse(\Contao\Date::getNumericTimeFormat(), $intStartTime);
$strEndTime = \Contao\Date::parse(\Contao\Date::getNumericTimeFormat(), $intEndTime);
$strResult = $strStartDate;
if ($intEndDate > 0 && $intEndDate > $intStartDate && $strStartDate != $strEndDate) {
$strResult .= $strIntervalDelimiter . $strEndDate;
}
if ($intStartTime > 0) {
if ($intEndTime > $intStartTime && $strStartTime != $strEndTime) {
$strResult .= $strDelimiter . $strStartTime . $strIntervalDelimiter . $strEndTime;
} else {
$strResult .= $strDelimiter . $strStartTime;
}
}
return $strResult;
}
示例12: renderDropdown
/**
* Render the versions dropdown menu
*
* @return string
*/
public function renderDropdown()
{
$objVersion = $this->Database->prepare("SELECT tstamp, version, username, active FROM tl_version WHERE fromTable=? AND pid=? ORDER BY version DESC")->execute($this->strTable, $this->intPid);
if ($objVersion->numRows < 2) {
return '';
}
$versions = '';
while ($objVersion->next()) {
$versions .= '
<option value="' . $objVersion->version . '"' . ($objVersion->active ? ' selected="selected"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['version'] . ' ' . $objVersion->version . ' (' . \Date::parse(\Config::get('datimFormat'), $objVersion->tstamp) . ') ' . $objVersion->username . '</option>';
}
return '
<div class="tl_version_panel">
<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_version" class="tl_form" method="post">
<div class="tl_formbody">
<input type="hidden" name="FORM_SUBMIT" value="tl_version">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<select name="version" class="tl_select">' . $versions . '
</select>
<button type="submit" name="showVersion" id="showVersion" class="tl_submit">' . $GLOBALS['TL_LANG']['MSC']['restore'] . '</button>
<a href="' . \Backend::addToUrl('versions=1&popup=1') . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']) . '" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . \StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['MSC']['recordOfTable'], $this->intPid, $this->strTable))) . '\',\'url\':this.href});return false">' . \Image::getHtml('diff.svg') . '</a>
</div>
</form>
</div>
';
}
示例13: compile
/**
* Generate the module
*/
protected function compile()
{
// Show logout form
if (FE_USER_LOGGED_IN) {
$this->import('FrontendUser', 'User');
$this->Template->logout = true;
$this->Template->formId = 'tl_logout_' . $this->id;
$this->Template->slabel = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['logout']);
$this->Template->loggedInAs = sprintf($GLOBALS['TL_LANG']['MSC']['loggedInAs'], $this->User->username);
$this->Template->action = ampersand(\Environment::get('indexFreeRequest'));
if ($this->User->lastLogin > 0) {
/** @var PageModel $objPage */
global $objPage;
$this->Template->lastLogin = sprintf($GLOBALS['TL_LANG']['MSC']['lastLogin'][1], \Date::parse($objPage->datimFormat, $this->User->lastLogin));
}
return;
}
$flashBag = \System::getContainer()->get('session')->getFlashBag();
if ($flashBag->has($this->strFlashType)) {
$this->Template->hasError = true;
$this->Template->message = $flashBag->get($this->strFlashType)[0];
}
$this->Template->username = $GLOBALS['TL_LANG']['MSC']['username'];
$this->Template->password = $GLOBALS['TL_LANG']['MSC']['password'][0];
$this->Template->action = ampersand(\Environment::get('indexFreeRequest'));
$this->Template->slabel = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['login']);
$this->Template->value = \StringUtil::specialchars(\Input::post('username'));
$this->Template->formId = 'tl_login_' . $this->id;
$this->Template->autologin = $this->autologin && \Config::get('autologin') > 0;
$this->Template->autoLabel = $GLOBALS['TL_LANG']['MSC']['autologin'];
}
示例14: formatValue
/**
* Format a value
*
* @param string $k
* @param mixed $value
* @param boolean $blnListSingle
*
* @return mixed
*/
protected function formatValue($k, $value, $blnListSingle = false)
{
$value = \StringUtil::deserialize($value);
// Return if empty
if (empty($value)) {
return '';
}
/** @var PageModel $objPage */
global $objPage;
// Array
if (is_array($value)) {
$value = implode(', ', $value);
} elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'date') {
$value = \Date::parse($objPage->dateFormat, $value);
} elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'time') {
$value = \Date::parse($objPage->timeFormat, $value);
} elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'datim') {
$value = \Date::parse($objPage->datimFormat, $value);
} elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'url' && preg_match('@^(https?://|ftp://)@i', $value)) {
$value = \Idna::decode($value);
// see #5946
$value = '<a href="' . $value . '" target="_blank">' . $value . '</a>';
} elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['rgxp'] == 'email') {
$value = \StringUtil::encodeEmail(\Idna::decode($value));
// see #5946
$value = '<a href="mailto:' . $value . '">' . $value . '</a>';
} elseif (is_array($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['reference'])) {
$value = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['reference'][$value];
} elseif ($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['eval']['isAssociative'] || array_is_assoc($GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['options'])) {
if ($blnListSingle) {
$value = $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['options'][$value];
} else {
$value = '<span class="value">[' . $value . ']</span> ' . $GLOBALS['TL_DCA'][$this->list_table]['fields'][$k]['options'][$value];
}
}
return $value;
}
示例15: compile
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$blnClearInput = false;
$intYear = \Input::get('year');
$intMonth = \Input::get('month');
$intDay = \Input::get('day');
// Jump to the current period
if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day'])) {
switch ($this->cal_format) {
case 'cal_year':
$intYear = date('Y');
break;
case 'cal_month':
$intMonth = date('Ym');
break;
case 'cal_day':
$intDay = date('Ymd');
break;
}
$blnClearInput = true;
}
$blnDynamicFormat = !$this->cal_ignoreDynamic && in_array($this->cal_format, array('cal_day', 'cal_month', 'cal_year'));
// Create the date object
try {
if ($blnDynamicFormat && $intYear) {
$this->Date = new \Date($intYear, 'Y');
$this->cal_format = 'cal_year';
$this->headline .= ' ' . date('Y', $this->Date->tstamp);
} elseif ($blnDynamicFormat && $intMonth) {
$this->Date = new \Date($intMonth, 'Ym');
$this->cal_format = 'cal_month';
$this->headline .= ' ' . \Date::parse('F Y', $this->Date->tstamp);
} elseif ($blnDynamicFormat && $intDay) {
$this->Date = new \Date($intDay, 'Ymd');
$this->cal_format = 'cal_day';
$this->headline .= ' ' . \Date::parse($objPage->dateFormat, $this->Date->tstamp);
} else {
$this->Date = new \Date();
}
} catch (\OutOfBoundsException $e) {
throw new PageNotFoundException('Page not found');
}
list($strBegin, $strEnd, $strEmpty) = $this->getDatesFromFormat($this->Date, $this->cal_format);
// Get all events
$arrAllEvents = $this->getAllEvents($this->cal_calendar, $strBegin, $strEnd);
$sort = $this->cal_order == 'descending' ? 'krsort' : 'ksort';
// Sort the days
$sort($arrAllEvents);
// Sort the events
foreach (array_keys($arrAllEvents) as $key) {
$sort($arrAllEvents[$key]);
}
$arrEvents = array();
$dateBegin = date('Ymd', $strBegin);
$dateEnd = date('Ymd', $strEnd);
// Remove events outside the scope
foreach ($arrAllEvents as $key => $days) {
if ($key < $dateBegin || $key > $dateEnd) {
continue;
}
foreach ($days as $day => $events) {
foreach ($events as $event) {
$event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w', $day)];
$event['firstDate'] = \Date::parse($objPage->dateFormat, $day);
$arrEvents[] = $event;
}
}
}
unset($arrAllEvents);
$total = count($arrEvents);
$limit = $total;
$offset = 0;
// Overall limit
if ($this->cal_limit > 0) {
$total = min($this->cal_limit, $total);
$limit = $total;
}
// Pagination
if ($this->perPage > 0) {
$id = 'page_e' . $this->id;
$page = \Input::get($id) !== null ? \Input::get($id) : 1;
// Do not index or cache the page if the page number is outside the range
if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
throw new PageNotFoundException('Page not found');
}
$offset = ($page - 1) * $this->perPage;
$limit = min($this->perPage + $offset, $total);
$objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id);
$this->Template->pagination = $objPagination->generate("\n ");
}
$strMonth = '';
$strDate = '';
$strEvents = '';
$dayCount = 0;
$eventCount = 0;
//.........这里部分代码省略.........