Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions .github/workflows/build-and-test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Build and Test

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,15 +19,17 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Run linting
run: pnpm lint
- name: Run tests
run: pnpm test
172 changes: 172 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# 📖 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](https://docs.epilot.io/docs/deadlines/deadlines-library/index/).

## 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

```typescript
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

```typescript
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

```typescript
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

```json
{
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

```typescript
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

```typescript
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

```typescript
import { CalendarProvider } from '@epilot/switching-deadlines'

const customCalendar = new CalendarProvider()

console.log(customCalendar.getCalendarVersion())
```

### Expected Output

```json
{
version: "2025.1.4",
year: 2025,
lastUpdated: "2025-09-29T13:20:52.863Z"
}
```
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A TypeScript library for handling German energy market compliance requirements, specifically supplier switching deadlines as defined by **GPKE** (power) and **GeLi Gas** (gas).

This library is regularly updated to reflect the latest calendar updates. You can find the changelog at [CHANGELOG.md](CHANGELOG.md).
This library is regularly updated to reflect the latest calendar updates. You can find the changelog at [here](CHANGELOG.md).

## ✨ Features

Expand Down Expand Up @@ -77,10 +77,9 @@ console.log(
`${`The earliest start date is ${relocationResult.earliestStartDate} for relocation and ${switchResult.earliestStartDate} for switching`}`
)
```
You can find more information in the 📖 [usage examples](EXAMPLES.md).

## 📖 Documentation

Comprehensive usage examples and background information are available in the 👉 [epilot dev center](https://docs.epilot.io/docs/deadlines/intro).
Comprehensive documentation and background information are available in the 👉 [epilot dev center](https://docs.epilot.io/docs/deadlines/intro).

## 📜 Disclaimer

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"clean": "rimraf dist coverage",
"prepare": "pnpm run build",
"prepublishOnly": "pnpm run build",
"gen-docs": "rm -rf docs && typedoc --plugin typedoc-plugin-markdown --out docs src && echo '{ \"label\": \"Switching Deadlines Library\", \"position\": 0 }' > docs/_category_.json"
"gen-docs": "rm -rf docs && typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts && echo '{ \"label\": \"Switching Deadlines Library\", \"position\": 0 }' > docs/_category_.json"
},
"keywords": [],
"author": "epilot GmbH",
Expand Down
5 changes: 2 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ export function calculateDeadline(
* ```typescript
* import { validateDate, Commodity, UseCase } from '@epilot/switching-deadlines';
*
* const result = validateDate('2025-10-05', {
* const isValid = validateDate('2025-10-05', {
* commodity: Commodity.POWER,
* useCase: UseCase.SWITCH,
* requiresTermination: true
* });
*
* console.log(result.isValid); // false
* console.log(result.earliestValidDate); // Date object for 2025-10-07
* console.log(isValid); // false
* ```
*/
export function validateDate(
Expand Down
3 changes: 3 additions & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projectDocuments": ["./CHANGELOG.md", "./EXAMPLES.md"]
}