Last active
August 10, 2021 11:30
-
-
Save kirpalmakanga/36dd9891b72b7cd5b03d4b4e07cfb927 to your computer and use it in GitHub Desktop.
Get date of intervals starts
This file contains 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
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(); | |
} |
This file contains 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
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