My Prog Adventures

By Mymedu

36 1 0

I am also a programmer. I have been intending to post some of my scripts on here. I can teach math and progra... More

factsofnum.java
bank.java
translator.js
userprofiles.js
snakecharm.java
snakecharmer.java
selentest.java
loadeditfile.js
calendarappmod.js
fractplot.java
csvpredtrain.py
slfchkalg.java
square enix christmas in html
powersum.java
New invention posting #1: 2 jet engine improvements

calendar.js

0 0 0
By Mymedu

function calculate(){
document.getElementById("calendar-dates").innerHTML='';
//Get the initial date and end date
var i= document.getElementById('initial_date').value
var initial_date = new Date(i)
initial_date.setDate(initial_date.getDate()+1)
n_days = document.getElementById('days').value
console.log(n_days)
if(n_days==''){alert("Ingresa el número de días")
return}
var end_date  = getEndDate(initial_date, n_days)

//declare constants
var month_name = ['January','February','March','April','May','June','July','August','September','October','November','December'];var day_name = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];

//get initial values
while(initial_date.getTime()<end_date.getTime()){
//get end of the month
var month = initial_date.getMonth();  
var year = initial_date.getFullYear();
var end_of_month = new Date(year, month+1, 0);

//get day number and day of the week
var first_date = initial_date.getDate();
var tmp = initial_date.toDateString();
var first_day = tmp.substring(0, 3); //Mon
var day_no = day_name.indexOf(first_day);   //1

//Evalue if end of month is mayor than end date
if(end_of_month.getTime()<=end_date.getTime()){
var days = end_of_month.getDate();
initial_date = new Date(end_of_month.setDate(end_of_month.getDate()+1));}
else{var days = end_date.getDate();
initial_date = new Date(end_date.setDate(end_date.getDate()+1));}
var title = month_name[month]+" "+year;
var calendar = get_calendar(first_date ,day_no, days, title);
document.getElementById("calendar-dates").appendChild(calendar);}}

function getEndDate(date, days){
var new_date = new Date(date);
new_date.setDate(new_date.getDate() + parseInt(days));
return new_date;}

function get_calendar(first_date, day_no, days, title){
var table = document.createElement('table');
table.setAttribute("class", "col-xs-4");
var tr = document.createElement('tr');
var td = document.createElement('td');
td.innerHTML = title;
td.setAttribute("colspan", 7)
tr.appendChild(td);
table.appendChild(tr);
tr = document.createElement('tr');
//row for the day letters
for(var c=0; c<=6; c++){
var td = document.createElement('td');
td.innerHTML = "SMTWTFS"[c];
tr.appendChild(td);}
table.appendChild(tr);

//create 2nd row
tr = document.createElement('tr');
var c;for(c=0; c<=6; c++){if(c == day_no){break;}
var td = document.createElement('td');
td.innerHTML = "";td.className = 'novalue';tr.appendChild(td);}

var count = first_date;
for(; c<=6; c++){
var td = document.createElement('td');
td.innerHTML = count;
if(c==0 || c==6){td.className = 'weekend';}
else{td.className = 'day';}
count++;tr.appendChild(td);}
   table.appendChild(tr);

for(var r=3; r<=7; r++){
tr = document.createElement('tr');
for(var c=0; c<=6; c++){if(count > days){
table.appendChild(tr);return table;}

var td = document.createElement('td');
td.innerHTML = count;
if(c==0 || c==6){td.className = 'weekend';}
else{td.className = 'day';}
count++;tr.appendChild(td);}
   table.appendChild(tr);}return table;}

//Original by More Nob

Continue Reading

You'll Also Like

8.1M 342K 52
"I hope you realize you made the worst f**king decision of your life." She could feel his cold icy blue eyes piercing through her soul. "I didn't as...
22.8K 1.9K 45
Her life has never been more busy. On the verge of a global business expansion and raising eight royal kids, Futhi is hit with the surprise of a life...
55.1M 1.8M 66
Henley agrees to pretend to date millionaire Bennett Calloway for a fee, falling in love as she wonders - how is he involved in her brother's false c...
3.9M 159K 69
Highest rank: #1 in Teen-Fiction and sci-fi romance, #1 mindreader, #2 humor Aaron's special power might just be the coolest- or scariest- thing ever...