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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.5.1] - 2026-03-13

### Added

- Added `toDate` function to the `DateFormatter` class

## [2.5.0] - 2026-02-12

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"publishConfig": {
"access": "public"
},
"version": "2.5.0",
"version": "2.5.1",
"license": "MIT",
"private": false,
"engines": {
Expand Down
17 changes: 17 additions & 0 deletions src/util/PatternCompiler/Plugin/DateFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
export class DateFormatter {
/**
* Safely converts date-like values into a valid Date object.
* Returns null when the input is empty or invalid.
*/
static toDate(value: Date | string | null | undefined): Date | null {
if (!value) {
return null;
}

if (value instanceof Date) {
return Number.isNaN(value.getTime()) ? null : value;
}

const parsed = new Date(value);
return Number.isNaN(parsed.getTime()) ? null : parsed;
}

/**
* Formats a date with time in German format
* @param date Date object or date string to format
Expand Down
Loading