Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created February 7, 2026 20:57
Show Gist options
  • Select an option

  • Save goofballLogic/2c2dbb10c55169bbdf66764073c9de35 to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/2c2dbb10c55169bbdf66764073c9de35 to your computer and use it in GitHub Desktop.
// 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