frequi_origin/src/shared/timemath.ts
2020-10-02 07:07:57 +02:00

18 lines
340 B
TypeScript

const ROUND_UP = 2;
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,
};