Skip to content

Commit

Permalink
fixed the number of days for each month
Browse files Browse the repository at this point in the history
  • Loading branch information
smob123 committed Jul 1, 2018
1 parent c26d0f7 commit 7e371b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 48 deletions.
27 changes: 6 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 30 additions & 27 deletions src/components/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,55 @@ class Calendar extends Component {
a.push(
<div id="month">
<h3>{dates[i].name}</h3>
<ul id="days">{this.getDays()}</ul>
<ul id="days">{this.getDays(i)}</ul>
</div>
);
}

return a;
}

/*adds each day with its number in one div*/
getDays() {
let days = [];
let n = [];
let d = [];
var x = 0; //keeps track of numbers
let i = 0; //keeps track of days
var nums = this.ReturnDays();

for (var j = 12; j < 19; j++) {
days.push(
/*adds each day with its number in one vertical div*/
getDays(monthID) {
let dayNames = [];
let numbers = [];
let dayDiv = [];
let dayId = 0; //current day in the array

for (let j = 12; j < 19; j++) {
dayNames.push(
<li>{dates[j]}</li>
);
}

let nums = this.ReturnDays(dates[monthID].numOfDays); //get number of days in the current month

while (nums[x] !== 'X' && x < nums.length) { //while current element is not X
n.push(<p id="dayNums">{nums[x]}</p>);
n.push(<br />);
x++;
for (let x = 0; x < nums.length; x++) {
if (nums[x] !== 'X') {
numbers.push(<div><p id="dayNums">{nums[x]}</p><br /></div>);
} else {
if (dayId < dayNames.length) {
dayDiv.push(<div>{dayNames[dayId]}{numbers}</div>);
dayId++;
numbers = []; //reset to add numbers to the next day
}
}
d.push(<div>{days[i]}{n}</div>);
n = [];
i++;
x++; //move to the next element to add it to the next day
}
return d;

return dayDiv;
}

ReturnDays() {
var n = 0; // adds numbers to be implemented under each day
var x = []; //stores numbers
ReturnDays(numOfDays) {
let n = 0; // adds numbers to be implemented under each day
let x = []; //stores numbers

for (var i = 1; i <= 31; i++) { //loop the same amount as the number of days in a month
for (let i = 1; i <= numOfDays; i++) { //loop the same amount as the number of days in a month
n = i;
x.push(n); //add current element
while (n <= 31) {
while (n <= numOfDays) {
n += 7; // get the next week's date of the same day

if (n <= 31) { //a month cannot have more than 31 days
if (n <= numOfDays) { //a month cannot have more than 31 days
x.push(n);
}
}
Expand Down

0 comments on commit 7e371b3

Please sign in to comment.