Skip to content

Commit b711295

Browse files
author
Brad Berger
committed
Fixes issue #18 bad dates
1 parent 3a79ab1 commit b711295

11 files changed

+79
-31
lines changed

.eslintrc

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
rules:
2-
indent:
3-
- 2
4-
quotes:
5-
- 2
6-
- double
7-
linebreak-style:
8-
- 2
9-
- unix
10-
semi:
11-
- 2
12-
- always
13-
globals:
14-
angular: false
15-
env:
16-
browser: true
17-
extends: 'eslint:recommended'
1+
{
2+
"rules": {
3+
"indent": [2],
4+
"quotes": [2, "double"],
5+
"linebreak-style": [2, "unix"],
6+
"semi": [2, "always"]
7+
},
8+
"globals": {
9+
"angular": false
10+
},
11+
"env": {
12+
"browser": true
13+
},
14+
"extends": "eslint:recommended"
15+
}

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.8
2+
3+
- Fixes bug with incorrect use of one-time bindings, resulting in the
4+
dates not updating.
5+
16
## 0.2.7
27

38
- Adds selection of multiple dates

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "material-calendar",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"homepage": "https://github.com/bradberger/material-calendar",
55
"keywords": "angular material design calendar ngCalendar mdCalendar calendarMd calendar-md md-calendar ng-calendar",
66
"authors": [

dist/angular-material-calendar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<md-content layout='column' layout-fill flex md-swipe-left='next()' md-swipe-right='prev()'><md-toolbar><div class='md-toolbar-tools' layout='row'><md-button ng-click='prev()'>&laquo;</md-button><div flex></div><h2 class='calendar-md-title'><span>{{ calendar.start | date:titleFormat:timezone }}</span></h2><div flex></div><md-button ng-click='next()'>&raquo;</md-button></div></md-toolbar><!-- agenda view --><md-content ng-if='weekLayout === columnWeekLayout' class='agenda'><div ng-repeat='week in calendar.weeks track by $index'><div ng-if='sameMonth(day)' ng-class='{ active: active === day }' ng-click='handleDayClick(day)' ng-repeat='day in week' layout><md-tooltip>{{ ::day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ ::day | date:dayFormat:timezone }}</div><div flex ng-bind-html='::getDayContent(day)'></div></div></div></md-content><!-- calendar view --><md-content ng-if='weekLayout !== columnWeekLayout' flex layout='column' class='calendar'><div ng-if='weekLayout != columnWeekLayout' layout='row' layout-fill class='subheader'><div layout-padding class='subheader-day' flex ng-repeat='day in calendar.weeks[0]'><md-tooltip>{{ ::day | date:dayLabelTooltipFormat:timezone }}</md-tooltip>{{ ::day | date:dayLabelFormat:timezone }}</div></div><div ng-if='weekLayout != columnWeekLayout' ng-repeat='week in calendar.weeks track by $index' flex layout='row' layout-fill><div tabindex='{{ ::sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{&quot;disabled&quot; : ! sameMonth(day), &quot;active&quot;: isActive(day), &quot;md-whiteframe-12dp&quot;: hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave='hover = false' ng-mouseenter='hover = true'><md-tooltip>{{ ::day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ ::day | date:dayFormat:timezone }}</div><div flex ng-bind-html='getDayContent(day)'></div></div></div></md-content></md-content>
1+
<md-content layout='column' layout-fill flex md-swipe-left='next()' md-swipe-right='prev()'><md-toolbar><div class='md-toolbar-tools' layout='row'><md-button ng-click='prev()'>&laquo;</md-button><div flex></div><h2 class='calendar-md-title'><span>{{ calendar.start | date:titleFormat:timezone }}</span></h2><div flex></div><md-button ng-click='next()'>&raquo;</md-button></div></md-toolbar><!-- agenda view --><md-content ng-if='weekLayout === columnWeekLayout' class='agenda'><div ng-repeat='week in calendar.weeks track by $index'><div ng-if='sameMonth(day)' ng-class='{ active: active === day }' ng-click='handleDayClick(day)' ng-repeat='day in week' layout><md-tooltip>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ day | date:dayFormat:timezone }}</div><div flex ng-bind-html='getDayContent(day)'></div></div></div></md-content><!-- calendar view --><md-content ng-if='weekLayout !== columnWeekLayout' flex layout='column' class='calendar'><div ng-if='weekLayout != columnWeekLayout' layout='row' layout-fill class='subheader'><div layout-padding class='subheader-day' flex ng-repeat='day in calendar.weeks[0]'><md-tooltip>{{ day | date:dayLabelTooltipFormat:timezone }}</md-tooltip>{{ day | date:dayLabelFormat:timezone }}</div></div><div ng-if='weekLayout != columnWeekLayout' ng-repeat='week in calendar.weeks track by $index' flex layout='row' layout-fill><div tabindex='{{ sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{&quot;disabled&quot; : ! sameMonth(day), &quot;active&quot;: isActive(day), &quot;md-whiteframe-12dp&quot;: hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave='hover = false' ng-mouseenter='hover = true'><md-tooltip>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ day | date:dayFormat:timezone }}</div><div flex ng-bind-html='getDayContent(day)'></div></div></div></md-content></md-content>

dist/angular-material-calendar.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var eslint = require("gulp-eslint");
1212
var size = require("gulp-size");
1313
var replace = require("gulp-replace");
1414
var protractor = require("gulp-protractor").protractor;
15+
var Karma = require("karma").Server;
1516

1617
function p(path) {
1718
return __dirname + (path.charAt(0) === "/" ? "" : "/") + path;
@@ -65,6 +66,13 @@ gulp.task("scss", function() {
6566
.pipe(connect.reload());
6667
});
6768

69+
gulp.task("karma:tdd", function(done) {
70+
new Karma({
71+
configFile: __dirname + "/karma.conf.js",
72+
singleRun: false
73+
}, done).start();
74+
});
75+
6876
gulp.task("test", ["js:lint-ci"], function() {
6977
connect.server({ root: "website", port: 3000 });
7078
gulp
@@ -86,4 +94,4 @@ gulp.task("watch", function() {
8694
gulp.watch(p("src/**/*"), ["js:lint", "build"]);
8795
});
8896

89-
gulp.task("default", ["build", "connect", "watch"]);
97+
gulp.task("default", ["build", "karma:tdd", "connect", "watch"]);

karma.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module.exports = function(config) {
2121
"test/unit/**/*.spec.js"
2222
],
2323

24+
autoWatch: true,
25+
2426
// list of files to exclude
2527
exclude: [
2628
],

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-material-calendar",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"description": "A calendar directive for AngularJS and Angular Material Design",
55
"main": "gulpfile.js",
66
"scripts": {

src/angular-material-calendar.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ <h2 class='calendar-md-title'><span>{{ calendar.start | date:titleFormat:timezon
1212
<md-content ng-if='weekLayout === columnWeekLayout' class='agenda'>
1313
<div ng-repeat='week in calendar.weeks track by $index'>
1414
<div ng-if="sameMonth(day)" ng-class='{ active: active === day }' ng-click='handleDayClick(day)' ng-repeat='day in week' layout>
15-
<md-tooltip>{{ ::day | date:dayTooltipFormat:timezone }}</md-tooltip>
16-
<div>{{ ::day | date:dayFormat:timezone }}</div>
17-
<div flex ng-bind-html='::getDayContent(day)'></div>
15+
<md-tooltip>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip>
16+
<div>{{ day | date:dayFormat:timezone }}</div>
17+
<div flex ng-bind-html='getDayContent(day)'></div>
1818
</div>
1919
</div>
2020
</md-content>
2121
<!-- calendar view -->
2222
<md-content ng-if='weekLayout !== columnWeekLayout' flex layout="column" class='calendar'>
2323
<div ng-if='weekLayout != columnWeekLayout' layout='row' layout-fill class='subheader'>
2424
<div layout-padding class='subheader-day' flex ng-repeat='day in calendar.weeks[0]'>
25-
<md-tooltip>{{ ::day | date:dayLabelTooltipFormat:timezone }}</md-tooltip>
26-
{{ ::day | date:dayLabelFormat:timezone }}
25+
<md-tooltip>{{ day | date:dayLabelTooltipFormat:timezone }}</md-tooltip>
26+
{{ day | date:dayLabelFormat:timezone }}
2727
</div>
2828
</div>
2929
<div ng-if='weekLayout != columnWeekLayout' ng-repeat='week in calendar.weeks track by $index' flex layout='row' layout-fill>
30-
<div tabindex='{{ ::sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{"disabled" : ! sameMonth(day), "active": isActive(day), "md-whiteframe-12dp": hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave="hover = false" ng-mouseenter="hover = true">
31-
<md-tooltip>{{ ::day | date:dayTooltipFormat:timezone }}</md-tooltip>
32-
<div>{{ ::day | date:dayFormat:timezone }}</div>
30+
<div tabindex='{{ sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{"disabled" : ! sameMonth(day), "active": isActive(day), "md-whiteframe-12dp": hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave="hover = false" ng-mouseenter="hover = true">
31+
<md-tooltip>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip>
32+
<div>{{ day | date:dayFormat:timezone }}</div>
3333
<div flex ng-bind-html="getDayContent(day)"></div>
3434
</div>
3535
</div>

src/angular-material-calendar.js

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ angular.module("materialCalendar").service("Calendar", ["$filter", function($fil
7878
return !date.getDay();
7979
};
8080

81+
// Month should be the javascript indexed month, 0 is January, etc.
8182
this.init = function(year, month) {
8283

8384
if (year) {

test/unit/calendarService.spec.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
/* global inject, module */
33
describe("calendar service", function() {
44

5+
var $date;
56
var Calendar;
67

78
beforeEach(module("materialCalendar"));
89

9-
beforeEach(inject(function(_Calendar_){
10+
beforeEach(inject(function(_Calendar_, _$filter_){
1011
Calendar = new _Calendar_();
12+
$date = function(year, month, day) {
13+
return _$filter_("dateToGmt")(new Date(year, month, day, 0, 0));
14+
};
1115
}));
1216

1317
it("should have all public methods defined", function() {
@@ -28,4 +32,34 @@ describe("calendar service", function() {
2832
expect(angular.isArray(Calendar.dates)).toBe(true);
2933
});
3034

35+
it("should start with the correct dates in October 2015", function() {
36+
Calendar.init(2015, 9);
37+
expect(angular.equals(Calendar.start, $date(2015, 9, 1))).toBe(true);
38+
expect(angular.equals(Calendar.weeks[0][0], $date(2015, 8, 27))).toBe(true);
39+
});
40+
41+
it("should start with the correct dates in November 2015", function() {
42+
Calendar.init(2015, 10);
43+
expect(angular.equals(Calendar.start, $date(2015, 10, 1))).toBe(true);
44+
expect(angular.equals(Calendar.weeks[0][0], $date(2015, 10, 1))).toBe(true);
45+
});
46+
47+
it("should start with the correct dates in July 2016", function() {
48+
Calendar.init(2016, 6);
49+
expect(angular.equals(Calendar.start, $date(2016, 6, 1))).toBe(true);
50+
expect(angular.equals(Calendar.weeks[0][0], $date(2016, 5, 26))).toBe(true);
51+
});
52+
53+
it("should start with the correct dates in March 2017", function() {
54+
Calendar.init(2017, 2);
55+
expect(angular.equals(Calendar.start, $date(2017, 2, 1))).toBe(true);
56+
expect(angular.equals(Calendar.weeks[0][0], $date(2017, 1, 26))).toBe(true);
57+
});
58+
59+
it("should start with the correct dates in April 2018", function() {
60+
Calendar.init(2018, 3);
61+
expect(angular.equals(Calendar.start, $date(2018, 3, 1))).toBe(true);
62+
expect(angular.equals(Calendar.weeks[0][0], $date(2018, 3, 1))).toBe(true);
63+
});
64+
3165
});

0 commit comments

Comments
 (0)