Skip to content

Instantly share code, notes, and snippets.

@finalclass
Created August 10, 2018 09:41
Show Gist options
  • Save finalclass/a674bb0fff4f7d018e33090b956aeac9 to your computer and use it in GitHub Desktop.
Save finalclass/a674bb0fff4f7d018e33090b956aeac9 to your computer and use it in GitHub Desktop.
Get bounds of a month (beginning of a month and the end of a month)
exports.getBeginningOfMonth = function getBeginningOfMonth(timestamp) {
const d = new Date(timestamp);
return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), 1, 0, 0, 0, 0);
};
exports.getEndOfMonth = function getEndOfMonth(timestamp) {
const d = new Date(timestamp);
const end = Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 1, 0, 0, 0);
return end - 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment