From f0a5e18335bf9619e52200dda36ebc21ef8186e5 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 21 Oct 2018 17:32:03 +0200 Subject: [PATCH] fix(ExtendedDate): now respects single digit dates --- ts/smarttime.classes.date.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ts/smarttime.classes.date.ts b/ts/smarttime.classes.date.ts index 6fbd955..defd4d3 100644 --- a/ts/smarttime.classes.date.ts +++ b/ts/smarttime.classes.date.ts @@ -15,11 +15,22 @@ export class ExtendedDate extends Date { } /** */ - public static fromEuropeanDateAndTime(europeanDateArg: string, timeArg: string, zoneArg: TAvailableZone) { + public static fromEuropeanDateAndTime( + europeanDateArg: string, + timeArg: string, + zoneArg: TAvailableZone + ) { const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDateArg); - const luxonDate = plugins.luxon.DateTime.fromISO(`${dateArray[3]}-${dateArray[2]}-${dateArray[1]}T${timeArg}`, { - zone: zoneArg - }); + const sliceDate = (dateString: string) => { + return `0${dateString}`.slice(-2); + }; + const dateTimeString = `${dateArray[3]}-${sliceDate(dateArray[2])}-${sliceDate(dateArray[1])}T${timeArg}`; + const luxonDate = plugins.luxon.DateTime.fromISO( + dateTimeString, + { + zone: zoneArg + } + ); const unixMilli = luxonDate.toMillis(); return new ExtendedDate(unixMilli); }