Deferral
createDeferralPresets, resolveDeferral, DEFERRAL_PRESET_IDS, and the energy-aware deferral strategy
Deferral ("snooze") is the "not now" primitive. Deferring an item is an energy statement: it declares insufficient capacity for it right now and names when it should resurface. Presets are pure (now: Date) => Date functions; the energy-aware strategy orders them so the default suggestion matches current capacity - low energy means longer deferrals, because items should resurface when capacity has plausibly recovered, not in an hour.
DEFERRAL_PRESET_IDS
const DEFERRAL_PRESET_IDS: Readonly<{
inOneHour: 'in-1-hour'
thisEvening: 'this-evening'
tomorrowMorning: 'tomorrow-morning'
nextWorkday: 'next-workday'
nextMonday: 'next-monday'
}>Stable preset ids, exported so configs/strategies can reference them.
DeferralPreset
A named deferral option.
Prop
Type
/>
createDeferralPresets
function createDeferralPresets(options?: DeferralPresetOptions): readonly DeferralPreset[]Build the standard deferral presets. Times are computed in local time - "tomorrow morning" means the user's morning. Throws for hours outside the integer range 0-23.
DeferralPresetOptions
Prop
Type
/>
The five presets
| Id | Label | Resurface time |
|---|---|---|
in-1-hour | In 1 hour | now + 60 minutes |
this-evening | This evening (18:00) | Today at eveningHour; if that has already passed, tomorrow at eveningHour |
tomorrow-morning | Tomorrow morning (9:00) | Tomorrow at morningHour |
next-workday | Next workday (9:00) | Next non-weekend day at morningHour |
next-monday | Next Monday (9:00) | The coming Monday at morningHour (a full week ahead when today is Monday) |
import { createDeferralPresets, resolveDeferral, DEFERRAL_PRESET_IDS } from '@kumbatio/energy-system'
const presets = createDeferralPresets({ morningHour: 8 })
const resurfaceAt = resolveDeferral(presets, DEFERRAL_PRESET_IDS.tomorrowMorning)
// epoch ms for tomorrow 08:00 local timeresolveDeferral
function resolveDeferral(
presets: readonly DeferralPreset[],
presetId: string,
now?: Date, // default: new Date()
): number | nullResolve a preset id to a resurface timestamp (epoch ms). Returns null for an unknown id - callers decide whether that is an error.
deferralStrategy
const deferralStrategy: AdaptationStrategy<DeferralConfig>The energy-aware ordering strategy (name: 'deferral'). Resolve it directly or through the engine like any built-in strategy.
DeferralConfig
Prop
Type
/>
Values per level
| Level | orderedPresetIds | defaultPresetId |
|---|---|---|
100 | in-1-hour, this-evening, tomorrow-morning, next-workday, next-monday | in-1-hour |
75 | in-1-hour, this-evening, tomorrow-morning, next-workday, next-monday | in-1-hour |
50 | this-evening, tomorrow-morning, in-1-hour, next-workday, next-monday | this-evening |
25 | tomorrow-morning, next-workday, this-evening, next-monday, in-1-hour | tomorrow-morning |
0 | tomorrow-morning, next-monday, next-workday, this-evening, in-1-hour | tomorrow-morning |
