Skip to content

Instantly share code, notes, and snippets.

@kirpalmakanga
Last active August 10, 2021 11:30
Show Gist options
  • Save kirpalmakanga/36dd9891b72b7cd5b03d4b4e07cfb927 to your computer and use it in GitHub Desktop.
Save kirpalmakanga/36dd9891b72b7cd5b03d4b4e07cfb927 to your computer and use it in GitHub Desktop.
Get date of intervals starts
const getStartOfQuarter = date => {
const
quarters = {
1: 1,
2: 4,
3: 7,
4: 10
},
d = date ? new Date(date) : new Date(),
q = Math.ceil((d.getMonth() + 1) / 3),
year = d.getFullYear(),
dateArgs = [
year,
quarters[q],
1
];
return new Date(...dateArgs).getTime();
}
const getStartOfSemester = date => {
const
d = date ? new Date(date) : new Date(),
semester = Math.ceil((d.getMonth() + 1) / 6),
year = d.getFullYear(),
dateArgs = [
year,
semester === 1 ? 1 : 7,
1
];
return new Date(...dateArgs).getTime();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment