1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/time-utils.ts
2022-11-04 09:30:02 +01:00

17 lines
361 B
TypeScript

import { startOfHour, subHours } from 'date-fns';
export interface HourBucket {
timestamp: Date;
}
export function generateHourBuckets(hours: number): HourBucket[] {
const start = startOfHour(new Date());
const result = [];
for (let i = 0; i < hours; i++) {
result.push({ timestamp: subHours(start, i) });
}
return result;
}