Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Created August 26, 2025 13:37
Show Gist options
  • Save erkobridee/3ce6aef5b43c08ea75f979ff2ffceff6 to your computer and use it in GitHub Desktop.
Save erkobridee/3ce6aef5b43c08ea75f979ff2ffceff6 to your computer and use it in GitHub Desktop.
/*
Day.js - format
https://day.js.org/docs/en/display/format
*/
const getLastSundaysOfYear = (year = new Date().getFullYear()) => {
const currentYear = dayjs().year(year);
const lastSundaysOfYearMap = new Map();
for(let i = 0; i < 12; i++) {
const lastSundayOfMonth = currentYear.month(i).endOf('month').day(0);
lastSundaysOfYearMap.set(i, lastSundayOfMonth);
}
return lastSundaysOfYearMap;
}
const lastSundaysOfYearMap = getLastSundaysOfYear(2025);
/*
console.log(Object.fromEntries(lastSundaysOfYearMap));
console.log(Array.from(lastSundaysOfYearMap.values()));
*/
const lastSundaysOfYearMapFormatted = lastSundaysOfYearMap.values().reduce((acc, sunday) => {
acc[Number(sunday.format('M'))] = sunday.format('YYYY-MM-DD HH:mm:ss ZZ');
return acc;
}, {});
console.log(JSON.stringify(lastSundaysOfYearMapFormatted, null, 2));
/*
output:
{
"1": "2025-01-26 23:59:59 +0100",
"2": "2025-02-23 23:59:59 +0100",
"3": "2025-03-30 23:59:59 +0200",
"4": "2025-04-27 23:59:59 +0200",
"5": "2025-05-25 23:59:59 +0200",
"6": "2025-06-29 23:59:59 +0200",
"7": "2025-07-27 23:59:59 +0200",
"8": "2025-08-31 23:59:59 +0200",
"9": "2025-09-28 23:59:59 +0200",
"10": "2025-10-26 23:59:59 +0100",
"11": "2025-11-30 23:59:59 +0100",
"12": "2025-12-28 23:59:59 +0100"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment