本文整理汇总了PHP中Mautic\CoreBundle\Helper\DateTimeHelper::setDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeHelper::setDateTime方法的具体用法?PHP DateTimeHelper::setDateTime怎么用?PHP DateTimeHelper::setDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mautic\CoreBundle\Helper\DateTimeHelper
的用法示例。
在下文中一共展示了DateTimeHelper::setDateTime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toText
/**
* Returns date/time like Today, 10:00 AM
*
* @param $datetime
* @param string $timezone
* @param string $fromFormat
*/
public function toText($datetime, $timezone = 'local', $fromFormat = 'Y-m-d H:i:s')
{
if (empty($datetime)) {
return '';
}
$this->helper->setDateTime($datetime, $fromFormat, $timezone);
$textDate = $this->helper->getTextDate();
$dt = $this->helper->getLocalDateTime();
if ($textDate) {
return $this->translator->trans('mautic.core.date.' . $textDate, array('%time%' => $dt->format("g:i a")));
} else {
$interval = $this->helper->getDiff('now', null, true);
return $this->translator->trans('mautic.core.date.ago', array('%days%' => $interval->days));
}
}
示例2: toText
/**
* Returns date/time like Today, 10:00 AM
*
* @param $datetime
* @param string $timezone
* @param string $fromFormat
* @param bool $forceDateForNonText If true, return as full date/time rather than "29 days ago"
*
* @return string
*/
public function toText($datetime, $timezone = 'local', $fromFormat = 'Y-m-d H:i:s', $forceDateForNonText = false)
{
if (empty($datetime)) {
return '';
}
$this->helper->setDateTime($datetime, $fromFormat, $timezone);
$textDate = $this->helper->getTextDate();
$dt = $this->helper->getLocalDateTime();
if ($textDate) {
return $this->translator->trans('mautic.core.date.' . $textDate, array('%time%' => $dt->format("g:i a")));
} else {
$interval = $this->helper->getDiff('now', null, true);
if ($interval->invert && !$forceDateForNonText) {
// In the past
return $this->translator->trans('mautic.core.date.ago', array('%days%' => $interval->days));
} else {
// In the future
return $this->toFullConcat($datetime, $timezone, $fromFormat);
}
}
}
示例3: getListFilterExpr
//.........这里部分代码省略.........
case 'yesterday':
if ($timeframe == 'yesterday') {
$dtHelper->modify('-1 day');
} elseif ($timeframe == 'tomorrow') {
$dtHelper->modify('+1 day');
}
// Today = 2015-08-28 00:00:00
if ($requiresBetween) {
// eq:
// field >= 2015-08-28 00:00:00
// field < 2015-08-29 00:00:00
// neq:
// field < 2015-08-28 00:00:00
// field >= 2015-08-29 00:00:00
$modifier = '+1 day';
} else {
// lt:
// field < 2015-08-28 00:00:00
// gt:
// field > 2015-08-28 23:59:59
// lte:
// field <= 2015-08-28 23:59:59
// gte:
// field >= 2015-08-28 00:00:00
if (in_array($func, array('gt', 'lte'))) {
$modifier = '+1 day -1 second';
}
}
break;
case 'week_last':
case 'week_next':
case 'week_this':
$interval = str_replace('week_', '', $timeframe);
$dtHelper->setDateTime('midnight monday ' . $interval . ' week', null);
// This week: Monday 2015-08-24 00:00:00
if ($requiresBetween) {
// eq:
// field >= Mon 2015-08-24 00:00:00
// field < Mon 2015-08-31 00:00:00
// neq:
// field < Mon 2015-08-24 00:00:00
// field >= Mon 2015-08-31 00:00:00
$modifier = '+1 week';
} else {
// lt:
// field < Mon 2015-08-24 00:00:00
// gt:
// field > Sun 2015-08-30 23:59:59
// lte:
// field <= Sun 2015-08-30 23:59:59
// gte:
// field >= Mon 2015-08-24 00:00:00
if (in_array($func, array('gt', 'lte'))) {
$modifier = '+1 week -1 second';
}
}
break;
case 'month_last':
case 'month_next':
case 'month_this':
$interval = substr($key, -4);
$dtHelper->setDateTime('midnight first day of ' . $interval . ' month', null);
// This month: 2015-08-01 00:00:00
if ($requiresBetween) {
// eq:
// field >= 2015-08-01 00:00:00
示例4: getLeadStats
/**
* Fetch Lead stats for some period of time.
*
* @param integer $quantity of units
* @param string $unit of time php.net/manual/en/class.dateinterval.php#dateinterval.props
* @param array $options
*
* @return mixed
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getLeadStats($quantity, $unit, $options = array())
{
$graphData = GraphHelper::prepareDatetimeLineGraphData($quantity, $unit, array('viewed'));
// Load points for selected period
$q = $this->getEntityManager()->getConnection()->createQueryBuilder();
$q->select(sprintf('count(*) as count, DATE(cl.date_added) as date_added'))->from(MAUTIC_TABLE_PREFIX . 'campaign_leads', 'cl');
$utc = new \DateTimeZone('UTC');
$graphData['fromDate']->setTimezone($utc);
$q->andwhere($q->expr()->andX($q->expr()->gte('cl.date_added', ':date'), $q->expr()->eq('cl.manually_removed', ':false')))->setParameter('date', $graphData['fromDate']->format('Y-m-d H:i:s'))->setParameter('false', false, 'boolean')->groupBy('DATE(cl.date_added)')->orderBy('date_added', 'ASC');
if (isset($options['campaign_id'])) {
$q->andwhere($q->expr()->gte('cl.campaign_id', (int) $options['campaign_id']));
}
$datesAdded = $q->execute()->fetchAll();
$format = GraphHelper::getDateLabelFormat($unit);
$formattedDates = array();
$dt = new DateTimeHelper();
foreach ($datesAdded as &$date) {
$dt->setDateTime($date['date_added'], 'Y-m-d', 'utc');
$key = $dt->getDateTime()->format($format);
$formattedDates[$key] = (int) $date['count'];
}
foreach ($graphData['labels'] as $key => $label) {
$graphData['datasets'][0]['data'][$key] = isset($formattedDates[$label]) ? $formattedDates[$label] : 0;
}
unset($graphData['fromDate']);
return $graphData;
}