Skip to content

Commit ae8c6ac

Browse files
docs(time): add JSDoc for UTC and timezone midnight functions
1 parent e15a46a commit ae8c6ac

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

utils/time.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
// utils/time.ts
22

3+
/**
4+
* Calculates the number of seconds remaining until the next UTC midnight.
5+
*
6+
* @returns Number of seconds until the upcoming UTC midnight
7+
*
8+
* @example
9+
* const seconds = getSecondsUntilUTCMidnight();
10+
* console.log(seconds); // e.g., 3600
11+
*/
12+
313
export function getSecondsUntilUTCMidnight(): number {
414
const now = new Date();
515

@@ -12,11 +22,21 @@ export function getSecondsUntilUTCMidnight(): number {
1222
return Math.floor((midnight.getTime() - now.getTime()) / 1000);
1323
}
1424

15-
// Returns seconds until midnight in the given IANA timezone (e.g. 'America/New_York').
16-
// Used to set CDN cache TTLs that reset at the user's local midnight rather than UTC midnight.
17-
// Note: on DST transition days (spring-forward/fall-back) the day is 23 or 25 hours,
18-
// so the returned TTL can be off by up to one hour on those two days per year — acceptable
19-
// for a cache TTL.
25+
/**
26+
* Calculates the number of seconds remaining until midnight in a given timezone.
27+
*
28+
* @param tz - IANA timezone string (e.g., "America/New_York", "Asia/Kolkata")
29+
* @returns Number of seconds until the next midnight in the specified timezone
30+
*
31+
* @remarks
32+
* ⚠️ On Daylight Saving Time (DST) transition days (spring-forward/fall-back),
33+
* the day length may be 23 or 25 hours. As a result, the returned value can be
34+
* off by up to one hour. This is acceptable for use cases like cache TTL.
35+
*
36+
* @example
37+
* const seconds = getSecondsUntilMidnightInTimezone("Asia/Kolkata");
38+
* console.log(seconds);
39+
*/
2040
export function getSecondsUntilMidnightInTimezone(tz: string): number {
2141
const now = new Date();
2242

0 commit comments

Comments
 (0)