function amr_newDateTime($text = '') { // create new datetime object with the global timezone // because wordpress insists that the php default must stay as UTC global $amr_globaltz; //$d = new DateTime($text,$amr_globaltz); $d = amr_create_date_time($text, $amr_globaltz); // traps exceptions return $d; }
function amr_create_date_from_parts($d, $tz) { /* create a date object from the parts array, with the TZ passed */ // wtf? new DateTime(); $datestring = $d['year'] . '-' . $d['month'] . '-' . $d['day'] . ' ' . $d['hour'] . ':' . $d['minute'] . ':' . $d['second']; $possdate = amr_create_date_time($datestring, $tz); //try { $possdate = new DateTime($datestring, $tz); // } //catch (Exception $e) { // echo '<b>'.__('Unexpected error creating date with string: '.$datestring,'amr-ical-events-list').'</b>'; // echo $e->getMessage(); // return (false); // } // somehow this exception business not helping? //if (isset($_GET['rdebug'])) { echo '<br />Datestring: '.$datestring.' as date: '.$possdate->format('c');} // if date does not match date string, then reject if ($d['day'] > 28) { //then check whther date was created correctly, or whether it should have been rejected. $newday = $possdate->format('j'); if (!($newday == $d['day'])) { if (isset($_GET['rdebug'])) { echo '<br />Rejecting...'; } return false; } } return $possdate; }
function amr_parseDate($text, $tzobj) { /* VALUE=DATE: 19970101,19970120,19970217,19970421 19970526,19970704,19970901,19971014,19971128,19971129,19971225 VALUE=DATE;TZID=/mozilla.org/20070129_1/Europe/Berlin:20061223 */ $p = explode(',', $text); /* if only a single will still return one array value */ foreach ($p as $i => $v) { $datestring = substr($v, 0, 4) . '-' . substr($v, 4, 2) . '-' . substr($v, 6, 2); $dates[] = amr_create_date_time($datestring, $tzobj); /*try { // $dates[] = new DateTime(substr($v,0, 4).'-'.substr($v,4, 2).'-'.substr($v,6, 2), $tzobj); //} //catch(Exception $e) { // echo '<br />Unable to create DateTime object from '.$text.' <br />'.$e->getMessage(); // return (false); }*/ } return $dates; }
function amr_check_timezonesettings() { global $amr_globaltz; echo '<ul>'; if (function_exists('timezone_version_get')) { printf('<li>' . __('Your timezone db version is: %s', 'amr-ical-events-list') . '</li>', timezone_version_get()); } else { echo '<li>' . '<a href="http://en.wikipedia.org/wiki/Tz_database">' . __('Plugin cannot determine timezonedb version in php < 5.3.', 'amr-ical-events-list') . '</a>'; } echo '</li></li><li><a href="http://pecl.php.net/package/timezonedb">'; _e('Php timezonedb versions', 'amr-ical-events-list'); echo '</a> <a href="http://pecl.php.net/package/timezonedb">'; _e('Info on what changes are in which timezonedb version', 'amr-ical-events-list'); echo '</a></li>'; if (!isset($amr_globaltz)) { echo '<b>' . __('No global timezone - is there a problem here? ', 'amr-ical-events-list') . '</b>'; return; } $tz = get_option('timezone_string'); $settingslink = '<a href="' . get_option('siteurl') . '/wp-admin/options-general.php">' . __('Go to settings', 'amr-ical-events-list') . '</a>'; if ($tz == '') { $gmtoffset = get_option('gmt_offset'); if (!empty($gmtoffset)) { printf('<li style="color: red;"><b>' . __('You are using the "old" gmt_offset setting ', 'amr-ical-events-list') . '</b></li><li>', $gmtoffset); _e('Consider changing to the more accurate timezone setting', 'amr-ical-events-list'); echo '</li>'; } } $now = date_create('now', $amr_globaltz); echo '<li>' . __('The plugin thinks your timezone is: ', 'amr-ical-events-list') . timezone_name_get($amr_globaltz) . ' ' . $settingslink . '</li>' . '<li>' . __('The current UTC offset for that timezone is: ', 'amr-ical-events-list') . $now->getoffset() / (60 * 60) . '</li>'; if (function_exists('timezone_transitions_get')) { foreach (timezone_transitions_get($amr_globaltz) as $tr) { if ($tr['ts'] > time()) { break; } } } $utctz = new DateTimeZone('UTC'); if (isset($tr['ts'])) { $d = amr_create_date_time("@{$tr['ts']}", $utctz); //try {$d = new DateTime( "@{$tr['ts']}",$utctz );} //catch(Exception $e) { break;} date_timezone_set($d, $amr_globaltz); printf('<li>' . __('Switches to %s on %s. GMT offset: %d', 'amr-ical-events-list') . '</li>', $tr['isdst'] ? "DST" : "standard time", $d->format('d M Y @ H:i'), $tr['offset'] / (60 * 60)); } echo '<li>'; _e('Current time (unlocalised): ', 'amr-ical-events-list'); echo $now->format('r'); echo '</li></ul>'; }