Skip to content

Instantly share code, notes, and snippets.

@facumartig
Created August 2, 2013 02:12
Show Gist options
  • Save facumartig/6137004 to your computer and use it in GitHub Desktop.
Save facumartig/6137004 to your computer and use it in GitHub Desktop.
var d = new Date();
var day = d.getDate(),
month = d.getMonth() + 1,
year = d.getFullYear(),
days_number = daysInMonth(month, year),
actual_d = d.getDate(),
actual_m = d.getMonth() + 1,
actual_y = d.getFullYear();
function firstDay(month, year) {
return new Date(year, (month - 1), 1).getDay(); // Sunday is 0, Monday is 1...
}
$("span#mes").text(m_text[month]);
$("span#anio").text(year);
var diap = 1;
firstDay = firstDay(m, y);
for (i = 1; i <= 7; i++) {
if (firstDay === 0) {
firstDay = 7;
}
if (i < firstDay) {
tbody.append("<td><span></span></td>");
}
else {
tbody.append("<td id=\"" + y + "-" + m + "-" + diap + "\"><span><a href=\"#myModal\" role=\"button\" class=\"days\" data-toggle=\"modal\">" + diap + "</a></span></td>");
diap++;
}
}
tbody.wrapInner("<tr>");
for (i = 1; i <= days_number; i++) {
if (y === actual_y && m === actual_m && diap === actual_d) {
tbody.append("<td id=\"" + y + "-" + m + "-" + diap + "\" class=\"actual\"><span><a href=\"#myModal\" role=\"button\" class=\"days\" data-toggle=\"modal\">" + diap + "</a></span></td>");
}
else {
tbody.append("<td id=\"" + y + "-" + m + "-" + diap + "\"><span><a href=\"#myModal\" role=\"button\" class=\"days\" data-toggle=\"modal\">" + diap + "</a></span></td>");
}
if (i % 7 === 0) { tbody.append("</tr><tr>"); }
if (diap === days_number) { break; }
diap++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment