MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / getDayDiff

Method getDayDiff

Dynamic-Programming/FindMonthCalendar.js:71–98  ·  view source on GitHub ↗
(startDate, endDate)

Source from the content-addressed store, hash-verified

69 }
70
71 getDayDiff(startDate, endDate) {
72 if (this.isGreater(startDate, endDate) === null) {
73 return 0
74 } else if (this.isGreater(startDate, endDate) === true) {
75 const midDate = startDate
76 startDate = endDate
77 endDate = midDate
78 }
79 let diff = 0
80 while (startDate.year !== endDate.year) {
81 diff += isLeapYear(startDate.year) ? 366 : 365
82 startDate.year = startDate.year + 1
83 }
84 while (startDate.month !== endDate.month) {
85 if (startDate.month < endDate.month) {
86 if (isLeapYear(startDate.year))
87 diff += this.monthDaysLeap[startDate.month]
88 else diff += this.monthDays[startDate.month]
89 startDate.month = startDate.month + 1
90 } else {
91 if (isLeapYear(startDate.year))
92 diff -= this.monthDaysLeap[startDate.month - 1]
93 else diff -= this.monthDays[startDate.month - 1]
94 startDate.month = startDate.month - 1
95 }
96 }
97 return diff
98 }
99
100 generateMonthCal(date) {
101 const Month = this.parseDate(date)

Callers 1

generateMonthCalMethod · 0.95

Calls 2

isGreaterMethod · 0.95
isLeapYearFunction · 0.90

Tested by

no test coverage detected