Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                div.header
  div
    input(type="date", name="startdate", id="startdate")
    input(type="date", name="enddate", id="enddate")
    button(type="button", onClick="CalculateCalendar()") GO
  button(type="button", onClick="HideWeeks()", id="monthbtn") MONTH
#table
  .title
    h1 Timeline
  .table
    table
      thead
        tr#th-month
        tr#th-weeks
        tr#th-days
      tbody
        tr#th-data
              
            
!

CSS

              
                .header {
  display: flex;
  background-color: orange;
  padding: 1.3em;
  box-shadow: 0px 1px 5px gray;
  flex-wrap: wrap;
  justify-content: space-between;
}
.title {
  color: #2d73f3;
  background-color: whitesmoke;
  padding: 0.5em;
  text-align: center;
  text-transform: uppercase;
  font-size: 2em;
  letter-spacing: 45px;
  border-radius: 3px 3px 0 0;
}
#table {
  width: calc(100% - 1em);
  padding-bottom: 3em;
  margin: 0.5em;
}
.table {
  background-color: rgba(234, 234, 234, 0.1);
  border: 2px solid #edecef;
  min-height: 150px;
  overflow-x: overlay;
}
input {
  padding: 0.3em;
  margin-right: 0.5em;
  border-radius: 3px;
  border: none;
}
button {
  padding: 0.3em 1em;
  border: none;
  border-radius: 3px;
  box-shadow: 0px 0px 2px blue;
  background-color: blue;
  color: yellow;
}
#th-month th {
  border-bottom: 1px solid rgba(175,175,175,1);
}
#th-month th:nth-child(odd) {
  background-color: #ececec;
}
#th-month th:nth-child(even) {
  background-color: #ddd;
}
th {
  padding: 0.3em;
}
#th-days.inactive, #th-weeks.inactive {
  display: none;
}
#monthbtn.active {
  background-color: #fff;
  color: blue;
}
td {
  padding: 0.35em;
}
.wew {
  background-color: green;
}
.new {
  border-radius: 3px 0 0 3px;
}
.nen {
  border-radius: 0 3px 3px 0;
}
              
            
!

JS

              
                window.onload = () => {
  document.getElementById('startdate').min = new Date().toISOString().split("T")[0];
}

function leapYear(year) {
  if (year % 4 == 0) { return true; }
  else { return false }
}

function getDayName(a) {
  var weekday = new Array(7);
  weekday[0] = "Sunday";
  weekday[1] = "Monday";
  weekday[2] = "Tuesday";
  weekday[3] = "Wednesday";
  weekday[4] = "Thursday";
  weekday[5] = "Friday";
  weekday[6] = "Saturday";
  return weekday[a];
}

function getInfo(month, year) {
  var ar = new Array(12);
  ar[0] = '{"days":"31","mm":"0","month":"January","year":"'+year+'"}';
  ar[1] = (leapYear(year)) ? '{"days":"29","mm":"1","month":"February","year":"'+year+'"}' : '{"days":"28","mm":"1","month":"February","year":"'+year+'"}';
  ar[2] = '{"days":"31","mm":"2","month":"March","year":"'+year+'"}';
  ar[3] = '{"days":"30","mm":"3","month":"April","year":"'+year+'"}';
  ar[4] = '{"days":"31","mm":"4","month":"May","year":"'+year+'"}';
  ar[5] = '{"days":"30","mm":"5","month":"June","year":"'+year+'"}';
  ar[6] = '{"days":"31","mm":"6","month":"July","year":"'+year+'"}';
  ar[7] = '{"days":"31","mm":"7","month":"August","year":"'+year+'"}';
  ar[8] = '{"days":"30","mm":"8","month":"September","year":"'+year+'"}';
  ar[9] = '{"days":"31","mm":"9","month":"October","year":"'+year+'"}';
  ar[10] = '{"days":"30","mm":"10","month":"November","year":"'+year+'"}';
  ar[11] = '{"days":"31","mm":"11","month":"December","year":"'+year+'"}';
  return ar[month];
}

function createMonthHead(a, b, start, end){
  for(var m = 0; m <= a; m++){
    var mdate = JSON.parse(b[m]); 
    var minfo = JSON.parse(getInfo(mdate.month, mdate.year));
    var monthname = document.createElement("th");
    monthname.colSpan = minfo.days;
    monthname.append(minfo.month + " " + minfo.year);
    document.getElementById('th-month').append(monthname); 
    createDaysHead(minfo.days, minfo.mm, minfo.year);
    createData(minfo.days, minfo.mm, minfo.year, start, end);
  }
}
function createDaysHead(a, b, c){
  for(var x = 1; x <= a; x++){
    var week = document.createElement("th"),
    day = document.createElement("th");
    day.append(x);
    week.append(getDayName(new Date(c,b,x).getDay()).charAt(0)); 
    document.getElementById('th-weeks').append(week); 
    document.getElementById('th-days').append(day);  
  }
}
function createData(a, b, c, d, e){
  for(var x = 1; x <= a; x++){
    var th = document.createElement("td"), curdate = new Date(c, b, x);
    d.setHours(0,0,0,0); e.setHours(0,0,0,0); curdate.setHours(0,0,0,0);
    if(curdate.getTime() === d.getTime()){
      th.classList.add('new');
      th.classList.add('wew');
    } else if(curdate.getTime() === e.getTime()){
      th.classList.add('nen');
      th.classList.add('wew');
    } else if(curdate > d && curdate < e){
      th.classList.add('wew');
    }
    document.getElementById('th-data').append(th);
  }
}

function monthDiff(dateFrom, dateTo) {
  return dateTo.getMonth() - dateFrom.getMonth() + (12 * (dateTo.getFullYear() - dateFrom.getFullYear()));
}

function monthsBet(d1, d2) {
  var months = ['{"month":"'+d1.getMonth()+'","year":"'+d1.getFullYear()+'"}'];
  while (d2.getFullYear() != d1.getFullYear() || d2.getMonth() != d1.getMonth()) {
    var oldmonth = d1.getMonth();
    d1 = new Date(d1.getTime() + 86400000);
    if (oldmonth != d1.getMonth()) {
      months.push('{"month":"'+d1.getMonth()+'","year":"'+d1.getFullYear()+'"}');
    }
  }
  return months;
}

function CalculateCalendar() {
  try {
    var start = new Date(document.getElementById('startdate').value);
    var end = new Date(document.getElementById('enddate').value);
    var startyear = start.getFullYear();
    var endyear = start.getFullYear();
    var monthDiffirence = monthDiff(start, end);
    var monthsBetween = monthsBet(start, end);
    var start1stDay = new Date(startyear, start.getMonth(), 1);
    var end1stDay = new Date(endyear, end.getMonth(), 1);
    document.getElementById('th-month').innerHTML = "";
    document.getElementById('th-weeks').innerHTML = "";
    document.getElementById('th-days').innerHTML = "";
    createMonthHead(monthDiffirence, monthsBetween, start, end);
  } catch (err) {
    alert("err");
  }
}

function HideWeeks(){
  try {
    document.getElementById('th-weeks').classList.toggle("inactive");
    document.getElementById('th-days').classList.toggle("inactive");
    document.getElementById('monthbtn').classList.toggle("active");
  } catch (err) {
    alert(err);
  }
}
              
            
!
999px

Console