function getPublishBeforeDate($date_format = DATE_ATOM) { if (isset($_GET['txtToDate']) && validDate($_GET['txtToDate'])) { $d = new Datetime($_GET['txtToDate']); $publishBeforeDate = $d->format($date_format); } else { $d = new Datetime('tomorrow'); //gets tomorrow's date; $publishBeforeDate = $d->format($date_format); } return $publishBeforeDate; }
function test_date(&$date) { if (strlen($date) != 19) { if (strlen($date) == 16) { $date[16] = ':'; $date[17] = 0; $date[18] = 0; } else { return false; } } $regex = '/^\\b(2([0-9])([0-9])([0-9]))\\-(([0-1])([0-9]))\\-(([0-3])([0-9])) (([0-2])([0-9])):(([0-5])([0-9])):(([0-5])([0-9]))\\b$/'; if (!preg_match($regex, $date)) { return false; } $year = (int) ("" . $date[0] . $date[1] . $date[2] . $date[3]); $month = (int) ("" . $date[5] . $date[6]); $day = (int) ("" . $date[8] . $date[9]); $hour = (int) ("" . $date[11] . $date[12]); $minutes = (int) ("" . $date[14] . $date[15]); $seconds = (int) ("" . $date[17] . $date[18]); return validDate($year, $month, $day, $hour, $minutes, $seconds); }
<input type="radio" name="datetype" value="week"> Week </td> </tr> <tr> <td colspan="2"> <input type="submit" value="Submit" /> </td> </tr> </table> </form> </div> <?php if (!empty($_GET['date'])) { $Date = $_GET['date']; $SQLTime = $Date . ' 00:00:00'; if (!validDate($SQLTime)) { error('Something is wrong with the date you provided'); } if (empty($_GET['datetype']) || $_GET['datetype'] == 'day') { $Type = 'day'; $Where = "\n\t\t\tWHERE th.Date BETWEEN '{$SQLTime}' AND '{$SQLTime}' + INTERVAL 24 HOUR\n\t\t\t\tAND Type = 'Daily'"; } else { $Type = 'week'; $Where = "\n\t\t\tWHERE th.Date BETWEEN '{$SQLTime}' - AND '{$SQLTime}' + INTERVAL 7 DAY\n\t\t\t\tAND Type = 'Weekly'"; } $Details = $Cache->get_value("top10_history_{$SQLTime}"); if ($Details === false) { $DB->query("\n\t\t\tSELECT\n\t\t\t\ttht.Rank,\n\t\t\t\ttht.TitleString,\n\t\t\t\ttht.TagString,\n\t\t\t\ttht.TorrentID,\n\t\t\t\tg.ID,\n\t\t\t\tg.Name,\n\t\t\t\tg.CategoryID,\n\t\t\t\tg.TagList,\n\t\t\t\tt.Format,\n\t\t\t\tt.Encoding,\n\t\t\t\tt.Media,\n\t\t\t\tt.Scene,\n\t\t\t\tt.HasLog,\n\t\t\t\tt.HasCue,\n\t\t\t\tt.LogScore,\n\t\t\t\tt.RemasterYear,\n\t\t\t\tg.Year,\n\t\t\t\tt.RemasterTitle\n\t\t\tFROM top10_history AS th\n\t\t\t\tLEFT JOIN top10_history_torrents AS tht ON tht.HistoryID = th.ID\n\t\t\t\tLEFT JOIN torrents AS t ON t.ID = tht.TorrentID\n\t\t\t\tLEFT JOIN torrents_group AS g ON g.ID = t.GroupID\n\t\t\t{$Where}\n\t\t\tORDER BY tht.Rank ASC"); $Details = $DB->to_array(); $Cache->cache_value("top10_history_{$SQLTime}", $Details, 3600 * 24); }
function verifyArticle($articleArray) { $feedback = array(); if ($articleArray['comment_to'] == "NULL") { if (strlen($articleArray['title']) < 2) { $feedback[] = getString("title_is_required", "Tittelen mangler."); } } if (strlen($articleArray['body']) < 2) { $feedback[] = getString("body_is_required", "Teksten mangler."); } if (!justTextAndNumbers($articleArray['author'])) { $feedback[] = "author_just_text_and_numbers"; } if (!isLoggedIn($articleArray['author_username'])) { $feedback[] = "user_does_not_exist"; } if (!mayCreateArticles($articleArray['author_username'])) { $feedback[] = "user_cannot_post_article"; } if (!categoryExists($articleArray['category'])) { $feedback[] = "category_does_not_exist"; } if (!validDate($articleArray['date_posted'])) { $feedback[] = "invalid_date"; } if (!validTime($articleArray['time_posted'])) { $feedback[] = "invalid_time"; } //if (!isBoolean($articleArray['is_draft'])) //$feedback[] = "isdraft_must_be_boolean"; if (!validURL($articleArray['picture_url'])) { $feedback[] = "invalid_url"; } // More than 0 errors, return now // First element in array must be -1 to signal error if (count($feedback) > 0) { array_push($feedback, "-1"); return array_reverse($feedback); } $feedback[] = "1"; return $feedback; }
} elseif (in_array($mes, $arrdois)) { if ($dia < 1 || $dia > 30) { $diav = false; } } elseif ($mes == 2) { if ($ano % 4 == 0 && $ano % 100 != 0 || $ano % 400 == 0) { $fev = '29'; } else { $fev = '28'; } if ($dia < 1 || $dia > $fev) { $diav = false; } } else { $mesv = false; } } else { $anov = false; } if (!$anov) { echo 'somente aceitamos anos entre 1800 à ' . date('Y'); } elseif (!$mesv) { echo 'mês informado não existe no calendário!'; } elseif (!$diav) { echo 'dia informado não existe no calendário!'; } else { echo 'data confere!'; } } validDate('21/03/2012'); echo '<hr />';
<?php require_once "db_layer.php"; require_once "date_layer.php"; require_once "settings.php"; $d = $_POST['d']; $m = $_POST['m']; $y = $_POST['y']; $d = filter_var($d, FILTER_VALIDATE_INT); $m = filter_var($m, FILTER_VALIDATE_INT); $y = filter_var($y, FILTER_VALIDATE_INT); //TODO Add the possibility to specify an end date. If not set use the behaviour specified below and if set check for that specific interval if (validDate($y, $m, $d, 0, 0)) { header('HTTP/1.1 200 OK'); echo json_encode(getReservationsNextDays($d, $m, $y)); exit; } else { header('HTTP/1.1 400 Bad Request'); echo "Geen geldige datum opgegeven."; exit; } /** * Returns all reservations that take place during the given month and year. * A reservation is considered to take place in the period if it has an overlap * (the union of the reservation and the month is not empty) * * @param $m The number of the month * @param $y The year * @pre $m and $y are integers * @return array An associated array ('begin', 'end', 'isSV') with the reservations for this month */
$vertrekdag = trim(strip_tags($_POST["vertrek-dag"]), " \n"); $vertrekmaand = trim(strip_tags($_POST["vertrek-maand"]), " \n"); $vertrekjaar = trim(strip_tags($_POST["vertrek-jaar"]), " \n"); $vertrekuur = trim(strip_tags($_POST["vertrek-uur"]), " \n"); $vertrekminuut = trim(strip_tags($_POST["vertrek-minuut"]), " \n"); // First check if dates are ok and valid, if so build the proper string $startSTR = ""; $endSTR = ""; $alreadyReserved = False; //Convert the month name to month number $aankomstmaandNummer = getMonthNumber($aankomstmaand); $vertrekmaandNummer = getMonthNumber($vertrekmaand); if ($aankomstmaandNummer === -1 || $vertrekmaandNummer === -1) { incompleteData("aankomsts- en/of vertrekmaand"); } if (!validDate($aankomstjaar, $aankomstmaandNummer, $aankomstdag, $aankomstuur, $aankomstminuut) || !validDate($vertrekjaar, $vertrekmaandNummer, $vertrekdag, $vertrekuur, $vertrekminuut)) { //Wrong dates, so indicate that incompleteData("aankomst- en/of vertrekdatum"); } //Dates valid, so create the actual string $start = new DateTime(); $start->setDate($aankomstjaar, $aankomstmaandNummer, $aankomstdag); $start->setTime($aankomstuur, $aankomstminuut); $startSTR = $start->format(DATE_TIME_FORMAT); $end = new DateTime(); $end->setDate($vertrekjaar, $vertrekmaandNummer, $vertrekdag); $end->setTime($vertrekuur, $vertrekminuut); $endSTR = $end->format(DATE_TIME_FORMAT); //create max end date of reservation $maxEndDate = new DateTime(); $maxEndDate->setDate($aankomstjaar, $aankomstmaandNummer, $aankomstdag);