当前位置: 首页>>代码示例>>PHP>>正文


PHP SugarDateTime::createFromFormat方法代码示例

本文整理汇总了PHP中SugarDateTime::createFromFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP SugarDateTime::createFromFormat方法的具体用法?PHP SugarDateTime::createFromFormat怎么用?PHP SugarDateTime::createFromFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SugarDateTime的用法示例。


在下文中一共展示了SugarDateTime::createFromFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDSTRange

 /**
  * @deprecated for public use
  * get timezone start & end
  */
 public function getDSTRange($year, $zone)
 {
     $year_date = SugarDateTime::createFromFormat("Y", $year, self::$gmtTimezone);
     $year_end = clone $year_date;
     $year_end->setDate((int) $year, 12, 31);
     $year_end->setTime(23, 59, 59);
     $year_date->setDate((int) $year, 1, 1);
     $year_date->setTime(0, 0, 0);
     $tz = $this->_getUserTZ();
     $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
     $idx = 0;
     while (!$transitions[$idx]["isdst"]) {
         $idx++;
     }
     $startdate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     while ($transitions[$idx]["isdst"]) {
         $idx++;
     }
     $enddate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     return array("start" => $this->asDb($startdate), "end" => $this->asDb($enddate));
 }
开发者ID:nickpro,项目名称:sugarcrm_dev,代码行数:25,代码来源:TimeDate.php

示例2: get_time_data

 /**
  * Get array of needed time data
  * @param SugarBean $bean 
  * @return array
  */
 static function get_time_data($bean)
 {
     $arr = array();
     $date_field = "date_start";
     if ($bean->object_name == 'Task') {
         $date_field = "date_due";
     }
     $timestamp = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $bean->{$date_field}, new DateTimeZone('UTC'))->format('U');
     $arr['timestamp'] = $timestamp;
     $arr['time_start'] = $GLOBALS['timedate']->fromTimestamp($arr['timestamp'])->format($GLOBALS['timedate']->get_time_format());
     return $arr;
 }
开发者ID:netconstructor,项目名称:sugarcrm_dev,代码行数:17,代码来源:CalendarUtils.php

示例3: saveRecurring

 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $timeArray array of datetimes
  * @return array
  */
 static function saveRecurring(SugarBean $bean, $timeArray)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     $db = $GLOBALS['db'];
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     // If the bean has a users_arr then related records for those ids will have
     // already been created. This prevents duplicates of those records for
     // users, contacts and leads (handled below)
     $exclude_users = empty($bean->users_arr) ? array() : array_flip($bean->users_arr);
     while ($ro = $db->fetchByAssoc($re)) {
         if (!isset($exclude_users[$ro['user_id']])) {
             $users_rel_arr[] = $ro['user_id'];
         }
     }
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_contacts = array();
     $qu_users = array();
     $qu_leads = array();
     $arr = array();
     $i = 0;
     Activity::disable();
     $clone = clone $bean;
     //this is a new bean being created - so throw away cloned fetched_row
     //attribute that incorrectly makes it look like an existing bean
     $clone->fetched_row = false;
     foreach ($timeArray as $date_start) {
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 $qu_users[] = array('id' => create_guid(), 'user_id' => $user_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 $qu_contacts[] = array('id' => create_guid(), 'contact_id' => $contact_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($leads_rel_arr as $lead_id) {
                 $qu_leads[] = array('id' => create_guid(), 'lead_id' => $lead_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     Activity::enable();
     if (!empty($qu_users)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'user_id' => array('name' => 'user_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_users as $qu_user) {
             $db->insertParams($bean->rel_users_table, $fields, $qu_user);
         }
     }
     if (!empty($qu_contacts)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'contact_id' => array('name' => 'contact_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_contacts as $qu_contact) {
             $db->insertParams($bean->rel_contacts_table, $fields, $qu_contact);
         }
     }
     if (!empty($qu_leads)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'lead_id' => array('name' => 'lead_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_leads as $qu_lead) {
             $db->insertParams($bean->rel_leads_table, $fields, $qu_lead);
         }
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
//.........这里部分代码省略.........
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:101,代码来源:CalendarUtils.php

示例4: getDSTRange

 /**
  * @deprecated for public use
  * get timezone start & end
  * @param $year
  * @param string $zone
  * @return array
  */
 public function getDSTRange($year, $zone = null)
 {
     if (!empty($zone)) {
         $tz = timezone_open($zone);
     }
     if (empty($tz)) {
         $tz = $this->_getUserTZ();
     }
     $year_date = SugarDateTime::createFromFormat("Y", $year, self::$gmtTimezone);
     $year_end = clone $year_date;
     $year_end->setDate((int) $year, 12, 31);
     $year_end->setTime(23, 59, 59);
     $year_date->setDate((int) $year, 1, 1);
     $year_date->setTime(0, 0, 0);
     $result = array();
     $transitions = $tz->getTransitions($year_date->ts, $year_end->ts);
     $idx = 0;
     if (version_compare(PHP_VERSION, '5.3.0', '<')) {
         // <5.3.0 ignores parameters, advance manually to current year
         $start_ts = $year_date->ts;
         while (isset($transitions[$idx]) && $transitions[$idx]["ts"] < $start_ts) {
             $idx++;
         }
     }
     // get DST start
     while (isset($transitions[$idx]) && !$transitions[$idx]["isdst"]) {
         $idx++;
     }
     if (isset($transitions[$idx])) {
         $result["start"] = $this->fromTimestamp($transitions[$idx]["ts"])->asDb();
     }
     // get DST end
     while (isset($transitions[$idx]) && $transitions[$idx]["isdst"]) {
         $idx++;
     }
     if (isset($transitions[$idx])) {
         $result["end"] = $this->fromTimestamp($transitions[$idx]["ts"])->asDb();
     }
     return $result;
 }
开发者ID:delkyd,项目名称:sugarcrm_dev,代码行数:47,代码来源:TimeDate.php

示例5: fill_in_additional_detail_fields

 function fill_in_additional_detail_fields()
 {
     global $locale;
     // Fill in the assigned_user_name
     $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
     if (!empty($this->contact_id)) {
         $query = "SELECT first_name, last_name FROM contacts ";
         $query .= "WHERE id='{$this->contact_id}' AND deleted=0";
         $result = $this->db->limitQuery($query, 0, 1, true, " Error filling in additional detail fields: ");
         // Get the contact name.
         $row = $this->db->fetchByAssoc($result);
         $GLOBALS['log']->info("additional call fields {$query}");
         if ($row != null) {
             $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', '');
             $GLOBALS['log']->debug("Call({$this->id}): contact_name = {$this->contact_name}");
             $GLOBALS['log']->debug("Call({$this->id}): contact_id = {$this->contact_id}");
         }
     }
     $this->created_by_name = get_assigned_user_name($this->created_by);
     $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
     $this->fill_in_additional_parent_fields();
     if (!isset($this->time_hour_start)) {
         $this->time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     //if-else
     if (isset($this->time_minute_start)) {
         $time_start_minutes = $this->time_minute_start;
     } else {
         $time_start_minutes = substr($this->time_start, 3, 5);
         if ($time_start_minutes > 0 && $time_start_minutes < 15) {
             $time_start_minutes = "15";
         } else {
             if ($time_start_minutes > 15 && $time_start_minutes < 30) {
                 $time_start_minutes = "30";
             } else {
                 if ($time_start_minutes > 30 && $time_start_minutes < 45) {
                     $time_start_minutes = "45";
                 } else {
                     if ($time_start_minutes > 45) {
                         $this->time_start_hour += 1;
                         $time_start_minutes = "00";
                     }
                 }
             }
         }
         //if-else
     }
     //if-else
     if (isset($this->time_hour_start)) {
         $time_start_hour = $this->time_hour_start;
     } else {
         $time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     global $timedate;
     $this->time_meridiem = $timedate->AMPMMenu('', $this->time_start, 'onchange="SugarWidgetScheduler.update_time();"');
     $hours_arr = array();
     $num_of_hours = 13;
     $start_at = 1;
     if (empty($time_meridiem)) {
         $num_of_hours = 24;
         $start_at = 0;
     }
     //if
     for ($i = $start_at; $i < $num_of_hours; $i++) {
         $i = $i . "";
         if (strlen($i) == 1) {
             $i = "0" . $i;
         }
         $hours_arr[$i] = $i;
     }
     //for
     if (!isset($this->duration_minutes)) {
         $this->duration_minutes = $this->minutes_value_default;
     }
     //setting default date and time
     if (is_null($this->date_start)) {
         $this->date_start = $timedate->now();
     }
     if (is_null($this->time_start)) {
         $this->time_start = $timedate->to_display_time(TimeDate::getInstance()->nowDb(), true);
     }
     if (is_null($this->duration_hours)) {
         $this->duration_hours = "0";
     }
     if (is_null($this->duration_minutes)) {
         $this->duration_minutes = "1";
     }
     if (empty($this->id) && !empty($_REQUEST['date_start'])) {
         $this->date_start = $_REQUEST['date_start'];
     }
     if (!empty($this->date_start)) {
         $start = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $this->date_start);
         if (!empty($start)) {
             if (!empty($this->duration_hours) || !empty($this->duration_minutes)) {
                 $this->date_end = $start->modify("+{$this->duration_hours} Hours +{$this->duration_minutes} Minutes")->format($GLOBALS['timedate']->get_date_time_format());
             }
         } else {
             $GLOBALS['log']->fatal("Meeting::save: Bad date {$this->date_start} for format " . $GLOBALS['timedate']->get_date_time_format());
         }
     }
//.........这里部分代码省略.........
开发者ID:jgera,项目名称:sugarcrm_dev,代码行数:101,代码来源:Meeting.php

示例6: get_ical_event

 /**
  * get ics file content for meeting invite email
  */
 public static function get_ical_event(SugarBean $bean, User $user)
 {
     $str = "";
     $str .= "BEGIN:VCALENDAR\n";
     $str .= "VERSION:2.0\n";
     $str .= "PRODID:-//SugarCRM//SugarCRM Calendar//EN\n";
     $str .= "BEGIN:VEVENT\n";
     $str .= "UID:" . $bean->id . "\n";
     $str .= "ORGANIZER;CN=" . $user->full_name . ":" . $user->email1 . "\n";
     $str .= "DTSTART:" . SugarDateTime::createFromFormat($GLOBALS['timedate']->get_db_date_time_format(), $bean->date_start)->format(self::UTC_FORMAT) . "\n";
     $str .= "DTEND:" . SugarDateTime::createFromFormat($GLOBALS['timedate']->get_db_date_time_format(), $bean->date_end)->format(self::UTC_FORMAT) . "\n";
     $str .= "DTSTAMP:" . $GLOBALS['timedate']->getNow(false)->format(self::UTC_FORMAT) . "\n";
     $str .= "SUMMARY:" . $bean->name . "\n";
     $str .= "DESCRIPTION:" . $bean->description . "\n";
     $str .= "END:VEVENT\n";
     $str .= "END:VCALENDAR\n";
     return $str;
 }
开发者ID:jgera,项目名称:sugarcrm_dev,代码行数:21,代码来源:vCal.php

示例7: get_freebusy_activities

 function get_freebusy_activities($user_focus, $start_date_time, $end_date_time)
 {
     $act_list = array();
     $vcal_focus = new vCal();
     $vcal_str = $vcal_focus->get_vcal_freebusy($user_focus);
     $lines = explode("\n", $vcal_str);
     $utc = new DateTimeZone("UTC");
     foreach ($lines as $line) {
         if (preg_match('/^FREEBUSY.*?:([^\\/]+)\\/([^\\/]+)/i', $line, $matches)) {
             $dates_arr = array(SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[1], $utc), SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[2], $utc));
             $act_list[] = new CalendarActivity($dates_arr);
         }
     }
     return $act_list;
 }
开发者ID:NALSS,项目名称:SuiteCRM,代码行数:15,代码来源:CalendarActivity.php

示例8: getDSTRange

 public function getDSTRange($current_user, $year)
 {
     $tz = $this->getUserTimezone($current_user);
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $year_date = SugarDateTime::createFromFormat("Y", $year, $tz);
         $year_end = clone $year_date;
         $year_end->setDate((int) $year, 12, 31);
         $year_end->setTime(23, 59, 59);
         $year_date->setDate((int) $year, 1, 1);
         $year_date->setTime(0, 0, 0);
         $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
         $idx = 0;
         while (!$transitions[$idx]["isdst"] && $idx < count($transitions)) {
             $idx++;
         }
         if (!$transitions[$idx]["isdst"]) {
             // No DST transitions found
             return array();
         }
         $startTransition = $transitions[$idx];
         while ($transitions[$idx]["isdst"]) {
             $idx++;
         }
         $endTransition = $transitions[$idx];
     } else {
         $transitions = $tz->getTransitions();
         $idx = 0;
         while (!$transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $startTransition = $transitions[$idx];
         while ($transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $endTransition = $transitions[$idx];
     }
     return array("start" => $startTransition, "end" => $endTransition);
 }
开发者ID:rgauss,项目名称:sugar-ical-patch,代码行数:38,代码来源:iCal.php

示例9: getFreeBusySchedule

 /**
  * Retrieve a list of this person's calendar event start and end times ordered by start datetime
  * @return array
  */
 public function getFreeBusySchedule(array $options = array())
 {
     global $timedate;
     global $sugar_config;
     //--- Explicit config can be used to force use of vCal Cache instead of RealTime Search
     $useFreeBusyCache = !empty($sugar_config['freebusy_use_vcal_cache']);
     $vcalBean = BeanFactory::getBean('vCals');
     if (!$useFreeBusyCache && !empty($options['start']) && !empty($options['end'])) {
         $sugarDateTimeStart = $timedate->fromIso($options['start']);
         $sugarDateTimeEnd = $timedate->fromIso($options['end']);
         $vcalData = $vcalBean->get_vcal_freebusy($this, false, $sugarDateTimeStart, $sugarDateTimeEnd);
     } else {
         $vcalData = $vcalBean->get_vcal_freebusy($this, true);
     }
     $vcalData = str_replace("\r\n", "\n", $vcalData);
     $lines = explode("\n", $vcalData);
     $utc = new DateTimeZone("UTC");
     $activities = array();
     foreach ($lines as $line) {
         if (preg_match('/^FREEBUSY.*?:([^\\/]+)\\/([^\\/]+)/i', $line, $matches)) {
             $datesArray = array(SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[1], $utc), SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[2], $utc));
             $act = new CalendarActivity($datesArray);
             $startTime = $timedate->asIso($act->start_time);
             $endTime = $timedate->asIso($act->end_time);
             $activities[$startTime] = array("start" => $startTime, "end" => $endTime);
         }
     }
     ksort($activities);
     // order by start date
     $freeBusySchedule = array();
     foreach ($activities as $startDate => $act) {
         $freeBusySchedule[] = $act;
     }
     return $freeBusySchedule;
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:39,代码来源:Person.php

示例10: testparseDateRange

 /**
  * @dataProvider dateRanges
  */
 public function testparseDateRange($range, $start, $end)
 {
     $this->time_date->setNow(SugarDateTime::createFromFormat(TimeDate::DB_DATETIME_FORMAT, "2011-08-30 12:01:02", new DateTimeZone($this->time_date->userTimezone())));
     $this->time_date->allow_cache = true;
     $daterage = $this->time_date->parseDateRange($range);
     $this->assertEquals($start, $daterage[0]->format(TimeDate::DB_DATETIME_FORMAT), 'Start date is wrong');
     $this->assertEquals($end, $daterage[1]->format(TimeDate::DB_DATETIME_FORMAT), 'End date is wrong');
 }
开发者ID:netconstructor,项目名称:sugarcrm_dev,代码行数:11,代码来源:TimeDateTest.php

示例11: testCreateFromString

 /**
  * @dataProvider stringFormats
  * @param string $format
  * @param string $string
  * @param string $result
  */
 public function testCreateFromString($format, $string, $result)
 {
     $this->_setPrefs("Y-m-d", $format, "GMT");
     $tz = new DateTimeZone("GMT");
     SugarDateTime::$use_php_parser = true;
     $date = SugarDateTime::createFromFormat($format, $string, $tz);
     $this->assertInstanceOf("SugarDateTime", $date, "Parsing {$string} failed with PHP parser");
     $this->assertEquals($result, $this->time_date->getTimePart($date->asDb()));
     SugarDateTime::$use_php_parser = false;
     $date = SugarDateTime::createFromFormat($format, $string, $tz);
     $this->assertInstanceOf("SugarDateTime", $date, "Parsing {$string} failed with strptime");
     $this->assertEquals($result, $this->time_date->getTimePart($date->asDb()));
     SugarDateTime::$use_strptime = false;
     $date = SugarDateTime::createFromFormat($format, $string, $tz);
     $this->assertInstanceOf("SugarDateTime", $date, "Parsing {$string} failed with manual parser");
     $this->assertEquals($result, $this->time_date->getTimePart($date->asDb()));
     SugarDateTime::$use_php_parser = true;
     SugarDateTime::$use_strptime = true;
 }
开发者ID:nickpro,项目名称:sugarcrm_dev,代码行数:25,代码来源:TimeDateTest.php

示例12: fill_in_additional_detail_fields

 function fill_in_additional_detail_fields()
 {
     global $locale;
     parent::fill_in_additional_detail_fields();
     if (!empty($this->contact_id)) {
         $query = "SELECT first_name, last_name FROM contacts ";
         $query .= "WHERE id='{$this->contact_id}' AND deleted=0";
         $result = $this->db->limitQuery($query, 0, 1, true, " Error filling in additional detail fields: ");
         // Get the contact name.
         $row = $this->db->fetchByAssoc($result);
         $GLOBALS['log']->info("additional call fields {$query}");
         if ($row != null) {
             $this->contact_name = $locale->formatName('Contacts', $row);
             $GLOBALS['log']->debug("Call({$this->id}): contact_name = {$this->contact_name}");
             $GLOBALS['log']->debug("Call({$this->id}): contact_id = {$this->contact_id}");
         }
     }
     if (!isset($this->time_hour_start)) {
         $this->time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     //if-else
     if (isset($this->time_minute_start)) {
         $time_start_minutes = $this->time_minute_start;
     } else {
         $time_start_minutes = substr($this->time_start, 3, 5);
         if ($time_start_minutes > 0 && $time_start_minutes < 15) {
             $time_start_minutes = "15";
         } else {
             if ($time_start_minutes > 15 && $time_start_minutes < 30) {
                 $time_start_minutes = "30";
             } else {
                 if ($time_start_minutes > 30 && $time_start_minutes < 45) {
                     $time_start_minutes = "45";
                 } else {
                     if ($time_start_minutes > 45) {
                         $this->time_start_hour += 1;
                         $time_start_minutes = "00";
                     }
                 }
             }
         }
         //if-else
     }
     //if-else
     if (isset($this->time_hour_start)) {
         $time_start_hour = $this->time_hour_start;
     } else {
         $time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     global $timedate;
     $this->time_meridiem = $timedate->AMPMMenu('', $this->time_start, 'onchange="SugarWidgetScheduler.update_time();"');
     $hours_arr = array();
     $num_of_hours = 13;
     $start_at = 1;
     if (empty($time_meridiem)) {
         $num_of_hours = 24;
         $start_at = 0;
     }
     //if
     for ($i = $start_at; $i < $num_of_hours; $i++) {
         $i = $i . "";
         if (strlen($i) == 1) {
             $i = "0" . $i;
         }
         $hours_arr[$i] = $i;
     }
     //for
     if (!isset($this->duration_minutes)) {
         $this->duration_minutes = $this->minutes_value_default;
     }
     //setting default date and time
     if (is_null($this->date_start)) {
         $this->date_start = $timedate->now();
     }
     if (is_null($this->time_start)) {
         $this->time_start = $timedate->to_display_time(TimeDate::getInstance()->nowDb(), true);
     }
     if (is_null($this->duration_hours)) {
         $this->duration_hours = "0";
     }
     if (is_null($this->duration_minutes)) {
         $this->duration_minutes = "1";
     }
     if (empty($this->id) && !empty($_REQUEST['date_start'])) {
         $this->date_start = $_REQUEST['date_start'];
     }
     if (!empty($this->date_start)) {
         $td = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $this->date_start);
         if (!empty($td)) {
             if (!empty($this->duration_hours) && $this->duration_hours != '') {
                 $td = $td->modify("+{$this->duration_hours} hours");
             }
             if (!empty($this->duration_minutes) && $this->duration_minutes != '') {
                 $td = $td->modify("+{$this->duration_minutes} mins");
             }
             $this->date_end = $td->format($GLOBALS['timedate']->get_date_time_format());
         } else {
             $GLOBALS['log']->fatal("Meeting::save: Bad date {$this->date_start} for format " . $GLOBALS['timedate']->get_date_time_format());
         }
     }
//.........这里部分代码省略.........
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:101,代码来源:Meeting.php

示例13: 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'));
 }
开发者ID:jglaine,项目名称:sugar761-ent,代码行数:47,代码来源:TimePeriod.php

示例14: getDSTRange

 /**
  * @deprecated for public use
  * get timezone start & end
  */
 public function getDSTRange($year, $zone)
 {
     $tz = $this->_getUserTZ();
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $year_date = SugarDateTime::createFromFormat("Y", $year, self::$gmtTimezone);
         $year_end = clone $year_date;
         $year_end->setDate((int) $year, 12, 31);
         $year_end->setTime(23, 59, 59);
         $year_date->setDate((int) $year, 1, 1);
         $year_date->setTime(0, 0, 0);
         $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
         $idx = 0;
         while (!$transitions[$idx]["isdst"]) {
             $idx++;
         }
         $startdate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
         while ($transitions[$idx]["isdst"]) {
             $idx++;
         }
         $enddate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     } else {
         $transitions = $tz->getTransitions();
         $idx = 0;
         while (!$transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $startdate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
         while ($transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $enddate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     }
     return array("start" => $this->asDb($startdate), "end" => $this->asDb($enddate));
 }
开发者ID:rgauss,项目名称:sugarcrm_dev,代码行数:38,代码来源:TimeDate.php

示例15: importSanitize

 /**
  * @see SugarFieldBase::importSanitize()
  */
 public function importSanitize($value, $vardef, $focus, ImportFieldSanitize $settings)
 {
     global $timedate;
     $format = $timedate->merge_date_time($settings->dateformat, $settings->timeformat);
     if (!$timedate->check_matching_format($value, $format)) {
         $parts = $timedate->split_date_time($value);
         if (empty($parts[0])) {
             $datepart = $timedate->getNow()->format($settings->dateformat);
         } else {
             $datepart = $parts[0];
         }
         if (empty($parts[1])) {
             $timepart = $timedate->fromTimestamp(0)->format($settings->timeformat);
         } else {
             $timepart = $parts[1];
             // see if we can get by stripping the seconds
             if (strpos($settings->timeformat, 's') === false) {
                 $sep = $timedate->timeSeparatorFormat($settings->timeformat);
                 // We are assuming here seconds are the last component, which
                 // is kind of reasonable - no sane time format puts seconds first
                 $timeparts = explode($sep, $timepart);
                 if (!empty($timeparts[2])) {
                     $timepart = join($sep, array($timeparts[0], $timeparts[1]));
                 }
             }
         }
         $value = $timedate->merge_date_time($datepart, $timepart);
         if (!$timedate->check_matching_format($value, $format)) {
             return false;
         }
     }
     try {
         $date = SugarDateTime::createFromFormat($format, $value, new DateTimeZone($settings->timezone));
     } catch (Exception $e) {
         return false;
     }
     return $date->asDb();
 }
开发者ID:delkyd,项目名称:sugarcrm_dev,代码行数:41,代码来源:SugarFieldDatetime.php


注:本文中的SugarDateTime::createFromFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。