Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. <div class="form-group">
  2. <label>Hora de inicío</label>';
  3.  
  4. // Make a DateTime object with the current date and time
  5. $today = new DateTime();
  6.  
  7. // Make an empty array to contain the hours
  8. $aHours = array();
  9.  
  10. // Make another DateTime object with the current date and time
  11. $oStart = new DateTime('now');
  12.  
  13. // Set current time to midnight
  14. $oStart->setTime(0, 0);
  15.  
  16. // Clone DateTime object (This is like 'copying' it)
  17. $oEnd = clone $oStart;
  18.  
  19. // Add 1 day (24 hours)
  20. $oEnd->add(new DateInterval("P1D"));
  21.  
  22. // Add each hour to an array
  23. while ($oStart->getTimestamp() < $oEnd->getTimestamp()) {
  24. $aHours[] = $oStart->format('H');
  25. $oStart->add(new DateInterval("PT1H"));
  26. }
  27.  
  28. // Create an array with halfs
  29. $halfs = array(
  30. '0',
  31. '30',
  32. );
  33.  
  34. // Get the current quarter
  35. $currentHalf = $today->format('i') - ($today->format('i') % 30);
  36. ?><div class="form-group">
  37. <select name="vaivaivai" id="">
  38. <option value="-1">Choose a time</option>
  39. <option value="$hora_inicio" selected><?= $hora_inicio ?></option>
  40. <?php foreach ($aHours as $hour): ?>
  41. <?php foreach ($halfs as $half): ?>
  42. <option value="<?= sprintf("%02d:%02d", $hour, $half); ?>" <?= ($hour == $today->format('H') && $half == $currentHalf) ? : ''; ?>>
  43. <?= sprintf("%02d:%02d", $hour, $half); ?>
  44. </option>
  45. <?php endforeach; ?>
  46. <?php endforeach; ?>
  47. </select></div><?php
  48.  
  49. if (isset($_SESSION["hora"])) {
  50. if ($_SESSION["hora"] == 1) {
  51. echo "<div class='alert alert-danger'>
  52. <strong>Erro!</strong> Hora inválida!
  53. </div>";
  54. $_SESSION["hora"] = 0;
  55. }
  56. }
  57.  
  58. echo '<div class="form-group">
  59. <label>Duração</label>
  60. <input class="form-control" name="duracao" value="' . $duracao . '">
  61. </div>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement