DeadlineCalculator
@epilot/switching-deadlines / index / DeadlineCalculator
Class: DeadlineCalculator
Defined in: deadlines-calculator.ts:47
Calculator for determining deadline dates and validating start dates for utility switching cases.
Handles different switching scenarios including power and gas contracts, with support for various use cases (relocation or supplier switch) and termination requirements. Can calculate both forward-looking and retrospective switching deadlines based on configurable business rules and working day calendars.
Exampleโ
const calculator = new DeadlineCalculator()
const result = calculator.calculateEarliestStartDate({
commodity: 'power',
useCase: 'relocation',
requiresTermination: false
})
console.log(result.earliestStartDate)
Constructorsโ
Constructorโ
new DeadlineCalculator(
options?):DeadlineCalculator
Defined in: deadlines-calculator.ts:68
Creates a new DeadlineCalculator instance.
Parametersโ
options?โ
Optional configuration options for the calculator.
Returnsโ
DeadlineCalculator
Exampleโ
// Default: built-in calendar + default rules
const calc = new DeadlineCalculator();
// With a custom calendar and rules
const calcCustom = new DeadlineCalculator({
calendarProvider: new CalendarProvider(),
customRules: [], // custom DeadlineRule objects
});
Methodsโ
calculateEarliestStartDate()โ
calculateEarliestStartDate(
switchingCase,fromDate?):object
Defined in: deadlines-calculator.ts:91
Calculate the earliest possible start date for a contract
Determines the earliest valid start date for a new utility contract based on the switching case type, applicable business rules, and working day calculations. Handles both standard forward switching and retrospective switching scenarios.
Parametersโ
switchingCaseโ
The switching case configuration
fromDate?โ
The date from which to calculate the deadline (defaults to current date)
string | Date
Returnsโ
Object containing calculated dates, applied rules, and metadata
calendarDaysTotalโ
calendarDaysTotal:
number
Total calendar days between request and earliest start
earliestStartDateโ
earliestStartDate:
Date
The earliest possible start date for the new contract
earliestStartDateStringโ
earliestStartDateString:
string
The earliest start date as ISO string
isRetrospectiveโ
isRetrospective:
boolean
Whether this is a retrospective switch (gas only)
ruleAppliedโ
ruleApplied:
DeadlineRule
The rule that was applied
workingDaysAppliedโ
workingDaysApplied:
number
Number of working days applied
Throwsโ
When no applicable rule is found for the switching case
getRule()โ
getRule(
switchingCase):undefined|DeadlineRule
Defined in: deadlines-calculator.ts:220
Get a specific rule for a switching case
Finds and returns the deadline rule that applies to the specified switching case configuration. Returns undefined if no matching rule exists.
Parametersโ
switchingCaseโ
The switching case to find a rule for
Returnsโ
undefined | DeadlineRule
The matching deadline rule or undefined if none found
getRules()โ
getRules():
DeadlineRule[]
Defined in: deadlines-calculator.ts:204
Get all configured rules
Returns a copy of all deadline rules currently configured in the calculator. Useful for debugging or displaying available switching scenarios.
Returnsโ
Array of all configured deadline rules
validateStartDate()โ
validateStartDate(
switchingCase,proposedDate,fromDate?):object
Defined in: deadlines-calculator.ts:167
Validate if a proposed start date is valid
Checks whether a proposed contract start date meets the minimum deadline requirements for the given switching case. Compares the proposed date against the calculated earliest valid date.
Parametersโ
switchingCaseโ
The switching case configuration
proposedDateโ
The date to validate
string | Date
fromDate?โ
The date from which to calculate the deadline (defaults to current date)
string | Date
Returnsโ
object
Validation result with validity status and earliest valid alternative if invalid
earliestValidDate?โ
optionalearliestValidDate:Date
isValidโ
isValid:
boolean
ruleAppliedโ
ruleApplied:
DeadlineRule