frequi_origin/src/shared/timemath.ts
2022-11-26 09:11:44 +01:00

18 lines
354 B
TypeScript

export const ROUND_UP = 2;
export const ROUND_DOWN = 3;
export function roundTimeframe(
timeframems: number,
timestamp: number,
direction: number = ROUND_DOWN,
) {
const offset = timestamp % timeframems;
return timestamp - offset + (direction === ROUND_UP ? timeframems : 0);
}
export default {
ROUND_UP,
ROUND_DOWN,
roundTimeframe,
};