My App
CourseKitBackend

TimeService

Utility methods for time overlap, gap, and range calculations

Overview

TimeService provides low-level time calculation utilities used internally by other services. You can also inject it directly for custom logic.

import { TimeService } from '@hfu.digital/coursekit-nestjs';

Methods

overlaps

Check if two time intervals overlap.

overlaps(aStart: Date, aDurationMin: number, bStart: Date, bDurationMin: number): boolean

Returns true if the intervals overlap (exclusive of endpoints).

time.overlaps(
    new Date('2026-03-02T09:00:00'), 90,  // 09:00 - 10:30
    new Date('2026-03-02T10:00:00'), 60,  // 10:00 - 11:00
); // true (they overlap between 10:00 and 10:30)

endTime

Compute the end time from a start time and duration.

endTime(start: Date, durationMin: number): Date
const end = time.endTime(new Date('2026-03-02T09:00:00'), 90);
// 2026-03-02T10:30:00

isInRange

Check if a date falls within a range (inclusive).

isInRange(date: Date, range: DateRange): boolean
time.isInRange(new Date('2026-03-05'), {
    start: new Date('2026-03-01'),
    end: new Date('2026-03-31'),
}); // true

gapMinutes

Compute the gap in minutes between two consecutive events.

gapMinutes(endOfFirst: Date, startOfSecond: Date): number

Returns a negative value if the events overlap.

time.gapMinutes(
    new Date('2026-03-02T10:30:00'),
    new Date('2026-03-02T11:00:00'),
); // 30

On this page