Skip to content

Commit

Permalink
First day of the Week #10
Browse files Browse the repository at this point in the history
- The calendar now has an option (firstDayOfWeek) to determine what day is the first, this option comes from 0 to 6, in which 0 is the Sunday and 6 is Saturday.
  • Loading branch information
jhonis committed Feb 8, 2016
1 parent 9170c97 commit 3061827
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ url: '',
events: [
{title: 'Event Title 1', description: 'Description 1', datetime: new Date(2016, 0, 12, 17)},
{title: 'Event Title 2', description: 'Description 2', datetime: new Date(2016, 0, 23, 16)}
]
],
firstDayOfWeek: 0
```
####Event Object Properties
```JavaScript
Expand All @@ -38,7 +39,8 @@ $('#calendar').eCalendar({
});

$('#calendar').eCalendar({url: 'loadCalendar',
weekDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']});
weekDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
firstDayOfWeek: 1}); // calendar starting on monday | (0 - 6: week days format)
```

PS: remember that in date object instantiation, like the code below, the month starts from 0 to 11 and generate a date: 31/01/2016
Expand Down
17 changes: 13 additions & 4 deletions js/jquery.e-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@

function print() {
loadEvents();
var dWeekDayOfMonthStart = new Date(dYear, dMonth, 1).getDay();
var dWeekDayOfMonthStart = new Date(dYear, dMonth, 1).getDay() - settings.firstDayOfWeek;
if (dWeekDayOfMonthStart < 0) {
dWeekDayOfMonthStart = 6 - ((dWeekDayOfMonthStart + 1) * -1);
}
var dLastDayOfMonth = new Date(dYear, dMonth + 1, 0).getDate();
var dLastDayOfPreviousMonth = new Date(dYear, dMonth + 1, 0).getDate() - dWeekDayOfMonthStart + 1;

Expand All @@ -109,10 +112,15 @@
cBody.append(cPrevious);
cBody.append(cMonth);
cBody.append(cNext);
for (var i = 0; i < settings.weekDays.length; i++) {
var dayOfWeek = settings.firstDayOfWeek;
for (var i = 0; i < 7; i++) {
if (dayOfWeek > 6) {
dayOfWeek = 0;
}
var cWeekDay = $('<div/>').addClass('c-week-day c-pad-top');
cWeekDay.html(settings.weekDays[i]);
cWeekDay.html(settings.weekDays[dayOfWeek]);
cBody.append(cWeekDay);
dayOfWeek++;
}
var day = 1;
var dayOfNextMonth = 1;
Expand Down Expand Up @@ -179,7 +187,8 @@
{title: 'Evento de Abertura', description: 'Abertura das Olimpíadas Rio 2016', datetime: new Date(2016, new Date().getMonth(), 12, 17)},
{title: 'Tênis de Mesa', description: 'BRA x ARG - Semifinal', datetime: new Date(2016, new Date().getMonth(), 23, 16)},
{title: 'Ginástica Olímpica', description: 'Classificatórias de equipes', datetime: new Date(2016, new Date().getMonth(), 31, 16)}
]
],
firstDayOfWeek: 0
};

}(jQuery));

0 comments on commit 3061827

Please sign in to comment.