| 12345678910111213141516171819 |
- // box-stats-api/src/feature/time-helper.ts
- const TZ_OFFSET_SEC = 8 * 3600;
- export function getGmt8HourStartUtcSec(epochSec: number): number {
- const shifted = epochSec + TZ_OFFSET_SEC;
- const hourStartShifted = Math.floor(shifted / 3600) * 3600;
- return hourStartShifted - TZ_OFFSET_SEC; // still UTC epoch seconds
- }
- export function getGmt8CurrentHourStartUtcSec(nowSec: number): number {
- return getGmt8HourStartUtcSec(nowSec);
- }
- export function computeHourlyWindowUtcSec(nowSec: number, lookbackHours = 2) {
- const currentHourStartUtc = getGmt8CurrentHourStartUtcSec(nowSec);
- const startSec = currentHourStartUtc - lookbackHours * 3600;
- const endSec = nowSec; // realtime
- return { startSec, endSec };
- }
|