function amr_show_look_more() { global $amr_limits, $amr_options, $amr_formats, $amr_globaltz, $amr_last_date_time; $next = new datetime('', $amr_globaltz); if (!empty($amr_last_date_time)) { $next = clone $amr_last_date_time; // get last used event date } else { $amr_last_date_time = $amr_limits['end']; $next = $amr_limits['end']; } date_time_set($next, 0, 0, 0); // set to the beginning of the day $prev = $amr_limits['start']; $nexturl = add_query_arg('events', $amr_limits['events'] * 2); $prevurl = remove_query_arg('events'); // if no events, then this makes no sense $explaint = sprintf (__('Displaying %s events.'),$amr_limits['events']) ; $explaint = ''; // due to events limit, it may not show all events in a given day, so do not say displaying until date, // rather just start the next display from that last date - may be a few events that overlap. foreach ($amr_limits as $i => $value) { if (in_array($i, array('days', 'hours', 'months', 'weeks'))) { $nexturl = add_query_arg($i, $value, $nexturl); $prevurl = add_query_arg($i, $value, $prevurl); date_modify($prev, '-' . $value . ' ' . $i); // work back to the previous event } } $nextd = $next->format("Ymd"); $prevd = $prev->format("Ymd"); $nexturl = add_query_arg(array('start' => $nextd), $nexturl); $prevurl = add_query_arg(array('start' => $prevd), $prevurl); // NB MUST increase the number of events otherwise one can get caught in a situation where if num of events less than events in a day, one can never get past that day. if (empty($amr_options['lookmoremessage'])) { $moret = __('Look for more', 'amr-ical-events-list'); } else { /* translators: ignore, the text appears for translation eslewhere */ $moret = __($amr_options['lookmoremessage'], 'amr-ical-events-list'); } $morett = sprintf(__('Look for more from %s', 'amr-ical-events-list'), $amr_last_date_time->format($amr_formats['Day'])); if (!empty($_REQUEST['start'])) { if (empty($amr_options['lookprevmessage'])) { $prevt = ''; } else { /* translators: ignore, the text appears for translation eslewhere */ $prevt = __($amr_options['lookprevmessage'], 'amr-ical-events-list'); } if (empty($amr_options['resetmessage'])) { $reset = ''; } else { /* translators: ignore, the text appears for translation eslewhere */ $reset = __($amr_options['resetmessage'], 'amr-ical-events-list'); } } else { // if we on first page, do not show $reset = ''; $prevt = ''; } if (!empty($reset)) { $reseturl = remove_query_arg(array('start', 'startoffset', 'events', 'days', 'months', 'hours', 'weeks')); $reset = '<a id="icalareset" title="' . __('Go back to initial view', 'amr-ical-events-list') . '" href="' . esc_attr($reseturl) . '">' . $reset . '</a>'; } if (!empty($prevt)) { $prevt = '<a rel="prev" id="icalaprev" title="' . __('Go back to previous events', 'amr-ical-events-list') . '" href="' . esc_attr($prevurl) . '">' . $prevt . '</a>'; } return '<div id="icallookmore" class="icalnext" > ' . $prevt . ' ' . $reset . ' ' . '<a rel="next" id="icalalookmore" title="' . $explaint . ' ' . $morett . '" href="' . esc_attr($nexturl) . '">' . $moret . '</a>' . '</div>'; }
/** * Adds a positive or negative amount of seconds * * @param util.Date date * @param int count default 1 * @return util.Date */ public static function addSeconds(Date $date, $count = 1) { $hdl = $date->getHandle(); date_time_set($hdl, $date->getHours(), $date->getMinutes(), $date->getSeconds() + $count); return new Date($hdl); }
/** * Construct a date object out of it's time values If a timezone string * the date will be set into that zone - defaulting to the system's * default timezone of none is given. * * @param int year * @param int month * @param int day * @param int hour * @param int minute * @param int second * @param util.TimeZone tz default NULL * @return util.Date */ public static function create($year, $month, $day, $hour, $minute, $second, TimeZone $tz = null) { $date = date_create(); if ($tz) { date_timezone_set($date, $tz->getHandle()); } if (false === @date_date_set($date, $year, $month, $day) || false === @date_time_set($date, $hour, $minute, $second)) { throw new IllegalArgumentException(sprintf('One or more given arguments are not valid: $year=%s, $month=%s, $day= %s, $hour=%s, $minute=%s, $second=%s', $year, $month, $day, $hour, $minute, $second)); } return new self($date); }
/** * Helper function to round minutes and seconds to requested value. */ function date_increment_round(&$date, $increment) { // Round minutes and seconds, if necessary. if (is_object($date) && $increment > 1) { $day = intval(date_format($date, 'j')); $hour = intval(date_format($date, 'H')); $second = intval(round(intval(date_format($date, 's')) / $increment) * $increment); $minute = intval(date_format($date, 'i')); if ($second == 60) { $minute += 1; $second = 0; } $minute = intval(round($minute / $increment) * $increment); if ($minute == 60) { $hour += 1; $minute = 0; } date_time_set($date, $hour, $minute, $second); if ($hour == 24) { $day += 1; $hour = 0; $year = date_format($date, 'Y'); $month = date_format($date, 'n'); date_date_set($date, $year, $month, $day); } } return $date; }
/** * Set hour * * @param \DateTime $hours * @return string */ public function setHour($hour) { $hours = date_format($hour, 'H'); $minutes = date_format($hour, 'i'); date_time_set($this->date, $hours, $minutes); return $this; }
/** * Check for new Day from Timestamp * @param $ts int Unix Timestamp * @return boolean */ function is_new_day($ts) { $lastday = date_create(); date_timestamp_set($lastday, $ts); $newday = date_create(); date_time_set($newday, 0, 0, 0); return $newday > $lastday; }
private function saveDailyPlansForService($plans, $hpPlans, $serviceId, $month, $year) { $em = $this->getDoctrine()->getManager(); $service = $em->getRepository('sisconeeAppBundle:Servicio')->findOneById($serviceId); $date = date_create(); for ($d = 1; $d <= 31; $d++) { date_date_set($date, $year, $month, $d); date_time_set($date, 0, 0, 0); $this->updateDailyPlan($em, $service, $date, $plans[$d], $hpPlans[$d]); } }
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); $object = date_create("2009-01-31 15:14:10"); $hour = 10; $sec = 45; foreach ($inputs as $variation => $minute) { echo "\n-- {$variation} --\n"; var_dump(date_time_set($object, $hour, $minute, $sec)); } // closing the resource fclose($file_handle); ?> ===DONE===
public function getSeries() { //date_default_timezone_set('America/Los_Angeles'); //date_default_timezone_set('UTC'); $timezoneSettingBackup = date_default_timezone_get(); if (!empty($this->currentSeries)) { $this->yAxisField = ""; $this->yAxisFieldList = array(); $this->xAxisField = ""; $this->zAxisField = ""; $this->toolTipField = ""; } $this->setDataFields(); if (!empty($this->highField)) { return $this->getFinancialSeries(); } $this->getDataDB(); if (!$this->resultDB) { return ""; } $fieldsInfo = mysqli_fetch_fields($this->resultDB); $rowCount = mysqli_num_rows($this->resultDB); if ($rowCount < 1) { return ""; } $localColumnNames = mysqli_fetch_assoc($this->resultDB); $totalColumns = mysqli_num_fields($this->resultDB); $xAxisFieldType = 246; //DECIMAL, NUMERIC //$yAxisFieldType = 246;//DECIMAL, NUMERIC $zAxisFieldType = 246; //DECIMAL, NUMERIC $xAxisStartFieldType = 246; //DECIMAL, NUMERIC $yAxisStartFieldType = 246; //DECIMAL, NUMERIC $nameFieldType = 253; $yAxisColumn = -1; $xAxisColumn = -1; $zAxisColumn = -1; $yAxisStartColumn = -1; $xAxisStartColumn = -1; $splitByColumn = -1; $bubbleSizeColumn = -1; $nameColumn = -1; $ganttCompleteColumn = -1; $toolTipColumn = -1; $labelColumn = -1; $localxAxisField = ""; $localzAxisField = ""; $localSeriesName = ""; $customFieldsColums = array(); $strJSONCompressed = ""; $totalSeries = count($this->yAxisFieldList); if ($totalSeries < 1) { $totalSeries = 1; } if (!empty($this->currentSeries)) { if (substr($this->currentSeries, -1) == "]") { $strJSONCompressed = substr($this->currentSeries, 0, strlen($this->currentSeries) - 1); } else { $strJSONCompressed = $this->currentSeries; } $strJSONCompressed .= ","; } else { $strJSONCompressed = '['; } for ($y = 0; $y < $totalSeries; $y++) { if ($this->dataFieldSet === FALSE) { if ($totalColumns == 1) { $yAxisColumn = 0; $yAxisFieldType = $fieldsInfo[$yAxisColumn]->type; } else { $yAxisColumn = 1; $xAxisColumn = 0; $yAxisFieldType = $fieldsInfo[$yAxisColumn]->type; $xAxisFieldType = $fieldsInfo[$xAxisColumn]->type; } $localSeriesName = $fieldsInfo[$yAxisColumn]->name; switch ($this->chartType) { case "Gantt": if ($totalColumns > 2) { $nameColumn = 2; } if ($totalColumns > 3) { $ganttCompleteColumn = 3; } break; case "Bubble": //$localxAxisField = mysqli_field_name($result, 0); $localxAxisField = $fieldsInfo[$yAxisColumn]->name; if ($totalColumns > 2) { $bubbleSizeColumn = 2; } break; default: $localxAxisField = $fieldsInfo[$yAxisColumn]->name; break; } //end switch } else { if (count($this->yAxisFieldList) > $y) { $this->yAxisField = $this->yAxisFieldList[$y]; } $yAxisFieldTemp = explode('=', $this->yAxisField); if (count($yAxisFieldTemp) > 0) { $this->yAxisField = $yAxisFieldTemp[0]; } if (count($yAxisFieldTemp) > 1) { $localSeriesName = $yAxisFieldTemp[1]; } else { $localSeriesName = $yAxisFieldTemp[0]; } if (!empty($this->xAxisField)) { $xAxisColumn = array_search($this->xAxisField, array_keys($localColumnNames)); if ($xAxisColumn === FALSE) { die("Could not find field " . $this->xAxisField); } $localxAxisField = $this->xAxisField; $xAxisFieldType = $fieldsInfo[$xAxisColumn]->type; //$xAxisFieldType = mysql_field_type($result, $xAxisColumn); } if (!empty($this->zAxisField)) { $zAxisColumn = array_search($this->zAxisField, array_keys($localColumnNames)); if ($zAxisColumn === FALSE) { die("Could not find field " . $this->zAxisField); } $localzAxisField = $this->zAxisField; $zAxisFieldType = $fieldsInfo[$zAxisColumn]->type; } if (!empty($this->yAxisField)) { $yAxisColumn = array_search($this->yAxisField, array_keys($localColumnNames)); if ($yAxisColumn === FALSE) { die("Could not find field " . $this->yAxisField); } $yAxisFieldType = $fieldsInfo[$yAxisColumn]->type; //$yAxisFieldType = mysqli_field_type($result, $yAxisColumn); } if (!empty($this->xAxisStartField)) { $xAxisStartColumn = array_search($this->xAxisStartField, array_keys($localColumnNames)); if ($xAxisStartColumn === FALSE) { die("Could not find field " . $this->xAxisStartField); } } if (!empty($this->yAxisStartField)) { $yAxisStartColumn = array_search($this->yAxisStartField, array_keys($localColumnNames)); if ($yAxisStartColumn === FALSE) { die("Could not find field " . $this->yAxisStartField); } } if (!empty($this->splitByField)) { $splitByColumn = array_search($this->splitByField, array_keys($localColumnNames)); if ($splitByColumn === FALSE) { die("Could not find field " . $this->splitByField); } $localsplitByField = $this->splitByField; } if (!empty($this->bubbleSizeField)) { $bubbleSizeColumn = array_search($this->bubbleSizeField, array_keys($localColumnNames)); if ($bubbleSizeColumn === FALSE) { die("Could not find field " . $this->bubbleSizeField); } } if (!empty($this->nameField)) { $nameColumn = array_search($this->nameField, array_keys($localColumnNames)); if ($nameColumn === FALSE) { die("Could not find field " . $this->nameField); } } if (!empty($this->ganttCompleteField)) { $ganttCompleteColumn = array_search($this->ganttCompleteField, array_keys($localColumnNames)); if ($ganttCompleteColumn === FALSE) { die("Could not find field " . $this->ganttCompleteField); } } if (!empty($this->toolTipField)) { $toolTipColumn = array_search($this->toolTipField, array_keys($localColumnNames)); if ($toolTipColumn === FALSE) { die("Could not find field " . $this->toolTipField); } } if (!empty($this->labelField)) { $labelColumn = array_search($this->labelField, array_keys($localColumnNames)); if ($labelColumn === FALSE) { die("Could not find field " . $this->labelField); } } if ($this->customFields) { foreach ($this->customFields as $key => $value) { $customFieldsColum = array_search($key, array_keys($localColumnNames)); if ($customFieldsColum === FALSE) { die("Could not find field " . $key); } $customFieldsColums[$customFieldsColum] = $value; } } } //end $strJSONCompressed .= '{"name":"'; if ($localSeriesName) { $strJSONCompressed .= $localSeriesName; } else { $strJSONCompressed .= ' Series '; $strJSONCompressed .= strval($y + 1); } $strJSONCompressed .= '","points":'; $strJSON = '['; mysqli_data_seek($this->resultDB, 0); $row = mysqli_fetch_row($this->resultDB); $currentDate = strtotime($row[$xAxisColumn]); $index = 0; $hour = 0; $daysInMonth = 30; $month = 0; $this->dateGrouping = strtolower($this->dateGrouping); do { if (!empty($this->dateGrouping)) { $strJSON .= '{'; switch ($this->dateGrouping) { case "day": if ($xAxisColumn > -1) { if ($xAxisFieldType == 12) { $dt2 = new DateTime($row[$xAxisColumn]); $hour = date_format($dt2, "H") + 0; date_time_set($dt2, $hour, 0, 0); $dt = date_timestamp_get($dt2); while ($hour > $index) { $missingdt = date('U', $dt - ($hour - $index) * 3600) * 1000; $strJSON .= '"x":' . $missingdt . ','; //$strJSON .= '"x":"' . date('c',($dt-(($hour-$index)*3600))) . '",'; //'c' :ISO 8601 date (added in PHP 5), javascript:yyyy-MM-ddTHH\:mm\:ss.fffffffzzz $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $strJSON .= '{'; $index = $index + 1; } $index = $index + 1; $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; //$strJSON .= '"x":"' . date('c',$dt) . '",'; //'c' :ISO 8601 date (added in PHP 5), javascript:yyyy-MM-ddTHH\:mm\:ss.fffffffzzz } else { $nameColumn = $xAxisColumn; $xAxisColumn = -1; } /*else { die("For dateGrouping, xAxis must be 'datetime' type."); } */ } if ($nameColumn > -1) { $curName = $row[$nameColumn]; $hour = intval($curName); while ($hour > $index) { $strJSON .= '"name":"' . (string) $index . '",'; $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $strJSON .= '{'; $index = $index + 1; } $index = $index + 1; $strJSON .= '"name":"' . $curName . '",'; } break; case "month": if ($xAxisColumn > -1) { if ($xAxisFieldType == 12) { $index = $index + 1; $dt2 = new DateTime($row[$xAxisColumn]); date_time_set($dt2, 0, 0, 0); $day = date_format($dt2, "d") + 0; $dt = date_timestamp_get($dt2); if ($day > $index) { $missingDays = $day - $index; $dt = $dt - $missingDays * 86400; } while ($day > $index) { $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $strJSON .= '{'; $index = $index + 1; $dt = $dt + 86400; //(24*60*60); } $index = $index + 1; //$strJSON .= '"x":"' . date('c',$dt) . '",'; //'c' :ISO 8601 date (added in PHP 5), javascript:yyyy-MM-ddTHH\:mm\:ss.fffffffzzz $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; } else { $nameColumn = $xAxisColumn; $xAxisColumn = -1; } } if ($nameColumn > -1) { $index = $index + 1; $curName = $row[$nameColumn]; $day = intval($curName); while ($day > $index) { $strJSON .= '"name":"' . (string) $index . '",'; $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $strJSON .= '{'; $index = $index + 1; } $strJSON .= '"name":"' . $curName . '",'; } break; case "year": if ($xAxisColumn > -1) { if ($xAxisFieldType == 12) { $index = $index + 1; $dt2 = new DateTime($row[$xAxisColumn]); $month = date_format($dt2, "m") + 0; $dt = strtotime($row[$xAxisColumn]); if ($month > $index) { $missingMonths = $month - $index; $missingMonths = '-' . $missingMonths . ' month'; $dt = strtotime($missingMonths, $dt); } while ($month > $index) { $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; //$strJSON .= '"x":"' . date('c',$dt) . '",'; //'c' :SO 8601 date (added in PHP 5), javascript:yyyy-MM-ddTHH\:mm\:ss.fffffffzzz $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $strJSON .= '{'; $index = $index + 1; $dt = strtotime('+1 month', $dt); } $index = $index + 1; // $strJSON .= '"x":"' . date('c',$dt) . '",'; //'c' :SO 8601 date (added in PHP 5), javascript:yyyy-MM-ddTHH\:mm\:ss.fffffffzzz $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; } else { $nameColumn = $xAxisColumn; $xAxisColumn = -1; } } if ($nameColumn > -1) { $index = $index + 1; $curName = $row[$nameColumn]; $month = intval($curName); while ($month > $index) { $strJSON .= '"name":"' . (string) $index . '",'; $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $strJSON .= '{'; $index = $index + 1; } $strJSON .= '"name":"' . $curName . '",'; } break; default: die("dategrouping:'" . $this->dateGrouping . "' is not supported. Only Day, Month and Year are supported."); break; } if ($yAxisColumn > -1) { $strJSON .= '"y":' . $row[$yAxisColumn] . ','; } if (count($customFieldsColums) > 0) { $strJSON .= '"attributes":{'; foreach ($customFieldsColums as $key => $value) { $strJSON .= '"' . $value . '":"' . $row[$key] . '",'; } $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; } if ($toolTipColumn > -1) { $strJSON .= '"tooltip":"' . $row[$toolTipColumn] . '",'; } $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; } else { //while ($row = mysqli_fetch_row($result)) { $strJSON .= '{'; if (count($customFieldsColums) > 0) { $strJSON .= '"attributes":{'; foreach ($customFieldsColums as $key => $value) { $strJSON .= '"' . $value . '":"' . $row[$key] . '",'; } $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; } if ($nameColumn > -1) { $strJSON .= '"name":"' . $row[$nameColumn] . '",'; } if ($xAxisColumn > -1) { if ($xAxisFieldType == 12) { $dt = strtotime($row[$xAxisColumn]); //$strJSON .= '"x":"' . date('Y-m-d',$dt) . '",'; $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; } else { if ($xAxisFieldType == 253) { $strJSON .= '"name":"' . $row[$xAxisColumn] . '",'; } else { $strJSON .= '"x":' . $row[$xAxisColumn] . ','; } } } if ($zAxisColumn > -1) { $strJSON .= '"z":' . $row[$zAxisColumn] . ','; } if ($yAxisColumn > -1) { $strJSON .= '"y":' . $row[$yAxisColumn] . ','; } if ($toolTipColumn > -1) { $strJSON .= '"tooltip":"' . $row[$toolTipColumn] . '",'; } $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; } //end dategrouping } while ($row = mysqli_fetch_row($this->resultDB)); //Add empty element at the end if required. if (!empty($this->dateGrouping)) { switch ($this->dateGrouping) { case "day": $hour = $hour + 1; while ($hour < 24) { $strJSON .= '{'; if ($xAxisColumn > -1) { $dt = $dt + 3600; $missingdt = date('U', $dt) * 1000; $strJSON .= '"x":' . $missingdt . ','; } else { $strJSON .= '"name":"' . (string) $hour . '",'; } $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $hour = $hour + 1; } break; case "month": if (empty($this->startDate)) { $this->startDate = $dt2; } if (!empty($this->startDate)) { $daysInMonth = intval(date_format($this->startDate, "t")); } $day = $day + 1; while ($day < $daysInMonth + 1) { $strJSON .= '{'; if ($xAxisColumn > -1) { $dt = $dt + 86400; //(24*60*60); $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; } else { $strJSON .= '"name":"' . (string) $day . '",'; } $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $day = $day + 1; } break; case "year": $month = $month + 1; while ($month < 13) { $strJSON .= '{'; if ($xAxisColumn > -1) { $dt = strtotime("+1 month", $dt); $strJSON .= '"x":' . date('U', $dt) * 1000 . ','; //$strJSON .= '"x":"' . date('c',$dt) . '",'; //'c' :SO 8601 date (added in PHP 5), javascript:yyyy-MM-ddTHH\:mm\:ss.fffffffzzz } else { $strJSON .= '"name":"' . (string) $month . '",'; } $strJSON .= '"y":0.00,'; $strJSON = rtrim($strJSON, ','); $strJSON .= '},'; $month = $month + 1; } break; } } $strJSON = rtrim($strJSON, ','); $strJSON .= ']'; //end points $pointArray = json_decode($strJSON); $pointsCompressed = $this->pointsToArray($pointArray); $strJSONCompressed .= $pointsCompressed; $strJSONCompressed .= '},'; //end one series } //end for $strJSONCompressed = rtrim($strJSONCompressed, ','); //remove the last , because there is no more series $strJSONCompressed .= ']'; //end series $this->currentSeries = $strJSONCompressed; $this->clear(); return $strJSONCompressed; }
} 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); var_dump($nextyear); $d = strtotime("2001-03-10 05:16:18");
/** * Rounds minutes and seconds to nearest requested value. * * @param $date * * @param $increment * * @return */ protected static function incrementRound(&$date, $increment) { // Round minutes and seconds, if necessary. if ($date instanceof DrupalDateTime && $increment > 1) { $day = intval(date_format($date, 'j')); $hour = intval(date_format($date, 'H')); $second = intval(round(intval(date_format($date, 's')) / $increment) * $increment); $minute = intval(date_format($date, 'i')); if ($second == 60) { $minute += 1; $second = 0; } $minute = intval(round($minute / $increment) * $increment); if ($minute == 60) { $hour += 1; $minute = 0; } date_time_set($date, $hour, $minute, $second); if ($hour == 24) { $day += 1; $year = date_format($date, 'Y'); $month = date_format($date, 'n'); date_date_set($date, $year, $month, $day); } } return $date; }
public static function getRangeFromDateString($string) { $formats = ['Y/m/d', 'Y/m', 'Y']; $deltas = ['+1 day', '+1 month', '+1 year']; $to = null; while ($format = array_pop($formats)) { $delta = array_pop($deltas); $from = date_create_from_format($format, $string); if ($from !== false) { // Rewind to start of range $month = 1; $day = 1; switch ($format) { case 'Y/m/d': $day = (int) $from->format('d'); case 'Y/m': $month = (int) $from->format('m'); case 'Y': $year = (int) $from->format('Y'); } date_date_set($from, $year, $month, $day); date_time_set($from, 0, 0, 0); // Create end of the the range $to = date_modify(clone $from, $delta); break; } } if (!$from || !$to) { throw new \InvalidArgumentException(sprintf('Invalid date "%s".', $string)); } return ['from' => $from->format(Mapping::DATE_FORMAT_CAPTION_PHP), 'to' => $to->format(Mapping::DATE_FORMAT_CAPTION_PHP)]; }
/** https://core.trac.wordpress.org/ticket/25768 * * Modified from the original patch to use the currently set * timezone from PHP, like PHP's date(), and to make the code * more readable. * * @param $j * @param $req_format * @param bool $i * @param bool $gmt * @return bool|string */ function fix_date_i18n($j, $req_format, $i = false, $gmt = false) { /* @var $wp_locale WP_Locale */ global $wp_locale; $timestamp = $i; // get current timestamp if $i is false if (false === $timestamp) { if ($gmt) { $timestamp = time(); } else { $timestamp = current_time('timestamp'); } } // get components of the date (timestamp) as array $date_components = getdate($timestamp); // numeric representation of a month, with leading zeros $date_month = $wp_locale->get_month($date_components['mon']); $date_month_abbrev = $wp_locale->get_month_abbrev($date_month); // numeric representation of the day of the week $date_weekday = $wp_locale->get_weekday($date_components['wday']); $date_weekday_abbrev = $wp_locale->get_weekday_abbrev($date_weekday); // get if hour is Ante meridiem or Post meridiem $meridiem = $date_components['hours'] >= 12 ? 'pm' : 'am'; // lowercase Ante meridiem and Post meridiem hours $date_meridiem = $wp_locale->get_meridiem($meridiem); // uppercase Ante meridiem and Post meridiem $date_meridiem_capital = $wp_locale->get_meridiem(strtoupper($meridiem)); // escape literals $date_weekday_abbrev = backslashit($date_weekday_abbrev); $date_month = backslashit($date_month); $date_weekday = backslashit($date_weekday); $date_month_abbrev = backslashit($date_month_abbrev); $date_meridiem = backslashit($date_meridiem); $date_meridiem_capital = backslashit($date_meridiem_capital); // the translated format string $translated_date_format_string = ''; // the 2 arrays map a format literal to its translation (e. g. 'F' to the escaped month translation) $translate_formats = array('D', 'F', 'l', 'M', 'a', 'A', 'c', 'r'); $translations = array($date_weekday_abbrev, $date_month, $date_weekday, $date_month_abbrev, $date_meridiem, $date_meridiem_capital, 'Y-m-d\\TH:i:sP', sprintf('%s, d %s Y H:i:s O', $date_weekday_abbrev, $date_month_abbrev)); // find each format literal that needs translation and replace it by its translation // respects the escaping // iterate $req_format from ending to beginning for ($i = strlen($req_format) - 1; $i > -1; $i--) { // test if current char is format literal that needs translation $translate_formats_index = array_search($req_format[$i], $translate_formats); if ($translate_formats_index !== false) { // counts the slashes (the escape char) in front of the current char $slashes_counter = 0; // count all slashes left-hand side of the current char for ($j = $i - 1; $j > -1; $j--) { if ($req_format[$j] == '\\') { $slashes_counter++; } else { break; } } // number of slashes is even if ($slashes_counter % 2 == 0) { // current char is not escaped, therefore it is a format literal $translated_date_format_string = $translations[$translate_formats_index] . $translated_date_format_string; } else { // current char is escaped, therefore it is not a format literal, just add it unchanged $translated_date_format_string = $req_format[$i] . $translated_date_format_string; } } else { // current char is no a format literal, just add it unchanged $translated_date_format_string = $req_format[$i] . $translated_date_format_string; } } $req_format = $translated_date_format_string; if ($gmt) { // get GMT date string $date_formatted = gmdate($req_format, $timestamp); } else { // get Wordpress time zone // $timezone_string = get_option('timezone_string'); // Haha, just kidding. Let's get the currently set timezone, as God and Rasmus intended $timezone_string = date_default_timezone_get(); if ($timezone_string) { // create time zone object $timezone_object = timezone_open($timezone_string); // create date object from time zone object $local_date_object = date_create(null, $timezone_object); // set time and date of $local_date_object to $timestamp $date_components = isset($date_components) ? $date_components : getdate($timestamp); date_date_set($local_date_object, $date_components['year'], $date_components['mon'], $date_components['mday']); date_time_set($local_date_object, $date_components['hours'], $date_components['minutes'], $date_components['seconds']); // format date according to the Wordpress time zone $date_formatted = date_format($local_date_object, $req_format); } else { // fall back if no Wordpress time zone set $date_formatted = date($req_format, $i); } } return $date_formatted; }
<?php /* Prototype : DateTime date_time_set ( DateTime $object , int $hour , int $minute [, int $second ] ) * Description: Resets the current time of the DateTime object to a different time. * Source code: ext/date/php_date.c * Alias to functions: DateTime::setTime */ //Set the default time zone date_default_timezone_set("Europe/London"); echo "*** Testing date_time_set() : basic functionality ***\n"; // Create a DateTime object $datetime = date_create("2009-01-31 15:14:10"); echo "Initial date: " . date_format($datetime, DATE_RFC2822) . "\n"; date_time_set($datetime, 17, 20); echo "After modification1 " . date_format($datetime, DATE_RFC2822) . "\n"; date_time_set($datetime, 19, 05, 59); echo "After modification2 " . date_format($datetime, DATE_RFC2822) . "\n"; date_time_set($datetime, 24, 10); echo "After modification3 " . date_format($datetime, DATE_RFC2822) . "\n"; date_time_set($datetime, 47, 35, 47); echo "After modification4 " . date_format($datetime, DATE_RFC2822) . "\n"; date_time_set($datetime, 54, 25); echo "After modification5 " . date_format($datetime, DATE_RFC2822) . "\n"; ?> ===DONE===
/** * Compara dos fechas comprobando que sean iguales (sin tener en cuenta las horas y los minutos) * @param type $date1 * @param type $date2 * @return type */ public function equalDates($date1, $date2) { $d1 = new \DateTime($date1->format('r')); $d1 = date_time_set($d1, 0, 0, 0); $d2 = new \DateTime($date2->format('r')); $d2 = date_time_set($d2, 0, 0, 0); return $d1 == $d2; }
public static function afterParse(&$report) { $classname = $report->options['Type'] . 'ReportType'; foreach ($report->options['Variables'] as $var => $params) { //if it's a select variable and the options are pulled from a database if (isset($params['database_options'])) { $classname::openConnection($report); $params['options'] = $classname::getVariableOptions($params['database_options'], $report); $report->options['Variables'][$var] = $params; } //if the type is daterange, parse start and end with strtotime if ($params['type'] === 'daterange' && $report->macros[$params['name']]['start'] && $report->macros[$params['name']]['end']) { $start = date_create($report->macros[$params['name']]['start']); if (!$start) { throw new Exception($params['display'] . " must have a valid start date."); } date_time_set($start, 0, 0, 0); $report->macros[$params['name']]['start'] = date_format($start, $params['format']); $end = date_create($report->macros[$params['name']]['end']); if (!$end) { throw new Exception($params['display'] . " must have a valid end date."); } date_time_set($end, 23, 59, 59); $report->macros[$params['name']]['end'] = date_format($end, $params['format']); } } }
public function getHourEnd($hourString, $day) { if (strpos($hourString, '-') === false) { // this is simply one hour - the end is implicitly one hour after the start. $hour = substr($hourString, 0, 2); $minute = substr($hourString, 3, 2); $result = clone $day; date_time_set($result, intval($hour) + 1, intval($minute), 00); return $result; } else { // this is a longer time range divided by a '-', so the end time is given. return $this->getHourStart(substr($hourString, strpos($hourString, '-') + 1), $day); } }
function amr_GET_params($attributes = array()) { /* We are passed the widget or shortcode attributes, check them, get what we can there, then check for passed parameters (form or query string ) Anything unset we will get from the default settings for that listtype. The defaults list type is 1. then set the amr_limits (note the calendar options may overwrite these) */ global $amr_limits, $amr_listtype, $amr_liststyle, $amr_options, $amr_groupings, $amr_fields_needed, $amr_event_columns, $amr_formats, $amr_globaltz, $change_view_allowed, $amr_calendar_url, $amrW; // indicates if widget, $amr_options = amr_GETset_options(); // $defaults = array('listtype' => $amr_listtype, 'startoffset' => '', 'hoursoffset' => '', 'monthsoffset' => '', 'daysoffset' => '', 'start' => '', 'days' => '', 'events' => '', 'months' => '', 'hours' => '', 'weeks' => '', 'tz' => '', 'eventpoststoo' => '1', 'agenda' => '', 'calendar' => '', 'eventmap' => '0', 'show_views' => '1', 'show_month_nav' => '0', 'show_look_more' => '0', 'day_links' => '1', 'month_year_dropdown' => '0', 'month_prev_next' => '0', 'calendar_properties' => '1', 'pagination' => '1', 'headings' => '1', 'ignore_query' => '', 'grouping' => '', 'more_url' => '', 'no_filters' => '0', 'sort_later_events_first' => '0', 'exclude_in_progress' => '0'); $shortcode_params = shortcode_atts($defaults, $attributes); // if (!empty($attributes)) { // if there is stuff left - must be urls foreach ($attributes as $i => $v) { if (is_numeric($i) or $i == 'ics') { // ie if it is a value passed with no name, we expect only urls like that if (substr($v, 0, 1) == ':') { /* attempt to maintain old filter compatibity */ $shortcode_params['urls'][$i] = substr($v, 1); } $v2 = str_ireplace('webcal://', 'http://', $v); //keep the webcal if (function_exists('filter_var') and !filter_var($v2, FILTER_VALIDATE_URL)) { /* rejecting a valid URL on php 5.2.14 */ echo '<h2>' . sprintf(__('Invalid Ical URL %s', 'amr-ical-events-list'), $v2) . '</h2>'; if (current_user_can('administrator')) { echo '<p>Notes to admin only (does not show if not logged in as admin): <ul> <li>If you have put [ical in the widget - take it out! </li> <li>the php validation functon does not cope with internationalised domain, please contact the developer if this affects you.</li> </ul></p>'; } } else { $shortcode_params['urls'][$i] = esc_url_raw($v); } unset($attributes[$i]); } } // end foreach } //end if // handle taxonomies we do not even know about yet /* get the parameters we want out of the attributes, supplying defaults for anything missing */ /* but now we may have missed taxonomies etc as the defaults do not know about them, so get the diff */ if (!empty($attributes)) { //var_dump($attributes); //var_dump($shortcode_params); // - this could be multi-d array due to urls so array diff will throw a notice in php 5.4 // maybe extract somehow ourselves? or use array_diff_key instead /**** $taxo_selection = array_diff_key($attributes, $shortcode_params); } // if we had some taxos, marge them into shortcode selection if (!empty($taxo_selection)) { $shortcode_params = array_merge($shortcode_params, $taxo_selection); } $allow_query = (!isset($shortcode_params['ignore_query']) or !$shortcode_params['ignore_query']); $ignore_query_all = (isset($shortcode_params['ignore_query']) and $shortcode_params['ignore_query'] == 'all'); unset($shortcode_params['ignore_query']); if ($allow_query) { // parse_str($_SERVER['QUERY_STRING'], $queryargs); /* Get anything passed in the query string that will override shortcodes */ // check for posted values to get around that pesky problem if (isset($_GET['start'])) { $queryargs['start'] = $_GET['start']; } foreach ($queryargs as $i => $arg) { $queryargs[$i] = filter_var($arg, FILTER_SANITIZE_STRING); //Strip tags, } if ($change_view_allowed) { // for upcoming events widget, may want to allow query of days etc, but not the listtype change if (isset($queryargs['calendar'])) { $queryargs['listtype'] = $queryargs['calendar']; } if (isset($queryargs['agenda'])) { $queryargs['listtype'] = $queryargs['agenda']; } } unset($queryargs['page_id']); unset($queryargs['debug']); if (isset($_GET['debugq'])) { echo '<hr> Query allowed, attributes/args to consider adding:<br />'; var_dump($queryargs); } $shortcode_params = array_merge($shortcode_params, $queryargs); /* If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended. */ // if (ICAL_EVENTS_DEBUG) {echo '<hr>After merge with query args<br />'; var_dump($shortcode_params); } //unset($queryargs['listtype']); } else { if (isset($_GET['debugq'])) { echo '<hr>Ignoring most query parameters '; } } // // save the global list type first if (!empty($shortcode_params['listtype'])) { $amr_listtype = $shortcode_params['listtype']; unset($shortcode_params['listtype']); } // unset($attributes['listtype']); if ($change_view_allowed and $allow_query) { // then we will NOT ignore these query parameters as that will break our navigation //if (ICAL_EVENTS_DEBUG) {echo '<br />Allowed to change views';} if (isset($_GET['listtype'])) { $amr_listtype = intval($_GET['listtype']); } if (isset($_GET['eventmap'])) { $amr_listtype = 'eventmap'; } // havent figured this out yet } // check the listtype here ? if (empty($amr_options['listtypes'][$amr_listtype])) { if (current_user_can('administrator')) { echo sprintf(__('System error - event list type %s missing - please inform administrator.', 'amr-ical-events-list'), $amr_listtype); _e('Now using an available list type to list events', 'amr-ical-events-list'); } $amr_listtype = amr_first_available_listtype(); } $amr_liststyle = isset($amr_options['listtypes'][$amr_listtype]['general']['ListHTMLStyle']) ? $amr_options['listtypes'][$amr_listtype]['general']['ListHTMLStyle'] : ($amr_liststyle = 'table'); //; 'list' if (!empty($shortcode_params['more_url'])) { $amr_calendar_url = esc_url($shortcode_params['more_url']); unset($shortcode_params['more_url']); } // always respond to start // if (in_array ($amr_liststyle, array('smallcalendar','largecalendar', 'weekscalendar'))) { // then query args overeride even if we have ignore query if (!$ignore_query_all) { if (isset($_GET['start'])) { $queryargs['start'] = $_GET['start']; } //need here too if (!empty($queryargs['start'])) { $shortcode_params['start'] = abs((int) $queryargs['start']); if (ICAL_EVENTS_DEBUG) { echo '<br />START = ' . $shortcode_params['start']; } // $shortcode_params['start'] = (substr((string) $shortcode_params['start'],0,6).'01'); //set to month start - done in month shortcdoe? } if (!empty($queryargs['months'])) { $shortcode_params['months'] = abs((int) $queryargs['months']); } if (!empty($queryargs['tz'])) { $shortcode_params['tz'] = filter_var($queryargs['tz'], FILTER_SANITIZE_STRING); } } else { if (isset($_GET['debugall'])) { echo '<br/>** Ignoring all query parameters'; } } //----------------------------------------------------------------------------------------------------------------- now do thelimits array // then get the limits for that list type $amr_limits = $amr_options['listtypes'][$amr_listtype]['limit']; /* get the default limits */ if ($amr_liststyle === 'weekscalendar') { $amr_limits['weeks'] = 2; // default for horizontal calendar } if ($amr_liststyle === 'largecalendar' or $amr_liststyle === 'smallcalendar') { if (empty($amr_limits['months'])) { $amr_limits['months'] = 1; } // default for horizontal calendar } // now check groupings $gg = ''; if (!empty($shortcode_params['grouping'])) { $gg = ucwords($shortcode_params['grouping']); } unset($shortcode_params['grouping']); if (!empty($_GET['grouping'])) { $gg = ucwords($_GET['grouping']); } if (!($gg == '')) { unset($amr_options['listtypes'][$amr_listtype]['grouping']); if (array_key_exists($gg, $amr_groupings)) { // if it is a valid grouping $amr_options['listtypes'][$amr_listtype]['grouping'][$gg] = true; unset($shortcode_params['grouping']); } } if (!empty($shortcode_params)) { foreach ($shortcode_params as $i => $v) { // must be atts not limits as atts may hold more then limits - limits just has initial limits if (in_array($i, array('headings', 'show_views', 'agenda', 'eventmap', 'calendar', 'eventpoststoo', 'pagination', 'calendar_properties', 'no_filters', 'show_month_nav', 'show_look_more', 'day_links', 'more_url', 'month_year_dropdown', 'month_prev_next'))) { $amr_limits[$i] = abs(intval($v)); unset($shortcode_params[$i]); // only unset if empty what??? - else will lose others } else { if (in_array($i, array('days', 'events', 'months', 'listtype', 'hours', 'weeks', 'daysoffset', 'startoffset', 'hoursoffset', 'monthsoffset'))) { if (!empty($v)) { $amr_limits[$i] = (int) $v; } // can be negative, so no abs unset($shortcode_params[$i]); } } } if (!empty($amr_limits['listtype'])) { $amr_listtype = $amr_limits['listtype']; if (ICAL_EVENTS_DEBUG) { echo '<br />listtype set to: '; } } } // else might be a taxonomy or categeory etc ... pass through - not if we have filtered string /* ----check if we want to overwrite the wordpress timezone */ if (!empty($shortcode_params['tz'])) { // allows one to overwrite the timezone $amr_globaltz = timezone_open($shortcode_params['tz']); } unset($shortcode_params['preview']); //clear it out so we do not pass to wp query unset($shortcode_params['tz']); //clear it out so we do not pass to wp query if (isset($_GET['tzdebug'])) { echo '<p>Plugin/Wordpress Timezone:' . timezone_name_GET($amr_globaltz); echo ', current offset is ' . $amr_globaltz->getOffset(date_create('now', $amr_globaltz)) / (60 * 60) . '</p>'; } //------------------------------- $pos_int_options = array("options" => array("min_range" => 1, "max_range" => 1000)); $neg_int_options = array("options" => array("min_range" => -1000, "max_range" => 1000)); /* check non url parameters */ if (empty($shortcode_params['start'])) { $amr_limits['start'] = date_create('now', $amr_globaltz); } else { $amr_limits['start'] = abs((int) $shortcode_params['start']); } unset($shortcode_params['start']); // clear it out so we do not pass it to wp query // work out whether we are doing a calendar or not. calendars must still respond to at least the month navigation foreach ($amr_limits as $i => $a) { // create our date objects if ($i === 'start' or $i === 'end') { if (!is_object($a)) { $dateok = checkdate(substr($a, 4, 2), substr($a, 6, 2), substr($a, 0, 4)); /* year */ if ($dateok) { $amr_limits[$i] = date_create($a, $amr_globaltz); if (!is_object($amr_limits[$i])) { amr_tell_error($i . ' ' . __('Date could not be converted to date object.', 'amr-ical-events-list') . __('Check date and global timezone.', 'amr-ical-events-list')); var_dump($amr_limits[$i]); var_dump($amr_globaltz); } } else { _e('Invalid Start Date', 'amr-ical-events-list'); echo '<br />' . $i . ' ' . $a; $amr_limits[$i] = date_create('now', $amr_globaltz); } } /* else all is okay - we have default date of now */ } } if (!empty($shortcode_params['daysoffset'])) { /* keeping startoffset for old version compatibility, but allowing for daysoffset for compatibility with other offsets */ $amr_limits['startoffset'] = (int) $shortcode_params['daysoffset']; // can be negative } /* ---- check for urls that are either passed by query or form, or are in the shortcode with a number or not ie: not ics = */ //set up global for easier access $amr_formats = $amr_options['listtypes'][$amr_listtype]['format']; // now adjust our start dta if necessary if (!empty($amr_limits['startoffset'])) { $daysoffset = (int) $amr_limits['startoffset']; if ($daysoffset > 0) { $daysoffset = '+' . (string) $daysoffset . ' days'; } else { $daysoffset = (string) $daysoffset . ' days'; } date_modify($amr_limits['start'], $daysoffset); } // if (!empty($amr_limits['hoursoffset'])) { $hrsoffset = (int) $amr_limits['hoursoffset']; if ($hrsoffset > 0) { $hrsoffset = '+' . (string) $hrsoffset . ' hours'; } else { $hrsoffset = (string) $hrsoffset . ' hours'; } date_modify($amr_limits['start'], $hrsoffset); /*** as per request from jd */ } // if (!empty($amr_limits['monthsoffset'])) { $mthsoffset = (int) $amr_limits['monthsoffset']; if ($mthsoffset >= 0) { $mthsoffset = '+' . (string) $mthsoffset . ' months'; } else { $mthsoffset = (string) $mthsoffset . ' months'; } date_modify($amr_limits['start'], $mthsoffset); } // if (!empty($amr_limits['hours'])) { /* then set the time to the beginning of the day , and get rid of months and days */ date_time_set($amr_limits['start'], $amr_limits['start']->format('G'), 0, 0); /* set the time to beginning of the hour */ unset($amr_limits['days']); unset($amr_limits['months']); } if (!empty($amr_limits['months'])) { /* then set the date to the beginning of the month and get rid of days */ $days = (int) $amr_limits['start']->format('d'); if ($days > 1) { $amr_limits['start']->modify('-' . ($days - 1) . ' days'); } date_time_set($amr_limits['start'], 0, 0, 0); unset($amr_limits['days']); } // if (empty($amr_limits['hours'])) { /* else use the days and then set the time to the beginning of the day */ date_time_set($amr_limits['start'], 0, 0, 0); } $wkst = ical_GET_weekstart(); // get the wp start of week if (isset($_GET['debugwks'])) { echo '<br/>wkst = ' . $wkst; } if (!empty($amr_limits['weeks'])) { // weeks overrides all else $amr_limits['start'] = amr_GET_human_start_of_week($amr_limits['start'], $wkst); /* set to start of week */ $amr_limits['days'] = $amr_limits['weeks'] * 7; unset($amr_limits['hours']); if (isset($_GET['debugwks'])) { echo '<br />Start set to = ' . $amr_limits['start']->format('c'); } } // now find our end date - may get overridden if calendar if (is_object($amr_limits['start'])) { $amr_limits['end'] = new Datetime(); //if cloning dont need tz $amr_limits['end'] = clone $amr_limits['start']; } else { // something horribly wrong here amr_tell_eror(__('Error: Start data of range is not a date object. Please advise administrator', 'amr-ical-events-list')); var_dump($amr_limits['start']); } if (!empty($amr_limits['months'])) { date_modify($amr_limits['end'], '+' . $amr_limits['months'] . ' months'); } if (!empty($amr_limits['days'])) { date_modify($amr_limits['end'], '+' . $amr_limits['days'] . ' days'); } if (!empty($amr_limits['hours'])) { date_modify($amr_limits['end'], '+' . $amr_limits['hours'] . ' hours'); } else { date_modify($amr_limits['end'], '-1 second'); } /* so that we do not include events starting in the next time period */ if (isset($_GET['debug'])) { echo '<br/>end = ' . $amr_limits['end']->format('c'); } // date_time_set ($amr_limits['end'],23,59,59); // if we have this, do we need the -1 second below? if (isset($_GET['debugq'])) { echo '<hr> Before passing others <br />'; var_dump($shortcode_params); echo amr_echo_parameters(); } $amr_event_columns = prepare_order_and_sequence($amr_options['listtypes'][$amr_listtype]['compprop']); //do once earlier $amr_fields_needed = amr_extract_fields($amr_event_columns); // setup global return $shortcode_params; // only return params needed for wp query ? }
<?php /* Prototype : DateTime date_time_set ( DateTime $object , int $hour , int $minute [, int $second ] ) * Description: Resets the current time of the DateTime object to a different time. * Source code: ext/date/php_date.c * Alias to functions: DateTime::setTime */ date_default_timezone_set("Europe/London"); echo "*** Testing date_time_set() : error conditions ***\n"; echo "\n-- Testing date_time_set() function with zero arguments --\n"; var_dump(date_time_set()); echo "\n-- Testing date_time_set() function with less than expected no. of arguments --\n"; $datetime = date_create("2009-01-31 15:34:10"); $hour = 18; var_dump(date_time_set($datetime)); var_dump(date_time_set($datetime, $hour)); echo "\n-- Testing date_time_set() function with more than expected no. of arguments --\n"; $min = 15; $sec = 30; $extra_arg = 10; var_dump(date_time_set($datetime, $hour, $min, $sec, $extra_arg)); echo "\n-- Testing date_time_set() function with an invalid values for \$object argument --\n"; $invalid_obj = new stdClass(); var_dump(date_time_set($invalid_obj, $hour, $min, $sec)); $invalid_obj = 10; var_dump(date_time_set($invalid_obj, $hour, $min, $sec)); $invalid_obj = null; var_dump(date_time_set($invalid_obj, $hour, $min, $sec)); ?> ===DONE===
date_time_set($from2, 8, 00, 01); $from = date_format($from2, "Y-m-d H:i:s"); //echo 'From date: '. $from .'<br>'; //echo 'To date: '. $to .'<br>'; } else { $date1 = $_POST['from']; $date2 = $_POST['to']; //to date calibration $to2 = date_create($date2); date_time_set($to2, 8, 00, 00); date_add($to2, date_interval_create_from_date_string('1 days')); //add one day to date $to = date_format($to2, "Y-m-d H:i:s"); //from date calibration $from2 = date_create($date1); date_time_set($from2, 8, 00, 01); $from = date_format($from2, "Y-m-d H:i:s"); } /******============================================================================================************/ $data["locationid"] = $location; $data["rain"] = $rain; $data["fromdate"] = $from; $data["todate"] = $to; $data["note"] = $note; $fields = json_encode($data); //echo 'From date: '. $from .'<br>'; // echo 'To date: '. $to .'<br>'; /******============================================================================================************/ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://afrihost.sasscal.org/api/rain"); curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $pw);
static function to_date($date = NULL, $default_to_earliest = TRUE, $fully_expand = FALSE) { if ($date == '') { if ($fully_expand) { return date('Y-m-d', time()); } return date('Y-m-d-H-i', time()); } if ($date[0] == '+') { return date('Y-m-d', time() + substr($date, 1)); } else { if ($date[0] == '-') { return date('Y-m-d', time() - substr($date, 1)); } else { if (is_string($date) && preg_match('/this_year/i', $date)) { $date = date('Y'); } } } if (is_array($date)) { $date_parts = $date; } else { $date_parts = preg_split('/[-\\.\\/ ]/', $date, -1, PREG_SPLIT_NO_EMPTY); } // we utilise the fact that setting the day to 0 will result in the // last day of the month being set $date = array(1970, 12, 0); if ($default_to_earliest) { $date = array(1970, 1, 1); } if (@isset($date_parts[0])) { $date[0] = $date_parts[0]; } if (@isset($date_parts[1])) { $date[1] = $date_parts[1]; } if (@isset($date_parts[2])) { $date[2] = $date_parts[2]; } else { if (!$default_to_earliest) { $date[1] += 1; } } $date_instance = date_create(); date_date_set($date_instance, $date[0], $date[1], $date[2]); // deal with an extended format, ie hour and minutes if (count($date_parts) >= 5) { date_time_set($date_instance, $date_parts[3], $date_parts[4]); return date_format($date_instance, 'Y-m-d-H-i'); } if ($fully_expand) { if (!$default_to_earliest) { date_time_set($date_instance, 23, 59); } else { date_time_set($date_instance, 00, 00); } return date_format($date_instance, 'Y-m-d-H-i'); } return date_format($date_instance, 'Y-m-d'); }