Created
February 7, 2026 20:57
-
-
Save goofballLogic/2c2dbb10c55169bbdf66764073c9de35 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
| // thanks: https://stackoverflow.com/a/16353241 | |
| const isLeapYear = year => | |
| ( | |
| // divisible by 4 but not 100 | |
| (year % 4 == 0) && (year % 100 != 0) | |
| ) || ( | |
| // divisible by 400 | |
| year % 400 == 0 | |
| ); | |
| const isPerfectMonth = year => | |
| // must be a year where Feb has 28 days | |
| !isLeapYear(year) | |
| && | |
| // starts on either a Sunday or a Monday | |
| new Date(year, 1, 1).getDay() < 2; | |
| const nextPerfectMonth = year => | |
| isPerfectMonth(year) ? year : nextPerfectMonth(year + 1); | |
| const previousPerfectMonth = year => | |
| isPerfectMonth(year) ? year : previousPerfectMonth(year - 1); | |
| const nearestPerfectMonths = year => | |
| ({ | |
| prev: `${previousPerfectMonth(year)}-02`, | |
| next: `${nextPerfectMonth(year + 1)}-02` | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment