Created
August 28, 2021 20:43
-
-
Save HNazmul-X/d37099bccab89cc2cf65795877fdc5f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dayCalculator = (addDay) => { | |
if(addDay){ | |
let [currMonth, currDay, currYear] = new Date().toLocaleDateString("en-US").split("/"); | |
console.log({currDay}) | |
const day31 = /1|3|5|7|8|10|12/; | |
const day30 = /4|6|9|11/; | |
for (let i = 0; i < addDay; i++) { | |
if (day31.test(currMonth.toString())) { | |
if (currDay === 31) { | |
currDay = 1; | |
if (currMonth === 12) { | |
currMonth = 1; | |
currYear++; | |
} else { | |
currMonth++; | |
} | |
} else { | |
currDay++; | |
} | |
} else if (day30.test(currMonth.toString())) { | |
if (currDay === 30) { | |
currDay = 1; | |
if (currMonth === 12) { | |
currMonth = 1; | |
currYear++; | |
} else { | |
currMonth++; | |
} | |
} else { | |
currDay++; | |
} | |
} else { | |
if (currDay === 28) { | |
currDay = 1; | |
if (currMonth === 12) { | |
currMonth = 1; | |
currYear++; | |
} else { | |
currMonth++; | |
} | |
} else { | |
currDay++; | |
} | |
} | |
} | |
return `${currDay}/ ${currMonth} / ${currYear}`; | |
} else { | |
return "please provide a number" | |
} | |
}; | |
console.log(dayCalculator(730)); |
Author
HNazmul-X
commented
Aug 28, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment