Advertisement
aslv

Awesome Calendar

Aug 17th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.38 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Awesome Calendar</title>
  5.         <style type="text/css">
  6.             header {
  7.                 text-align: center;
  8.             }
  9.             body > header, body > section {
  10.                 margin: 5px auto;
  11.                 width: 70%;
  12.             }
  13.             body > header {
  14.                 font-size: 1.5em;
  15.                 border-bottom: 2px solid gray;
  16.             }
  17.             h1 {
  18.                 margin: 0;
  19.                 font-family: Arial, sans-serif;
  20.             }
  21.             section {
  22.                 display: flex;
  23.                 flex-wrap: wrap;
  24.                 justify-content: center;
  25.                 align-content: flex-start;
  26.             }
  27.             div {
  28.                 margin: 10px;
  29.             }
  30.             div > header {
  31.                 border-bottom: 1px solid gray;
  32.             }
  33.             th {
  34.                 border-bottom: 1px solid gray;
  35.             }
  36.             th:last-child {
  37.                 color: red;
  38.             }
  39.             td {
  40.                 text-align: right;
  41.                 font-size: 1.1em;
  42.             }
  43.         </style>
  44.     </head>
  45.     <body>
  46.         <header>
  47.             <h1><?= date('Y'); ?></h1>
  48.         </header>
  49.         <section>
  50.             <?php
  51.             date_default_timezone_set('Europe/Sofia');
  52.  
  53.             $theRequiredYear = date('Y');
  54.             $yearBegin = new DateTime($theRequiredYear . '-01-01');
  55.             $yearEnd = clone $yearBegin;
  56.             $yearEnd->add(DateInterval::createFromDateString('1 year'));
  57.  
  58.             $months = new DatePeriod($yearBegin, DateInterval::createFromDateString('1 month'), $yearEnd);
  59.             //var_dump($months);
  60.             $indexMonths = -1;
  61.             $prev = null;
  62.             foreach ($months as $month) {
  63.                 $indexMonths++;
  64.                 if ($indexMonths === 0) {
  65.                     $prev = $month;
  66.                     continue;
  67.                 }
  68.                 $output = '';
  69.                 $daysInMonth = new DatePeriod($prev, DateInterval::createFromDateString('1 day'), $month);
  70.                 $indexDays = 0;
  71.                 $numberOfWeeks = 0;
  72.                 $output .= '<div><header>';
  73.                 $output .= $prev->format('F');
  74.                 $output .= '</header><table><thead><tr>';
  75.                 $output .= '<th>Mo</th><th>Tu</th><th>We</th><th>Th</th><th>Fr</th><th>Sa</th><th>Su</th>';
  76.                 $output .= '</tr></thead><tbody><tr>';
  77.                 foreach ($daysInMonth as $day) {
  78.                     //echo $day->format('d M l') . PHP_EOL;
  79.                     $weekDay = $day->format('N');
  80.                     if ($indexDays === 0) {
  81.                         $output .= '<td colspan="' . $weekDay . '">';
  82.                     }
  83.                     else {
  84.                         $output .= '<td>';
  85.                     }
  86.                     $output .= $day->format('j') . '</td>';
  87.                     if ($weekDay == 7) {
  88.                         $output .= '</tr><tr>';
  89.                     }
  90.                     $indexDays++;
  91.                 }
  92.                 $output .= '</tr></tbody></table></div>';
  93.                 echo $output;
  94.                 $prev = $month;
  95.             }
  96.             $output = '';
  97.             $daysInMonth = new DatePeriod($prev, DateInterval::createFromDateString('1 day'), $yearEnd);
  98.             $indexDays = 0;
  99.             $numberOfWeeks = 0;
  100.             $output .= '<div><header>';
  101.             $output .= $prev->format('F');
  102.             $output .= '</header><table><thead><tr>';
  103.             $output .= '<th>Mo</th><th>Tu</th><th>We</th><th>Th</th><th>Fr</th><th>Sa</th><th>Su</th>';
  104.             $output .= '</tr></thead><tbody><tr>';
  105.             foreach ($daysInMonth as $day) {
  106.                 //echo $day->format('d M l') . PHP_EOL;
  107.                 $weekDay = $day->format('N');
  108.                 if ($indexDays === 0) {
  109.                     $output .= '<td colspan="' . $weekDay . '">';
  110.                 }
  111.                 else {
  112.                     $output .= '<td>';
  113.                 }
  114.                 $output .= $day->format('j') . '</td>';
  115.                 if ($weekDay == 7) {
  116.                     $output .= '</tr><tr>';
  117.                 }
  118.                 $indexDays++;
  119.             }
  120.             $output .= '</tr></tbody></table></div>';
  121.             echo $output;
  122.             ?>
  123.         </section>
  124.     </body>
  125. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement