Created
June 2, 2015 14:04
-
-
Save torsak/b46372d0d88e611ee7b6 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/qihaza
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="KDApp"> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="CalCtrl"> | |
<table border="1"> | |
<tr ng-repeat="week in datesGroupedByWeek"> | |
<td ng-repeat="date in week">{{date}}</td> | |
</tr> | |
</table> | |
<button>Prev</button> | |
<button>Today</button> | |
<button>Next</button> | |
<script id="jsbin-javascript"> | |
var KDApp = angular.module('KDApp', []); | |
KDApp.controller('CalCtrl', function($scope) { | |
var startDate = '2015-07-01'; | |
var current = new Date(startDate); | |
current.setHours(12); // prevent repeated date because of timezone bug | |
var prevMonthDateCount = current.getDay(); | |
current.setDate(current.getDate() - prevMonthDateCount); | |
var dates = []; | |
var i; | |
for (i = 0; i < 42; i++) { | |
dates[i] = new Date(current); | |
current.setDate(current.getDate() + 1); | |
} | |
var datesGroupedByWeek = []; | |
var week = []; | |
for (i = 0; i < 42; i++) { | |
week.push(dates[i].getDate()); | |
if (0 === ((i + 1) % 7)) { | |
datesGroupedByWeek.push(week); | |
week = []; | |
} | |
} | |
console.log(datesGroupedByWeek); | |
$scope.datesGroupedByWeek = datesGroupedByWeek; | |
}); | |
// Leap year has additional day in Feb | |
var isLeapYear = function(year) { | |
return ((year % 400 === 0) || ((year % 4 === 0) && (year % 100 !== 0))); | |
}; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var KDApp = angular.module('KDApp', []); | |
KDApp.controller('CalCtrl', function($scope) { | |
var startDate = '2015-07-01'; | |
var current = new Date(startDate); | |
current.setHours(12); // prevent repeated date because of timezone bug | |
var prevMonthDateCount = current.getDay(); | |
current.setDate(current.getDate() - prevMonthDateCount); | |
var dates = []; | |
var i; | |
for (i = 0; i < 42; i++) { | |
dates[i] = new Date(current); | |
current.setDate(current.getDate() + 1); | |
} | |
var datesGroupedByWeek = []; | |
var week = []; | |
for (i = 0; i < 42; i++) { | |
week.push(dates[i].getDate()); | |
if (0 === ((i + 1) % 7)) { | |
datesGroupedByWeek.push(week); | |
week = []; | |
} | |
} | |
console.log(datesGroupedByWeek); | |
$scope.datesGroupedByWeek = datesGroupedByWeek; | |
}); | |
// Leap year has additional day in Feb | |
var isLeapYear = function(year) { | |
return ((year % 400 === 0) || ((year % 4 === 0) && (year % 100 !== 0))); | |
};</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var KDApp = angular.module('KDApp', []); | |
KDApp.controller('CalCtrl', function($scope) { | |
var startDate = '2015-07-01'; | |
var current = new Date(startDate); | |
current.setHours(12); // prevent repeated date because of timezone bug | |
var prevMonthDateCount = current.getDay(); | |
current.setDate(current.getDate() - prevMonthDateCount); | |
var dates = []; | |
var i; | |
for (i = 0; i < 42; i++) { | |
dates[i] = new Date(current); | |
current.setDate(current.getDate() + 1); | |
} | |
var datesGroupedByWeek = []; | |
var week = []; | |
for (i = 0; i < 42; i++) { | |
week.push(dates[i].getDate()); | |
if (0 === ((i + 1) % 7)) { | |
datesGroupedByWeek.push(week); | |
week = []; | |
} | |
} | |
console.log(datesGroupedByWeek); | |
$scope.datesGroupedByWeek = datesGroupedByWeek; | |
}); | |
// Leap year has additional day in Feb | |
var isLeapYear = function(year) { | |
return ((year % 400 === 0) || ((year % 4 === 0) && (year % 100 !== 0))); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment