Skip to content

Commit

Permalink
add getMonthDays()
Browse files Browse the repository at this point in the history
  • Loading branch information
itmor committed May 29, 2020
1 parent d15e513 commit c5997ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/calendar-array.min.js

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

27 changes: 26 additions & 1 deletion src/calendar-array.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
class CalendarArray {
getCalendar(...dates) {
if (this.#isValidDateArg(dates)) {
console.log('is valid');
this.#createCalendarArray(dates);
}
}

#createCalendarArray(dates) {
for (let date of dates) {

for (let i = 0; i < date.length; i++) {
if (i === 0) {
const year = date[0];
} else {

}
}
}
}

#getMonthDays(year, month) {
// Correct date 2020, 12 | Wrong date 99999, 99
if (String(year).length < 5 && String(month).match(/^([1-9]|1[0-2])$/) !== null) {
const date = new Date(year, month - 1);
const daysValue = new Date(date.getFullYear(), date.getMonth()+1, 0);

return daysValue.getDate();
}

throw new Error('Wrong date');
}

#isValidDateArg(dates) {
// Sample correct arguments [[2020, 3], [2012], [2007]]
if (dates.length > 0) {
Expand Down

0 comments on commit c5997ee

Please sign in to comment.