From 2b627ec31f23f6c3558a08a9e7c7c1318ae5529a Mon Sep 17 00:00:00 2001 From: Marlon Kerth Date: Fri, 13 Mar 2026 14:50:52 +0100 Subject: [PATCH] Release: v2.5.1 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- .../PatternCompiler/Plugin/DateFormatter.ts | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b248a2c..b38c4f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index 0941b16..5309dee 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "publishConfig": { "access": "public" }, - "version": "2.5.0", + "version": "2.5.1", "license": "MIT", "private": false, "engines": { diff --git a/src/util/PatternCompiler/Plugin/DateFormatter.ts b/src/util/PatternCompiler/Plugin/DateFormatter.ts index 087527d..112d340 100644 --- a/src/util/PatternCompiler/Plugin/DateFormatter.ts +++ b/src/util/PatternCompiler/Plugin/DateFormatter.ts @@ -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