Skip to content

Commit 2af976e

Browse files
committed
Merge pull request #201 from DanTalash/new-features
Fixing issue with month view when the first day is a Sunday
2 parents b7371e4 + 10f3064 commit 2af976e

File tree

6 files changed

+18
-24
lines changed

6 files changed

+18
-24
lines changed

app/scripts/datePickerUtils.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,18 @@ angular.module('datePicker').factory('datePickerUtils', function () {
2828
var startYear = m.year(),
2929
startMonth = m.month();
3030

31-
// set date to start of the week
31+
//Set date to the first day of the month
3232
m.date(1);
3333

34+
//Grab day of the week
3435
var day = m.day();
3536

3637
if (day === 0) {
37-
// day is sunday, let's get back to the previous week
38-
m.date(-5);
39-
} else {
40-
// day is not sunday, let's get back to the start of the week
41-
m.date(m.date() - day);
42-
}
43-
if (m.date() === 1) {
44-
// day is monday, let's get back to the previous week
38+
//If the first day of the month is a sunday, go back one week.
4539
m.date(-6);
40+
} else {
41+
//Otherwise, go back the required number of days to arrive at the previous sunday
42+
m.date(1 - day);
4643
}
4744

4845
var weeks = [];

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-datepicker",
33
"license": "MIT",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"main": [
66
"./dist/angular-datepicker.js",
77
"./dist/angular-datepicker.css"

dist/angular-datepicker.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,18 @@ var tz;
382382
var startYear = m.year(),
383383
startMonth = m.month();
384384

385-
// set date to start of the week
385+
//Set date to the first day of the month
386386
m.date(1);
387387

388+
//Grab day of the week
388389
var day = m.day();
389390

390391
if (day === 0) {
391-
// day is sunday, let's get back to the previous week
392-
m.date(-5);
393-
} else {
394-
// day is not sunday, let's get back to the start of the week
395-
m.date(m.date() - day);
396-
}
397-
if (m.date() === 1) {
398-
// day is monday, let's get back to the previous week
392+
//If the first day of the month is a sunday, go back one week.
399393
m.date(-6);
394+
} else {
395+
//Otherwise, go back the required number of days to arrive at the previous sunday
396+
m.date(1 - day);
400397
}
401398

402399
var weeks = [];

dist/angular-datepicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-datepicker",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"main": "dist/angular-datepicker.js",
55
"repository": {
66
"url": "https://github.com/g00fy-/angular-datepicker.git"

test/spec/datePickerUtilsTest.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ describe('Test date Picker Utils', function(){
3737
});
3838

3939
it('get visible weeks provided date', function(){
40-
var start = dateBuilder('2014-05-26T00:00:00+00:00'); // monday
41-
var end = dateBuilder('2014-07-06T00:00:00+00:00'); // sunday
42-
var chosen = ('2014-06-29T19:00:00+00:00'); // sunday
40+
var start = dateBuilder('2014-05-25T00:00:00+00:00'); // sunday
41+
var end = dateBuilder('2014-07-05T00:00:00+00:00'); // saturday
42+
var chosen = dateBuilder('2014-06-29T19:00:00+00:00'); // sunday
4343
var weeks = utils.getVisibleWeeks(chosen, constants.step);
4444

4545
expect(weeks).toBeDefined();

0 commit comments

Comments
 (0)