/** * Returns human readable date. * * Set the offset to the system offset as the dates returned by the * cache keys are not GMT. * * @param array An optional array with configuration options. * @return string Formatted date. */ public function humanize($config = array()) { $config = new KConfig($config); $config->append(array( 'gmt_offset' => date_offset_get(new DateTime) )); return parent::humanize($config); }
/** * Returns human readable date. * * @param array An optional array with configuration options. * @return string Formatted date. */ public function humanize($config = array()) { $config = new KConfig($config); $config->append(array('date' => null, 'gmt_offset' => date_offset_get(new DateTime()), 'smallest_period' => 'second')); $periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year'); $lengths = array(60, 60, 24, 7, 4.35, 12, 10); $now = strtotime(gmdate("M d Y H:i:s")); $time = is_numeric($config->date) ? $config->date : strtotime($config->date); if ($time) { if ($config->gmt_offset != 0) { $now = $now + $config->gmt_offset; } if ($now != $time) { if ($now > $time) { $difference = $now - $time; $tense = 'ago'; } else { $difference = $time - $now; $tense = 'from now'; } for ($i = 0; $difference >= $lengths[$i] && $i < 6; $i++) { $difference /= $lengths[$i]; } $difference = round($difference); $period_index = array_search($config->smallest_period, $periods); $omitted_periods = $periods; array_splice($omitted_periods, $period_index); if (in_array($periods[$i], $omitted_periods)) { $difference = 1; $i = $period_index; } if ($periods[$i] == 'day') { switch ($difference) { case 1: return 'Today'; break; case 2: return $tense == 'ago' ? 'Yesterday' : 'Tomorrow'; break; } } if ($difference != 1) { $periods[$i] .= 's'; } $result = sprintf(JText::_('%s ' . $periods[$i] . ' ' . $tense), $difference); } else { $result = JText::_('Now'); } } else { $result = JText::_('Never'); } return $result; }
/** * Returns human readable date. * * @param array An optional array with configuration options. * @return string Formatted date. */ public function humanize($config = array()) { $config = new KConfig($config); $config->append(array('date' => null, 'gmt_offset' => date_offset_get(new DateTime()), 'smallest_period' => 'second')); $periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year'); $lengths = array(60, 60, 24, 7, 4.35, 12, 10); $now = strtotime(gmdate("M d Y H:i:s")); $time = is_numeric($config->date) ? $config->date : strtotime($config->date); if ($time) { if ($config->gmt_offset != 0) { $now = $now + $config->gmt_offset; } if ($now != $time) { if ($now > $time) { $difference = $now - $time; $tense = 'ago'; } else { $difference = $time - $now; $tense = 'from now'; } for ($i = 0; $difference >= $lengths[$i] && $i < 6; $i++) { $difference /= $lengths[$i]; } $difference = round($difference); $period_index = array_search($config->smallest_period, $periods); $omitted_periods = $periods; array_splice($omitted_periods, $period_index); if (in_array($periods[$i], $omitted_periods)) { $difference = 1; $i = $period_index; } if ($periods[$i] == 'day' && $difference == 1) { // Since we got 1 by rounding it down and if it's less than 24 hours it would say x hours ago, this is yesterday return $tense == 'ago' ? $this->translate('Yesterday') : $this->translate('Tomorrow'); } $period = $periods[$i]; $period_plural = $period . 's'; // We do not pass $period or $tense as parameters to replace because // some languages use different words for them based on the time difference. $translator = $this->getTemplate()->getHelper('translator')->getTranslator(); $result = $translator->choose(array("%number% {$period} {$tense}", "%number% {$period_plural} {$tense}"), $difference, array('%number%' => $difference)); } else { $result = $this->translate('Just now'); } } else { $result = $this->translate('Never'); } return $result; }
function nicetime($posted_date, $admin = false, $nohour = false) { // Adapted for something found on Internet, but I forgot to keep the url... $act_opt = get_option('act_settings'); $date_relative = $act_opt['act_date_relative']; $date_format = $act_opt['act_date_format']; $gmt_offset = get_option('gmt_offset'); if (empty($gmt_offset) and $gmt_offset != 0) { $timezone = get_option('timezone_string'); $gmt = date_create($posted_date, timezone_open($timezone)); $gmt_offset = date_offset_get($gmt) / 3600; } /*$cur_time_gmt = current_time('timestamp', true); $posted_date = gmdate("Y-m-d H:i:s", strtotime($posted_date) + ($gmt_offset * 3600)); $in_seconds = strtotime($posted_date);*/ $cur_time_gmt = time(); $in_seconds = strtotime($posted_date); $posted_date = gmdate("Y-m-d H:i:s", strtotime($posted_date) + $gmt_offset * 3600); $relative_date = ''; $diff = $cur_time_gmt - $in_seconds; $months = floor($diff / 2592000); $diff -= $months * 2419200; $weeks = floor($diff / 604800); $diff -= $weeks * 604800; $days = floor($diff / 86400); $diff -= $days * 86400; $hours = floor($diff / 3600); $diff -= $hours * 3600; $minutes = floor($diff / 60); $diff -= $minutes * 60; $seconds = $diff; if ($months > 0 or !$date_relative or $admin) { // over a month old, just show date if ((!$date_relative or $admin) and !$nohour) { $h = substr($posted_date, 10); } else { $h = ''; } switch ($date_format) { case 'dd/mm/yyyy': return substr($posted_date, 8, 2) . '/' . substr($posted_date, 5, 2) . '/' . substr($posted_date, 0, 4) . $h; break; case 'mm/dd/yyyy': return substr($posted_date, 5, 2) . '/' . substr($posted_date, 8, 2) . '/' . substr($posted_date, 0, 4) . $h; break; case 'yyyy/mm/dd': default: return substr($posted_date, 0, 4) . '/' . substr($posted_date, 5, 2) . '/' . substr($posted_date, 8, 2) . $h; break; } } else { if ($weeks > 0) { // weeks and days $relative_date .= ($relative_date ? ', ' : '') . $weeks . ' ' . ($weeks > 1 ? __('weeks', 'wp-activity') : __('week', 'wp-activity')); $relative_date .= $days > 0 ? ($relative_date ? ', ' : '') . $days . ' ' . ($days > 1 ? __('days', 'wp-activity') : __('day', 'wp-activity')) : ''; } elseif ($days > 0) { // days and hours $relative_date .= ($relative_date ? ', ' : '') . $days . ' ' . ($days > 1 ? __('days', 'wp-activity') : __('day', 'wp-activity')); $relative_date .= $hours > 0 ? ($relative_date ? ', ' : '') . $hours . ' ' . ($hours > 1 ? __('hours', 'wp-activity') : __('hour', 'wp-activity')) : ''; } elseif ($hours > 0) { // hours and minutes $relative_date .= ($relative_date ? ', ' : '') . $hours . ' ' . ($hours > 1 ? __('hours', 'wp-activity') : __('hour', 'wp-activity')); $relative_date .= $minutes > 0 ? ($relative_date ? ', ' : '') . $minutes . ' ' . ($minutes > 1 ? __('minutes', 'wp-activity') : __('minute', 'wp-activity')) : ''; } elseif ($minutes > 0) { // minutes only $relative_date .= ($relative_date ? ', ' : '') . $minutes . ' ' . ($minutes > 1 ? __('minutes', 'wp-activity') : __('minute', 'wp-activity')); } else { // seconds only $relative_date .= ($relative_date ? ', ' : '') . $seconds . ' ' . ($seconds > 1 ? __('seconds', 'wp-activity') : __('second', 'wp-activity')); } } // show relative date and add proper verbiage return sprintf(__('%s ago', 'wp-activity'), $relative_date); }
function getNHStateData($stn = 'PLYMOUTH ARPRT') { $apline = -1; $infile = file("/web/temp/obs.txt"); if ($infile) { foreach ($infile as $ob) { if (!stristr($ob, 'NEW HAMPSHIRE OBSERVATIONS') === FALSE) { $timeline = $ob; preg_match('/OBSERVATIONS for (.*)/', $ob, $matches); $airport_data['observation_time'] = $matches[1]; } if (!stristr($ob, $stn) === FALSE) { $apline = $ob; break; } } } if (($stn = 'PLYMOUTH ARPRT') && $apline == -1) { $stn = 'PLYMOUTH STATE'; foreach ($infile as $ob) { if (!stristr($ob, 'KPLY') === FALSE) { // Can't use Plymouth State as it is in the header $apline = $ob; break; } } } $airport_data['location'] = $stn == 'PLYMOUTH ARPRT' ? "Plymouth Airport" : ucwords($stn); $airport_data['location'] = $stn == 'PLYMOUTH STATE' ? "Plymouth State" : ucwords($stn); $airport_data['temp_f'] = trim(substr($apline, 17, 3)); $airport_data['relative_humidity'] = trim(substr($apline, 25, 3)); $airport_data['dewpoint_f'] = trim(substr($apline, 21, 3)); $airport_data['wind_degrees'] = trim(substr($apline, 29, 3)); $airport_data['wind_dir_abbrev'] = $this->get_wind_dir_abbrev($airport_data['wind_degrees']); $airport_data['latitude'] = 43.77; $airport_data['longitude'] = -71.75; $airport_data['tzoffset'] = date_offset_get(new DateTime()) / 3600 * 100; $airport_data['sunrise'] = $this->get_sundata("sunrise", $airport_data['latitude'], $airport_data['longitude'], $airport_data['tzoffset']); $airport_data['sunset'] = $this->get_sundata("sunset", $airport_data['latitude'], $airport_data['longitude'], $airport_data['tzoffset']); $airport_data['wind_mph'] = trim(substr($apline, 37, 2)); $airport_data['new_wind_chill'] = $this->get_new_wind_chill($airport_data['temp_f'], $airport_data['wind_mph']); $airport_data['new_heat_index'] = $this->get_new_heat_index($airport_data['temp_f'], $airport_data['relative_humidity']); $airport_data['sky'] = trim(substr($apline, 66, 3)); $airport_data['precip'] = trim(substr($apline, 69, 4)); if (strlen($airport_data['precip']) > 0) { if (preg_match('/R/', $airport_data['precip'])) { $airport_data['weather'] = "rain"; } else { if (preg_match('/S/', $airport_data['precip'])) { $airport_data['weather'] = "snow"; } else { if (preg_match('/H/', $airport_data['precip'])) { $airport_data['weather'] = "haze"; } else { if (preg_match('/F/', $airport_data['precip'])) { $airport_data['weather'] = "fog"; } else { if (preg_match('/L/', $airport_data['precip'])) { $airport_data['weather'] = "drizzle"; } } } } } if (preg_match('/-/', $airport_data['precip'])) { $airport_data['weather'] = "Lt. " . $airport_data['weather']; } else { if (preg_match('/\\+/', $data['precip'])) { $airport_data['weather'] = "Hvy. " . $airport_data['weather']; } } $airport_data['wximg'] = $this->get_wximage('ob', $airport_data['weather'], $airport_data['latitude'], $airport_data['longitude'], true); } else { if (preg_match('/CLR/', $data['sky'])) { $data['weather'] = "clear"; } else { if (preg_match('/FEW/', $airport_data['sky'])) { $airport_data['weather'] = "fair"; } else { if (preg_match('/SCT/', $airport_data['sky'])) { $airport_data['weather'] = "partly cloudy"; } else { if (preg_match('/BKN/', $airport_data['sky'])) { $airport_data['weather'] = "mostly cloudy"; } else { if (preg_match('/OVC/', $airport_data['sky'])) { $airport_data['weather'] = "overcast"; } else { if (preg_match('/X/', $airport_data['sky'])) { $airport_data['weather'] = "obscur"; } } } } } } $airport_data['wximg'] = $this->get_wximage('ob', $airport_data['weather'], $airport_data['latitude'], $airport_data['longitude'], false); } return $airport_data; }
{ var_dump(date_format($dt, "Y-m-d H:i:s")); } format(date_create("2006-12-12"), "2006-12-12 00:00:00"); format(date_create("@1170288001"), "2007-02-01 00:00:01"); $dt = date_create("2006-12-12 12:34:56"); date_date_set($dt, 2007, 11, 23); format($dt); $dt = date_create("2008-08-08 00:00:00"); date_isodate_set($dt, 2007, 35, 3); format($dt); $dt = date_create("2006-12-12 00:00:00"); date_modify($dt, "+1 day"); format($dt); var_dump(date_offset_get(date_create("2006-12-12"))); var_dump(date_offset_get(date_create("2008-08-08"))); $dt = date_create("2006-12-12 12:34:56"); date_time_set($dt, 23, 45, 12); format($dt); $d = strtotime("2008-09-10 12:34:56"); var_dump(date("l", $d)); var_dump(date("l jS \\of F Y h:i:s A", $d)); var_dump(date("l", mktime(0, 0, 0, 7, 1, 2000))); var_dump(date(DATE_RFC822, $d)); var_dump(date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000))); var_dump(date("l \\t\\h\\e jS", $d)); $tomorrow = mktime(0, 0, 0, (int) date("m", $d), (int) date("d", $d) + 1, (int) date("Y", $d)); var_dump($tomorrow); $lastmonth = mktime(0, 0, 0, (int) date("m", $d) - 1, (int) date("d", $d), (int) date("Y", $d)); var_dump($lastmonth); $nextyear = mktime(0, 0, 0, (int) date("m", $d), (int) date("d", $d), (int) date("Y", $d) + 1);
/** * Convert a date string into a Unix timestamp. * Interpreteting the date string in GMT context (instead of the time zone currently * set with date_default_timezone_set in ./inc/init.php) * * Be careful not to use this function when working with non-dates * such as "1 minute ago". Those must be passed to strtotime() directly, otherwise offset * will be incorrectly offset applied. gmstrototime() is only to be used on actual dates * such as "2012-01-01 15:45:01". * * @since 1.0.0 * @source php.net/strtotime#107773 * * @param $time string * @param $now int * @return int Timestamp */ function gmstrtotime($time, $now = null) { static $utc_offset = null; if ($utc_offset === null) { $utc_offset = date_offset_get(new DateTime()); } if ($now === null) { $loctime = strtotime($time); } else { $loctime = strtotime($time, $now); } return $loctime + $utc_offset; }
var_dump(timezone_name_get(date_timezone_get($dt))); var_dump(date_format($dt, 'Y-m-d H:i:s')); var_dump(timezone_name_from_abbr("CET")); var_dump(timezone_name_from_abbr("", 3600, 0)); $tz = timezone_open("Asia/Shanghai"); var_dump(timezone_name_get($tz)); // Create two timezone objects, one for Taipei (Taiwan) and one for // Tokyo (Japan) $dateTimeZoneTaipei = timezone_open("Asia/Taipei"); $dateTimeZoneJapan = timezone_open("Asia/Tokyo"); // Create two DateTime objects that will contain the same Unix timestamp, but // have different timezones attached to them. $dateTimeTaipei = date_create("2008-08-08", $dateTimeZoneTaipei); $dateTimeJapan = date_create("2008-08-08", $dateTimeZoneJapan); var_dump(date_offset_get($dateTimeTaipei)); var_dump(date_offset_get($dateTimeJapan)); $tz = timezone_open("Asia/Shanghai"); var_dump(timezone_name_get($tz)); $timezone = timezone_open("CET"); $transitions = timezone_transitions_get($timezone); var_dump($transitions[0]['ts']); var_dump($transitions[0]['offset']); var_dump($transitions[0]['isdst']); var_dump($transitions[0]['abbr']); $tz = timezone_open("EDT"); var_dump(timezone_name_get($tz)); $tz = timezone_open("PST"); var_dump(timezone_name_get($tz)); $tz = timezone_open("CHAST"); var_dump(timezone_name_get($tz)); var_dump((bool) timezone_version_get());
/** * pass this a zone, and it passes back the seconds offset for the current time in that zone. */ function timezone_offset($zone) { if (function_exists('date_offset_get') and function_exists('date_create') and function_exists('timezone_open')) { $offset = date_offset_get(date_create("now", timezone_open($zone))); } else { $old_tz = getenv('TZ'); putenv("TZ={$zone}"); $offset = date('Z', time()); putenv("TZ={$old_tz}"); } return $offset; }
$majorTicks = $majorTicks * 1000; $minorTicks = $majorTicks / 4; $page = 0; $g_canvas->header_left_text = $g_label; $time = $_REQUEST["time"]; if (!$time) { if ($g_is_watchdog) { $time = $g_server->StartTime->getTime() / 1000; } else { $time = time() + 5; } } $g_end = $time; $g_end_unadjusted = $g_end; if (2 * DAY <= $period) { $tz = date_offset_get(new DateTime()); $ticks_sec = $majorTicks / 1000; $g_end = ceil(($g_end + $tz) / $ticks_sec) * $ticks_sec - $tz; } $g_start = $g_end - $period; $g_canvas->footer_left_text = date("Y-m-d H:i", $g_end); $g_canvas->footer_right_text = date("Y-m-d H:i", $g_end); $jmx_dump = pdf_load_json_dump("Resin|JmxDump", $g_start, $g_end); if (!$jmx_dump) { // a JMX dump was not found, try to find an older one $jmx_dump = pdf_load_json_dump("Resin|JmxDump"); if ($jmx_dump) { $timestamp = $jmx_dump["timestamp"] / 1000; array_push($g_pdf_warnings, "A saved JMX snapshot not was found in the selected data range."); array_push($g_pdf_warnings, "Using an earlier JMX snapshot from " . date("Y-m-d H:i", $timestamp)); }
/** * Mostly borrowed from phpBB 3.1 includes/functions.php/phpbb_timezone_select() * To have it available for 3.0.x too. * * Options to pick a timezone and date/time * * @param \phpbb\template\template $template phpBB template object * @param \phpbb\user $user Object of the current user * @param string $default A timezone to select * @param boolean $truncate Shall we truncate the options text * * @return array Returns an array containing the options for the time selector. */ function qi_timezone_select($user, $default = '', $truncate = false) { date_default_timezone_set('UTC'); $unsorted_timezones = DateTimeZone::listIdentifiers(); $timezones = array(); foreach ($unsorted_timezones as $timezone) { $tz = date_create(date('d M Y, H:i'), timezone_open($timezone)); $offset = date_offset_get($tz); $current_time = date('d M Y, H:i', time() + $offset); $offset_string = qi_format_timezone_offset($offset, true); $timezones['UTC' . $offset_string . ' - ' . $timezone] = array('tz' => $timezone, 'offset' => $offset_string, 'current' => $current_time); if ($timezone === $default) { $default_offset = 'UTC' . $offset_string; } } unset($unsorted_timezones); uksort($timezones, 'qi_tz_select_compare'); $tz_select = $opt_group = ''; foreach ($timezones as $key => $timezone) { if ($opt_group != $timezone['offset']) { // Generate tz_select for backwards compatibility $tz_select .= $opt_group ? '</optgroup>' : ''; $tz_select .= '<optgroup label="' . $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $timezone['current']) . '">'; $opt_group = $timezone['offset']; } $label = $timezone['tz']; if (isset($user->lang['timezones'][$label])) { $label = $user->lang['timezones'][$label]; } $title = $user->lang(array('timezones', 'UTC_OFFSET_CURRENT'), $timezone['offset'], $label); if ($truncate) { $label = truncate_string($label, 50, 255, false, '...'); } // Also generate timezone_select for backwards compatibility $selected = $timezone['tz'] === $default ? ' selected="selected"' : ''; $tz_select .= '<option title="' . $title . '" value="' . $timezone['tz'] . '"' . $selected . '>' . $label . '</option>'; } $tz_select .= '</optgroup>'; return $tz_select; }
<?php echo $user->username; ?> </a> <? else : ?> <?php echo $user->username; ?> <? endif; ?> </td> <td> <?php echo $user->group_name; ?> </td> <td> <?php echo JApplicationHelper::getClientInfo($user->loggedin_client_id)->name; ?> </td> <td> <?php echo @helper('com://admin/users.template.helper.date.humanize', array('date' => $user->loggedin_on - date_offset_get(new DateTime()))); ?> </td> </tr> <?php } ?> </tbody> </table>
/** * Return timezone offset for the date being processed. */ function get_offset($comp_date = NULL) { if (!empty($this->db_timezone) && !empty($this->local_timezone)) { if ($this->db_timezone != $this->local_timezone) { if (empty($comp_date)) { $comp_date = new DrupalDateTime('now', $this->db_timezone); } $comp_date->setTimezone(timezone_open($this->local_timezone)); return date_offset_get($comp_date); } } return 0; }
$yc = $yakcatColl->findOne(array('_id' => new MongoId($id))); if (!empty($yc)) { $yakCatId[] = new MongoId($yc['_id']); $yakCatName[] = $yc['title']; } } /* EVENT DATE */ $eventDate = array(); $i = 0; foreach ($eventDateInput as $date) { $fixedDate = str_replace('.0Z', 'Z', $date[0]); $dateTimeFrom = DateTime::createFromFormat(DateTime::ISO8601, $fixedDate); $eventDate[$i]['dateTimeFrom'] = new MongoDate($dateTimeFrom->gettimestamp() - date_offset_get($dateTimeFrom)); $fixedDate = str_replace('.0Z', 'Z', $date[1]); $dateTimeEnd = DateTime::createFromFormat(DateTime::ISO8601, $fixedDate); $eventDate[$i]['dateTimeEnd'] = new MongoDate(date_timestamp_get($dateTimeEnd) - date_offset_get($dateTimeEnd)); $i++; } // clean duplicates cats and tags $freeTag = array_unique($freeTag); $yakCatName = array_unique($yakCatName); $yakCatId = array_unique($yakCatId); if (sizeof($freeTag) > 0) { $freeTag = array_diff($freeTag, $yakCatName); } $freeTag = (array) $freeTag; $freeTagNew = array_values($freeTag); $freeTag = $freeTagNew; $freeTagClean = array(); echo '<br> DEBUG-----<br>'; foreach ($freeTag as $t) {
<?php /* Prototype : int date_offset_get ( DateTime $object ) * Description: Returns the daylight saving time offset * Source code: ext/date/php_date.c * Alias to functions: DateTime::getOffset */ //Set the default time zone date_default_timezone_set('Europe/London'); echo "*** Testing date_offset_get() : basic functionality ***\n"; $winter = date_create('2008-12-25 14:25:41'); $summer = date_create('2008-07-02 14:25:41'); echo "Winter offset: " . date_offset_get($winter) / 3600 . " hours\n"; echo "Summer offset: " . date_offset_get($summer) / 3600 . " hours\n"; ?> ===DONE===
<?php /* Prototype : int date_offset_get ( DateTimeInterface $object ) * Description: Returns the daylight saving time offset * Source code: ext/date/php_date.c * Alias to functions: DateTimeInterface::getOffset */ //Set the default time zone date_default_timezone_set("Europe/London"); echo "*** Testing date_offset_get() : error conditions ***\n"; echo "\n-- Testing date_offset_get() function with zero arguments --\n"; var_dump(date_offset_get()); echo "\n-- Testing date_offset_get() function with more than expected no. of arguments --\n"; $datetime = date_create("2009-01-30 19:34:10"); $extra_arg = 30; var_dump(date_offset_get($datetime, $extra_arg)); echo "\n-- Testing date_offset_get() function with an invalid values for \$object argument --\n"; $invalid_obj = new stdClass(); var_dump(date_offset_get($invalid_obj)); $invalid_obj = 10; var_dump(date_offset_get($invalid_obj)); $invalid_obj = null; var_dump(date_offset_get($invalid_obj)); ?> ===DONE===
protected function getDateTime($datetime) { try { $offset = date_offset_get(new DateTime($datetime)); } catch (Exception $e) { try { $datetime = strstr($datetime, " (", true); $offset = date_offset_get(new DateTime($datetime)); } catch (Exception $e) { $datetime = date('D, M d, Y h:i a'); $offset = date_offset_get(new DateTime($datetime)); } } if (!$this->daylight_saving(strtotime($datetime))) { } $offset += 3600; return $date = date('D, M d, Y h:i a', strtotime($datetime) - $offset); }
/** * Creates the block's main content * * @return string */ public function get_content() { global $USER, $OUTPUT, $CFG; if (isset($this->content)) { return $this->content; } // Establish settings variables based on instance config. $showserverclock = !isset($this->config->show_clocks) || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_BOTH || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_SERVER_ONLY; $showuserclock = !isset($this->config->show_clocks) || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_BOTH || $this->config->show_clocks == B_SIMPLE_CLOCK_SHOW_USER_ONLY; $showicons = !isset($this->config->show_icons) || $this->config->show_icons == 1; $showseconds = isset($this->config->show_seconds) && $this->config->show_seconds == 1; $showday = isset($this->config->show_day) && $this->config->show_day == 1; $show24hrtime = isset($this->config->twenty_four_hour_time) && $this->config->twenty_four_hour_time == 1; // Start the content, which is primarily a table. $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $table = new html_table(); $table->attributes = array('class' => 'clockTable'); // First item added is the server's clock. if ($showserverclock) { $row = array(); if ($showicons) { $alt = get_string('server', 'block_simple_clock'); $usingie = false; if (class_exists('core_useragent')) { $usingie = core_useragent::is_ie(); } else { $usingie = check_browser_version('MSIE'); } if ($usingie) { $servericon = $OUTPUT->pix_icon('server', $alt, 'block_simple_clock'); } else { $servericon = $OUTPUT->pix_icon('favicon', $alt, 'theme'); } $row[] = $servericon; } $row[] = get_string('server', 'block_simple_clock') . ':'; $attributes = array(); $attributes['class'] = 'clock'; $attributes['id'] = 'block_progress_serverTime'; $attributes['value'] = get_string('loading', 'block_simple_clock'); $row[] = HTML_WRITER::empty_tag('input', $attributes); $table->data[] = $row; } // Next item is the user's clock. if ($showuserclock) { $row = array(); if ($showicons) { if ($USER->id != 0) { $userpictureparams = array('size' => 16, 'link' => false, 'alt' => 'User'); $userpicture = $OUTPUT->user_picture($USER, $userpictureparams); $row[] = $userpicture; } else { $row[] = ''; } } $row[] = get_string('you', 'block_simple_clock') . ':'; $attributes = array(); $attributes['class'] = 'clock'; $attributes['id'] = 'block_progress_youTime'; $attributes['value'] = get_string('loading', 'block_simple_clock'); $row[] = HTML_WRITER::empty_tag('input', $attributes); $table->data[] = $row; } $this->content->text .= HTML_WRITER::table($table); // Set up JavaScript code needed to keep the clock going. $noscriptstring = get_string('javascript_disabled', 'block_simple_clock'); $this->content->text .= HTML_WRITER::tag('noscript', $noscriptstring); if ($CFG->timezone != 99) { // Ensure that the Moodle timezone is set correctly. $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($CFG->timezone))); $moodletimeoffset = $date->getOffset(); // + dst_offset_on(time(), $CFG->timezone); $servertimeoffset = date_offset_get(new DateTime()); $timearray = localtime(time() + $moodletimeoffset - $servertimeoffset, true); } else { // Ensure that the server timezone is set. // From 2.9 onwards, this should never happen. $timearray = localtime(time(), true); } $arguments = array($showserverclock, $showuserclock, $showseconds, $showday, $show24hrtime, $timearray['tm_year'] + 1900, $timearray['tm_mon'], $timearray['tm_mday'], $timearray['tm_hour'], $timearray['tm_min'], $timearray['tm_sec'] + 2); $jsmodule = array('name' => 'block_simple_clock', 'fullpath' => '/blocks/simple_clock/module.js', 'requires' => array(), 'strings' => array(array('clock_separator', 'block_simple_clock'), array('before_noon', 'block_simple_clock'), array('after_noon', 'block_simple_clock'), array('day_names', 'block_simple_clock'))); $this->page->requires->js_init_call('M.block_simple_clock.initSimpleClock', $arguments, false, $jsmodule); $this->content->footer = ''; return $this->content; }
?> </div> <div id="productSignature"> <?php echo product_signature(); ?> <span id="request_duration"><?php printf(' in %.3f seconds', microtime(true) - $GLOBALS['request_start_time']); ?> </span> <span id="current_datetime"><?php echo date('c/I[W]'); ?> </span> <span id="user_current_datetime"><?php $seconds = date_offset_get(new DateTime()); echo $seconds / 3600; echo ' ' . logged_user()->getTimezone(); ?> </span> </div> </div> </div> <!-- /content wrapper --> </div> <?php trace(__FILE__, 'body end'); ?> </body> </html>
/** * Reworked from Drupal's format_date function to handle pre-1970 and * post-2038 dates and accept a date object instead of a timestamp as input. * * Translates formatted date results, unlike PHP function date_format(). * Should only be used for display, not input, because it can't be parsed. * * @param $oject * A date object. * @param $type * The format to use. Can be "small", "medium" or "large" for the preconfigured * date formats. If "custom" is specified, then $format is required as well. * @param $format * A PHP date format string as required by date(). A backslash should be used * before a character to avoid interpreting the character as part of a date * format. * @return * A translated date string in the requested format. */ function date_format_date($date, $type = 'medium', $format = '', $langcode = NULL) { if (empty($date)) { return ''; } switch ($type) { case 'small': case 'short': $format = variable_get('date_format_short', 'm/d/Y - H:i'); break; case 'large': case 'long': $format = variable_get('date_format_long', 'l, F j, Y - H:i'); break; case 'custom': $format = $format; break; case 'medium': default: $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); } $format = date_limit_format($format, $date->granularity); $max = strlen($format); $datestring = ''; for ($i = 0; $i < $max; $i++) { $c = $format[$i]; switch ($c) { case 'l': $datestring .= t($date->format('l'), array(), array('context' => '', 'langcode' => $langcode)); break; case 'D': $datestring .= t($date->format('D'), array(), array('context' => '', 'langcode' => $langcode)); break; case 'F': $datestring .= t($date->format('F'), array(), array('context' => 'Long month name', 'langcode' => $langcode)); break; case 'M': $datestring .= t($date->format('M'), array(), array('context' => 'month_abbr', 'langcode' => $langcode)); break; case 'A': case 'a': $datestring .= t($date->format($c), array(), array('context' => 'ampm', 'langcode' => $langcode)); break; // The timezone name translations can use t(). // The timezone name translations can use t(). case 'e': case 'T': $datestring .= t($date->format($c)); break; // Remaining date parts need no translation. // Remaining date parts need no translation. case 'O': $datestring .= sprintf('%s%02d%02d', date_offset_get($date) < 0 ? '-' : '+', abs(date_offset_get($date) / 3600), abs(date_offset_get($date) % 3600) / 60); break; case 'P': $datestring .= sprintf('%s%02d:%02d', date_offset_get($date) < 0 ? '-' : '+', abs(date_offset_get($date) / 3600), abs(date_offset_get($date) % 3600) / 60); break; case 'Z': $datestring .= date_offset_get($date); break; case '\\': $datestring .= $format[++$i]; break; case 'r': $datestring .= date_format_date($date, 'custom', 'D, d M Y H:i:s O', $langcode); break; default: if (strpos('BdcgGhHiIjLmnNosStTuUwWYyz', $c) !== FALSE) { $datestring .= $date->format($c); } else { $datestring .= $c; } } } return $datestring; }
function dir_events_query($method_name, $params, $app_data) { $req = $params[0]; $text = $req['text']; $flags = $req['flags']; $query_start = $req['query_start']; if ($text == "%%%") { $response_xml = xmlrpc_encode(array('success' => False, 'errorMessage' => "Invalid search terms")); print $response_xml; return; } $pieces = explode("|", $text); $day = $pieces[0]; $category = $pieces[1]; if (count($pieces) < 3) { $search_text = ""; } else { $search_text = $pieces[2]; } //Get todays date/time and adjust it to UTC $now = time() - date_offset_get(new DateTime()); $terms = array(); if ($day == "u") { $terms[] = "dateUTC > " . $now; } else { //Is $day a number of days before or after current date? if ($day != 0) { $now += $day * 86400; } $now -= $now % 86400; $then = $now + 86400; $terms[] = "(dateUTC > " . $now . " AND dateUTC <= " . $then . ")"; } if ($category != 0) { $terms[] = "category = " . $category . ""; } $type = array(); if ($flags & 16777216) { //IncludePG (1 << 24) $type[] = "eventflags = 0"; } if ($flags & 33554432) { //IncludeMature (1 << 25) $type[] = "eventflags = 1"; } if ($flags & 67108864) { //IncludeAdult (1 << 26) $type[] = "eventflags = 2"; } //Was there at least one PG, Mature, or Adult flag? if (count($type) > 0) { $terms[] = join_terms(" OR ", $type, True); } if ($search_text != "") { $search_text = mysql_real_escape_string($search_text); $terms[] = "(name LIKE '%{$search_text}%' OR " . "description LIKE '%{$search_text}%')"; } if (count($terms) > 0) { $where = " WHERE " . join_terms(" AND ", $terms, False); } else { $where = ""; } $sql = "SELECT * FROM events" . $where . " LIMIT " . mysql_real_escape_string($query_start) . ",101"; $result = mysql_query($sql); $data = array(); while ($row = mysql_fetch_assoc($result)) { $date = strftime("%m/%d %I:%M %p", $row["dateUTC"]); $data[] = array("owner_id" => $row["owneruuid"], "name" => $row["name"], "event_id" => $row["eventid"], "date" => $date, "unix_time" => $row["dateUTC"], "event_flags" => $row["eventflags"], "landing_point" => $row["globalPos"], "region_UUID" => $row["simname"]); } $response_xml = xmlrpc_encode(array('success' => True, 'errorMessage' => "", 'data' => $data)); print $response_xml; }
foreach (Tree::getAll() as $WT_TREE) { break; } } // With no parameters, init() looks to the environment to choose a language define('WT_LOCALE', I18N::init()); Session::put('locale', WT_LOCALE); // Note that the database/webservers may not be synchronised, so use DB time throughout. define('WT_TIMESTAMP', (int) Database::prepare("SELECT UNIX_TIMESTAMP()")->fetchOne()); // Users get their own time-zone. Visitors get the site time-zone. if (Auth::check()) { date_default_timezone_set(Auth::user()->getPreference('TIMEZONE', 'UTC')); } else { date_default_timezone_set(Site::getPreference('TIMEZONE') ?: 'UTC'); } define('WT_TIMESTAMP_OFFSET', date_offset_get(new \DateTime('now'))); define('WT_CLIENT_JD', 2440588 + (int) ((WT_TIMESTAMP + WT_TIMESTAMP_OFFSET) / 86400)); // The login URL must be an absolute URL, and can be user-defined if (Site::getPreference('LOGIN_URL')) { define('WT_LOGIN_URL', Site::getPreference('LOGIN_URL')); } else { define('WT_LOGIN_URL', WT_BASE_URL . 'login.php'); } // If there is no current tree and we need one, then redirect somewhere if (WT_SCRIPT_NAME != 'admin_trees_manage.php' && WT_SCRIPT_NAME != 'admin_pgv_to_wt.php' && WT_SCRIPT_NAME != 'login.php' && WT_SCRIPT_NAME != 'logout.php' && WT_SCRIPT_NAME != 'import.php' && WT_SCRIPT_NAME != 'help_text.php' && WT_SCRIPT_NAME != 'message.php' && WT_SCRIPT_NAME != 'action.php') { if (!$WT_TREE || !$WT_TREE->getPreference('imported')) { if (Auth::isAdmin()) { header('Location: ' . WT_BASE_URL . 'admin_trees_manage.php'); } else { header('Location: ' . WT_LOGIN_URL . '?url=' . rawurlencode(WT_SCRIPT_NAME . (isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '')), true, 301); }
function getTimeOffset() { global $schedulePars; if (is_numeric($schedulePars[SCHEDULE_GMTOFFSET])) { $offset = $schedulePars[SCHEDULE_GMTOFFSET]; } else { date_default_timezone_set($schedulePars[SCHEDULE_GMTOFFSET]); $offset = date_offset_get(new DateTime("now")) / 3600; } return $offset; }
function prepare_configs($phone_info) { //$endpoint = Doctrine::getTable('Endpoint')->findOneByMac($mac_address); //if (!$endpoint) { // // TODO: Add code to automatically add a new device here, detecting it's model, family and brand based on it's // // UID //} /*$model = $endpoint->EndpointModel; $family = $model->EndpointBrand; $brand = $model->EndpointBrand;*/ // Replace all bogus data below with $endpointdevice['XXX'] from plugins field of basemodel $model = array('name' => $phone_info['model']); $family = array('name' => $phone_info['family']); $brand = array('name' => $phone_info['brand']); $phone_info['directory'] = $phone_info['brand']; $phone_info['cfg_dir'] = $phone_info['family']; $class = "endpoint_" . $brand['name'] . "_" . $family['name'] . '_phone'; $provisioner_lib = new $class(); //have to because of versions less than php5.3 $provisioner_lib->brand_name = $brand['name']; $provisioner_lib->family_line = $family['name']; //Mac Address $provisioner_lib->mac = $phone_info['mac']; //Phone Model (Please reference family_data.xml in the family directory for a list of recognized models) $provisioner_lib->model = $model['name']; //Timezone $provisioner_lib->timezone = date_offset_get(new DateTime()); //Server IP if (isset($phone_info['host'])) { $provisioner_lib->server[1]['ip'] = $phone_info['host']; } else { $provisioner_lib->server[1]['ip'] = $_SERVER["SERVER_ADDR"]; } if (isset($phone_info['port'])) { $provisioner_lib->server[1]['port'] = $phone_info['port']; } else { $provisioner_lib->server[1]['port'] = 5060; } $provisioner_lib->options = $phone_info['options']; //Provide alternate Configuration file instead of the one from the hard drive //$endpoint->config_files_override['$mac.cfg'] = "{\$srvip}\n{\$admin_pass|0}\n{\$test.line.1}"; //Pretend we have three lines, we could just have one line or 20...whatever the phone supports foreach ($phone_info['line'] as $line) { $provisioner_lib->lines[$line['line']] = array('ext' => $line['ext'], 'secret' => $line['secret'], 'displayname' => $line['description'], 'options' => $line['options']); } $provisioner_lib->root_dir = MODPATH . 'endpointmanager-1.1' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR; $provisioner_lib->processor_info = 'Endpoint Manager 1.1 for Blue.Box'; //Set Variables according to the template_data files included. We can include different template.xml files within family_data.xml also one can create //template_data_custom.xml which will get included or template_data_<model_name>_custom.xml which will also get included //line 'global' will set variables that aren't line dependant //$endpoint->options = array("admin_pass" => "password","main_icon" => "Main ICON Line #3"); //Setting a line variable here...these aren't defined in the template_data.xml file yet. however they will still be parsed //and if they have defaults assigned in a future template_data.xml or in the config file using pipes (|) those will be used, pipes take precedence // Because every brand is an extension (eventually) of endpoint, you know this function will exist regardless of who it is $data = $provisioner_lib->generate_config(); //Start timer $time_start = microtime(true); $returned_data = $provisioner_lib->generate_config(); //End timer $time_end = microtime(true); $time = $time_end - $time_start; if ($time > 360) { $this->error['generate_time'] = "It's taking a awfully long time to generate configs...(" . round($time, 2) . " seconds)"; } //Create Directory Structure (If needed) if (isset($provisioner_lib->directory_structure)) { foreach ($provisioner_lib->directory_structure as $data) { $dir = $this->global_cfg['config_location'] . $data; if (!file_exists($dir)) { mkdir($dir, 0777); } } } //Copy Files/Directories (If needed) if (isset($provisioner_lib->copy_files)) { foreach ($provisioner_lib->copy_files as $data) { if (file_exists($this->global_cfg['config_location'] . $data) and !in_array($data, $provisioner_lib->protected_files) or !file_exists($this->global_cfg['config_location'] . $data)) { if (is_dir(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data)) { if (!file_exists($this->global_cfg['config_location'] . $data)) { if (!@mkdir($this->global_cfg['config_location'] . $data, 0777)) { $this->error['parse_configs'] = "Could Not Create Directory: " . $data; } } $dir_iterator = new RecursiveDirectoryIterator(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data . "/"); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); // could use CHILD_FIRST if you so wish foreach ($iterator as $file) { if (is_dir($file)) { $dir = str_replace(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data . "/", "", $file); if (!file_exists($this->global_cfg['config_location'] . $data . "/" . $dir)) { if (!@mkdir($this->global_cfg['config_location'] . $data . "/" . $dir, 0777)) { $this->error['parse_configs'] = "Could Not Create Directory: " . $data . "/" . $dir; } } } else { $dir = str_replace(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data . "/", "", $file); if (!@copy($file, $this->global_cfg['config_location'] . $data . "/" . $dir)) { $this->error['parse_configs'] = "Could Not Copy File: " . $data . "/" . $dir; } else { chmod($this->global_cfg['config_location'] . $data . "/" . $dir, 0777); } } } } else { copy(PHONE_MODULES_PATH . "endpoint/" . $phone_info['directory'] . "/" . $phone_info['cfg_dir'] . "/" . $data, $this->global_cfg['config_location'] . $data); chmod($this->global_cfg['config_location'] . $data, 0777); } } } } //Generate Files foreach ($returned_data as $key => $data) { if (file_exists($this->global_cfg['config_location'] . $key) and !in_array($key, $provisioner_lib->protected_files) or !file_exists($this->global_cfg['config_location'] . $key)) { $fp = fopen($this->global_cfg['config_location'] . $key, 'w'); fwrite($fp, $data); fclose($fp); if (!file_exists($this->global_cfg['config_location'] . $key)) { $this->error['parse_configs'] = "File not written to hard drive!"; } } } }
function form_fuseau_horaire($defaut) { if (version_compare(PHP_VERSION, '5.2.0', '>=')) { $all_timezones = timezone_identifiers_list(); $liste_fuseau = array(); $cities = array(); foreach ($all_timezones as $tz) { $spos = strpos($tz, '/'); if ($spos !== FALSE) { $continent = substr($tz, 0, $spos); $city = substr($tz, $spos + 1); $liste_fuseau[$continent][] = array('tz_name' => $tz, 'city' => $city); } if ($tz == 'UTC') { $liste_fuseau['UTC'][] = array('tz_name' => 'UTC', 'city' => 'UTC'); } } $form = '<label>' . $GLOBALS['lang']['pref_fuseau_horaire'] . '</label>' . "\n"; $form .= '<select name="fuseau_horaire">' . "\n"; foreach ($liste_fuseau as $continent => $zone) { $form .= "\t" . '<optgroup label="' . ucfirst(strtolower($continent)) . '">' . "\n"; foreach ($zone as $fuseau) { $form .= "\t\t" . '<option value="' . htmlentities($fuseau['tz_name']) . '"'; $form .= $defaut == $fuseau['tz_name'] ? ' selected="selected"' : ''; $timeoffset = date_offset_get(date_create('now', timezone_open($fuseau['tz_name']))); $formated_toffset = '(UTC' . ($timeoffset < 0 ? '–' : '+') . str2(floor(abs($timeoffset) / 3600)) . ':' . str2(floor(abs($timeoffset) % 3600 / 60)) . ') '; $form .= '>' . $formated_toffset . ' ' . htmlentities($fuseau['city']) . '</option>' . "\n"; } $form .= "\t" . '</optgroup>' . "\n"; } $form .= '</select>' . "\n"; return $form; } }
At sunrise, turn lighting off Crontab: * * * * * ~/lighting/sunset.php > /dev/null 2>&1 DMX Dimmer pack on channels 1,2,3,4 Ch.1 Tree Lantern Street Side Ch.2 Tree Lantern Driveway Side Ch.3 Walkway Far Ch.4 Walkway Near Uses "open lighting architecture" on raspberry pi http://opendmx.net/index.php/Open_Lighting_Architecture - Presence */ /* Figure out timezone offset, in hours, from GMT, watching for DST and standard time */ date_default_timezone_set('America/Los_Angeles'); $offset = date_offset_get(date_create(date('Y-m-d'), timezone_open('America/Los_Angeles'))) / 60 / 60; if (isset($argv[1])) { echo "offset: {$offset}\n"; echo date("D M d Y") . ', sunrise time : ' . date_sunrise(time(), SUNFUNCS_RET_STRING, 36.1215, -115.1739, 90, $offset) . "\n"; echo date("D M d Y") . ', sunset time : ' . date_sunset(time(), SUNFUNCS_RET_STRING, 36.1215, -115.1739, 90, $offset) . "\n"; } /* sunset in seconds */ $sunrise = strtotime(date_sunrise(time(), SUNFUNCS_RET_STRING, 36.1215, -115.1739, 90, $offset)); $sunset = strtotime(date_sunset(time(), SUNFUNCS_RET_STRING, 36.1215, -115.1739, 90, $offset)); $now = time(); if ($now >= $sunset && $now >= $sunrise) { echo "go sunset\n"; if (!isset($argv[1])) { system("/usr/local/bin/ola_streaming_client -u 1 -d 255,255,255,255"); } } elseif ($now <= $sunset && $now <= $sunrise) {
// define some classes class classWithToString { public function __toString() { return "Class A object"; } } class classWithoutToString { } // heredoc string $heredoc = <<<EOT hello world EOT; // add arrays $index_array = array(1, 2, 3); $assoc_array = array('one' => 1, 'two' => 2); // resource $file_handle = fopen(__FILE__, 'r'); //array of values to iterate over $inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource' => $file_handle); foreach ($inputs as $variation => $object) { echo "\n-- {$variation} --\n"; var_dump(date_offset_get($object)); } // closing the resource fclose($file_handle); ?> ===DONE===
<?php namespace B; date_offset_get(1); \date_modify(2); \A\date_parse_from_format(); // fall back system... Needs to be a undefined in \A space
/** * Constructor */ function timezone() { // are we riding a dinosaur? if (!timezone::is_supported()) { // Standard time zones as compiled by H.M. Nautical Almanac Office, June 2004 // http://aa.usno.navy.mil/faq/docs/world_tzones.html $timezones = array(-12, -11, -10, -9.5, -9, -8.5, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, +1, +2, +3, +3.5, +4, +4.5, +5, +5.5, +6, +6.5, +7, +8, +9, +9.5, +10, +10.5, +11, +11.5, +12, +13, +14); foreach ($timezones as $tz) { // Fake timezone id $timezone_id = 'GMT' . sprintf('%+05.1f', $tz); $sign = $tz >= 0 ? '+' : ''; $label = sprintf("GMT %s%02d:%02d", $sign, $tz, abs($tz - (int) $tz) * 60); $this->_details[$timezone_id]['continent'] = gTxt('timezone_gmt'); $this->_details[$timezone_id]['city'] = $label; $this->_details[$timezone_id]['offset'] = $tz * 3600; $this->_offsets[$tz * 3600] = $timezone_id; } } else { $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'); $server_tz = date_default_timezone_get(); $tzlist = timezone_abbreviations_list(); foreach ($tzlist as $abbr => $timezones) { foreach ($timezones as $tz) { $timezone_id = $tz['timezone_id']; // $timezone_ids are not unique among abbreviations if ($timezone_id && !isset($this->_details[$timezone_id])) { $parts = explode('/', $timezone_id); if (in_array($parts[0], $continents)) { if (!empty($server_tz)) { if (date_default_timezone_set($timezone_id)) { $is_dst = date('I', time()); } } $this->_details[$timezone_id]['continent'] = $parts[0]; $this->_details[$timezone_id]['city'] = isset($parts[1]) ? $parts[1] : ''; $this->_details[$timezone_id]['subcity'] = isset($parts[2]) ? $parts[2] : ''; $this->_details[$timezone_id]['offset'] = date_offset_get(date_create()) - ($is_dst ? 3600 : 0); $this->_details[$timezone_id]['dst'] = $tz['dst']; $this->_details[$timezone_id]['abbr'] = strtoupper($abbr); // Guesstimate a timezone key for a given GMT offset $this->_offsets[$tz['offset']] = $timezone_id; } } } } } if (!empty($server_tz)) { date_default_timezone_set($server_tz); } }
private function preparePost($args) { $blogId = (int) $args[0]; $username = $args[1]; $password = $args[2]; $user = $this->login($username, $password); if (!$user) { return $this->error; } $values = array(); $values['author'] = $user->getIdentity()->getId(); //$values['author'] = $user->getIdentity()->getName(); $values['title'] = $args[3]['title']; $values['content'] = $args[3]['description']; if (isset($args[3]['date_created_gmt'])) { $publish_time = $args[3]['date_created_gmt']; $timezone = new DateTimeZone((string) date_default_timezone_get()); $datetime = new DateTime('now', $timezone); $offset = date_offset_get($datetime); $values['publish_time'] = $publish_time->getTimestamp() + $offset; } $values['published'] = $args[4]; if (isset($args[3]['categories'][0])) { $category = $this->model('categories')->getByName($args[3]['categories'][0]); $values['category'] = (int) $category->id; } else { $values['category'] = 0; } $values['content_type'] = 'page'; return $values; }