diff --git a/CHANGELOG.md b/CHANGELOG.md index b38c4f3..f9def46 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.2] - 2026-03-16 + +### Added + +- Added `toTimestamp` function to the `DateFormatter` class + ## [2.5.1] - 2026-03-13 ### Added diff --git a/package.json b/package.json index 5309dee..7463f31 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "publishConfig": { "access": "public" }, - "version": "2.5.1", + "version": "2.5.2", "license": "MIT", "private": false, "engines": { diff --git a/src/util/PatternCompiler/Plugin/DateFormatter.ts b/src/util/PatternCompiler/Plugin/DateFormatter.ts index 112d340..012a6c7 100644 --- a/src/util/PatternCompiler/Plugin/DateFormatter.ts +++ b/src/util/PatternCompiler/Plugin/DateFormatter.ts @@ -16,6 +16,19 @@ export class DateFormatter { return Number.isNaN(parsed.getTime()) ? null : parsed; } + /** + * Safely converts a date-string into a timestamp. + */ + static toTimestamp(value: string | null | undefined): number | null { + if (!value) { + return null; + } + + const parsed = new Date(value); + const time = parsed.getTime(); + return Number.isNaN(time) ? null : time; + } + /** * Formats a date with time in German format * @param date Date object or date string to format