Last active
May 11, 2022 15:59
-
-
Save mantismamita/3f364280b23967aa955e1129d7aebb6b to your computer and use it in GitHub Desktop.
js algorithm utility functions
This file contains hidden or 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
// greatest common denominator | |
const gcd = (a, b) => b ? gcd(b, a % b) : a | |
// lowest common multiplier | |
const lcm = (a, b) => (a * b)/ gcd(a, b) | |
// some Date stuff for safe-keeping | |
const weekdayMonthFormat = { | |
weekday: 'long', | |
day: 'numeric', | |
month: 'long', | |
timeZone: 'Europe/Paris', | |
} as Intl.DateTimeFormatOptions; | |
const getFrenchMonths = () => { | |
const now = new Date(Date.now()); | |
const availableDates = []; | |
for (let i = (-1 * 7); i <= 0; i++) { | |
const tempDate = new Date(Number(now)); | |
tempDate.setDate(now.getDate() + i); | |
tempDate.setHours(12); | |
const tempTime = ~~(tempDate.getTime() / 1e3); | |
availableDates.push(getDateFromTimestamp(tempTime, weekdayMonthFormat)); | |
} | |
return availableDates; | |
}; | |
const getMidnightOfTimestamp = (time: number): number => { | |
const midnight = new Date(time * 1e3).setHours(0, 0, 0, 0); | |
return midnight / 1e3; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment