本文整理汇总了PHP中SugarDateTime::asDbDate方法的典型用法代码示例。如果您正苦于以下问题:PHP SugarDateTime::asDbDate方法的具体用法?PHP SugarDateTime::asDbDate怎么用?PHP SugarDateTime::asDbDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SugarDateTime
的用法示例。
在下文中一共展示了SugarDateTime::asDbDate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatDate
/**
* Formats a DateTime object as string for given widget
*
* @param SugarDateTime $date - Date to be formatted for widget
* @return string date formatted for widget type
*/
protected function formatDate($date)
{
return $date->asDbDate(false);
}
示例2: getGenericStartEndByDuration
/**
* @param integer $duration
* @param string|null $start_date The starting date in format of Y-m-d
* @return array
*/
public function getGenericStartEndByDuration($duration, $start_date = null)
{
$mapping = array('current' => 0, 'next' => 3, 'year' => 12);
if (array_key_exists($duration, $mapping)) {
$duration = $mapping[$duration];
} elseif (!is_numeric($duration)) {
$duration = 0;
}
$start = false;
if (!is_null($start_date)) {
$start = SugarDateTime::createFromFormat('Y-m-d', $start_date);
$end = SugarDateTime::createFromFormat('Y-m-d', $start_date);
}
if ($start === false) {
$start = new SugarDateTime();
$end = new SugarDateTime();
}
// since we subtract one from the month, we need to add one to the duration since php is
// not zero 0 based for months
// figure out what the starting month is.
$startMonth = floor(($start->month - 1) / 3) * 3 + $duration + 1;
$year = $start->year;
$endYear = $year;
$endMonth = $startMonth + 3;
// if the end month is dec, we put it to Jan and increase the end year as well so it goes back to the last
// day of dec
if ($endMonth == 12) {
$endYear++;
$endMonth = 1;
}
if ($duration == 12) {
$endYear++;
$startMonth = 1;
$endMonth = 1;
}
$start->setDate($year, $startMonth, 1);
$end->setDate($endYear, $endMonth, 0);
// since we are using timestamp, we need to convert this into UTC since that is
// what the DB is storing as
$tz = new DateTimeZone("UTC");
return array('start_date' => $start->asDbDate(false), 'start_date_timestamp' => $start->setTimezone($tz)->setTime(0, 0, 0)->format('U'), 'end_date' => $end->asDbDate(false), 'end_date_timestamp' => $end->setTimezone($tz)->setTime(0, 0, 0)->format('U'));
}