EXAMPLES
@epilot/switching-deadlines / EXAMPLES
๐ Usage Examples
This section provides examples of typical usage scenarios. For detailed information on how to use the library, please refer to the complete documentation.
Calculating a single deadlineโ
Use the function calculateDeadline when you only need the earliest possible contract start date for a single case, without additional details.
Exampleโ
import { calculateDeadline, Commodity, UseCase } from '@epilot/switching-deadlines'
const result = calculateDeadline(
{
commodity: Commodity.POWER,
useCase: UseCase.SWITCH,
requiresTermination: true
},
'2025-10-01' // optional date to calculate from
)
console.log(result)
Expected Outputโ
2025-10-07
Validating a dateโ
Use the function validateDate if you want to quickly check whether a specific switching date is valid for a given commodity and use case.
Exampleโ
import { validateDate, Commodity, UseCase } from '@epilot/switching-deadlines'
const isValid = validateDate(
{
commodity: Commodity.POWER,
useCase: UseCase.SWITCH,
requiresTermination: true
},
'2025-01-05', // proposed start date
'2025-10-01' // optional date to calculate from
)
console.log(isValid)
Expected Outputโ
false
Using the Deadline Calculatorโ
Use the DeadlineCalculator class when you need more detailed results (e.g., for APIs or batch calculations), including applied rules and working days.
Exampleโ
import { DeadlineCalculator, Commodity, UseCase } from '@epilot/switching-deadlines'
const calculator = new DeadlineCalculator()
const result = calculator.calculateEarliestStartDate(
{
commodity: Commodity.POWER,
useCase: UseCase.SWITCH,
requiresTermination: true
},
'2025-10-01'
)
console.log(result)
Expected Outputโ
{
earliestStartDate: 2025-10-07T00:00:00.000Z,
earliestStartDateString: '2025-10-07',
workingDaysApplied: 2,
calendarDaysTotal: 6,
isRetrospective: false,
ruleApplied: {
id: 'power_switch_with_termination',
commodity: 'power',
useCase: 'switch',
requiresTermination: true,
requiredWorkingDays: 2,
allowsRetrospective: false,
description: 'Power contract switch with termination requires 2 working days lead time'
}
Using a custom Calendar Providerโ
Use a custom calendar provider if you want to include one-time or special holidays not yet reflected in the default calendar.
Exampleโ
import { DeadlineCalculator, CalendarProvider, HolidayType } from '@epilot/switching-deadlines'
const customCalendar = new CalendarProvider({
customCalendar: {
holidays: [
{
date: '2026-03-10',
name: 'Einmaliger Sonderfeiertag',
type: HolidayType.SPECIAL_HOLIDAY,
description: 'Special holiday for demonstration purposes',
isOneTime: true
}
]
},
useSpecialHolidays: true
})
const calculator = new DeadlineCalculator({
customCalendarProvider: customCalendar
})
Checking the library versionโ
To verify that your library installation contains the latest holiday updates and is up to date.
Exampleโ
import { getVersion } from '@epilot/switching-deadlines'
const { version } = getVersion()
console.log(`Library version: ${version}`)
Expected Outputโ
Library version: 2025.1.4
Alternatively, you can use the CalendarProvider to check the version details.
Exampleโ
import { CalendarProvider } from '@epilot/switching-deadlines'
const customCalendar = new CalendarProvider()
console.log(customCalendar.getCalendarVersion())
Expected Outputโ
{
version: "2025.1.4",
year: 2025,
lastUpdated: "2025-09-29T13:20:52.863Z"
}