本文整理汇总了PHP中SugarDateTime::setTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP SugarDateTime::setTimezone方法的具体用法?PHP SugarDateTime::setTimezone怎么用?PHP SugarDateTime::setTimezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SugarDateTime
的用法示例。
在下文中一共展示了SugarDateTime::setTimezone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'));
}
示例2: empty
/**
* @deprecated for public use
* handles offset values for Timezones and DST
* @param $date string date/time formatted in user's selected format
* @param $format string destination format value as passed to PHP's date() funtion
* @param $to boolean
* @param $user object user object from which Timezone and DST
* @param $usetimezone string timezone name
* values will be derived
* @return string date formatted and adjusted for TZ and DST
*/
function handle_offset($date, $format, $to = true, $user = null, $usetimezone = null)
{
$tz = empty($usetimezone) ? $this->_getUserTZ($user) : new DateTimeZone($usetimezone);
$dateobj = new SugarDateTime($date, $to ? self::$gmtTimezone : $tz);
$dateobj->setTimezone($to ? $tz : self::$gmtTimezone);
return $dateobj->format($format);
// return $this->_convert($date, $format, $to ? self::$gmtTimezone : $tz, $format, $to ? $tz : self::$gmtTimezone);
}
示例3: toDatabaseSearchDateTime
/**
* Set the DateTime Search Data based on Current User TimeZone
*
* @param string $userSearchDateTime - user Search Datetime
* @return string $dbSearchDateTime - database Search Datetime
*/
public function toDatabaseSearchDateTime($userSearchDateTime)
{
global $timedate;
global $current_user;
$usertimezone = $current_user->getPreference('timezone');
if (empty($usertimezone)) {
$usertimezone = "UTC";
}
$tz = new DateTimeZone($usertimezone);
$sugarDateTime = new SugarDateTime($userSearchDateTime);
$sugarDateTime->setTimezone($tz);
$dbSearchDateTime = $timedate->asDb($sugarDateTime);
return $dbSearchDateTime;
}