feat: create branded types to determine different handling of time

This commit is contained in:
Carlos Valente
2026-02-16 06:51:43 +01:00
committed by Carlos Valente
parent 168d7103b1
commit e8f159d894
13 changed files with 315 additions and 41 deletions
@@ -0,0 +1,15 @@
declare const __brand: unique symbol;
type Brand<B> = { [__brand]: B };
type Branded<T, B> = T & Brand<B>;
/** A timestamp in milliseconds from epoch */
export type Instant = Branded<number, 'instant'>;
/** A timestamp of milliseconds since midnight today in the set timezone */
export type TimeOfDay = Branded<number, 'time-of-day'>;
/** A duration of milliseconds */
export type Duration = Branded<number, 'duration'>;
/** A day count integer */
export type Day = Branded<number, 'day'>;
+4 -1
View File
@@ -20,6 +20,9 @@ export type { RundownEntries, Rundown, ProjectRundowns } from './definitions/cor
export { TimeStrategy } from './definitions/TimeStrategy.type.js';
export { TimerType } from './definitions/TimerType.type.js';
// ---> Core
export type { Day, Duration, Instant, TimeOfDay } from './definitions/core/Temporal.js';
// ---> Report
export type { OntimeReport, OntimeEventReport } from './definitions/core/Report.type.js';
@@ -125,7 +128,7 @@ export {
isOntimeAction,
isTimerLifeCycle,
} from './utils/guards.js';
export type { MaybeNumber, MaybeString } from './utils/utils.type.js';
export type { Maybe, MaybeNumber, MaybeString } from './utils/utils.type.js';
// Colour
export type { RGBColour } from './definitions/Colour.type.js';
+2
View File
@@ -1,2 +1,4 @@
export type MaybeNumber = number | null;
export type MaybeString = string | null;
export type Maybe<T> = T | null;