MCPcopy Create free account
hub / github.com/codemistic/Web-Development / CalendarControl

Function CalendarControl

calender/index.js:5–228  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3//Added previous month and next month view
4
5function CalendarControl() {
6 const calendar = new Date();
7 const calendarControl = {
8 localDate: new Date(),
9 prevMonthLastDate: null,
10 calWeekDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
11 calMonthName: [
12 "Jan",
13 "Feb",
14 "Mar",
15 "Apr",
16 "May",
17 "Jun",
18 "Jul",
19 "Aug",
20 "Sep",
21 "Oct",
22 "Nov",
23 "Dec",
24 ],
25 daysInMonth: function (month, year) {
26 return new Date(year, month, 0).getDate();
27 },
28 firstDay: function () {
29 return new Date(calendar.getFullYear(), calendar.getMonth(), 1);
30 },
31 lastDay: function () {
32 return new Date(calendar.getFullYear(), calendar.getMonth() + 1, 0);
33 },
34 firstDayNumber: function () {
35 return calendarControl.firstDay().getDay() + 1;
36 },
37 lastDayNumber: function () {
38 return calendarControl.lastDay().getDay() + 1;
39 },
40 getPreviousMonthLastDate: function () {
41 let lastDate = new Date(
42 calendar.getFullYear(),
43 calendar.getMonth(),
44 0
45 ).getDate();
46 return lastDate;
47 },
48 navigateToPreviousMonth: function () {
49 calendar.setMonth(calendar.getMonth() - 1);
50 calendarControl.attachEventsOnNextPrev();
51 },
52 navigateToNextMonth: function () {
53 calendar.setMonth(calendar.getMonth() + 1);
54 calendarControl.attachEventsOnNextPrev();
55 },
56 navigateToCurrentMonth: function () {
57 let currentMonth = calendarControl.localDate.getMonth();
58 let currentYear = calendarControl.localDate.getFullYear();
59 calendar.setMonth(currentMonth);
60 calendar.setYear(currentYear);
61 calendarControl.attachEventsOnNextPrev();
62 },

Callers

nothing calls this directly

Calls 2

logMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected