From 17d5acee9dfaba8207c9220ef7205765f48d73d2 Mon Sep 17 00:00:00 2001 From: pitzm Date: Fri, 16 May 2025 10:31:06 +0200 Subject: [PATCH] Neue Datum-Konvertierungsfunktion --- Base/StringFunctions.vb | 44 ++++++++++++++++++++++++++- Jobs/ZUGFeRD/XRechnungViewDocument.vb | 6 ++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Base/StringFunctions.vb b/Base/StringFunctions.vb index 1eb4b131..b8570587 100644 --- a/Base/StringFunctions.vb +++ b/Base/StringFunctions.vb @@ -1,4 +1,7 @@ -Public Class StringFunctions +Imports System.Globalization +Imports DigitalData.Modules.Logging + +Public Class StringFunctions Public Shared Function SplitText_Length(ByVal input As String, ByVal maxLength As Integer) As List(Of String) Dim result As New List(Of String) @@ -19,4 +22,43 @@ Dim lines As List(Of String) = text.Split({vbCrLf, vbLf, vbCr}, StringSplitOptions.None).ToList() Return lines End Function + + Public Shared Function DatetimeStringToGermanStringConverter(pDatetimeString As String, pLogger As Logger) As String + + If pDatetimeString.IsNullOrEmpty() = True Then + ' Wenn nichts kommt, kommt nichts zurueck + Return String.Empty + End If + + Dim formatList As List(Of String) = New List(Of String) From { + "yyyyMMdd", + "MM/dd/yyyy", "M/d/yyyy", "MM/d/yyyy", "M/dd/yyyy", + "yyyy-MM-dd", "yyyy-M-d", "yyyy-MM-d", "yyyy-M-dd", + "dd.MM.yyyy", "d.M.yyyy", "d.MM.yyyy", "dd.M.yyyy" + } + + Dim dateStringResult As Date = Date.MinValue + Dim oConvertResult As Boolean = False + + For Each formatStringItem In formatList + Try + dateStringResult = DateTime.ParseExact(pDatetimeString, formatStringItem, CultureInfo.InvariantCulture) + oConvertResult = True + Exit For + Catch ex As FormatException + oConvertResult = False + pLogger?.Debug("DatetimeStringToGermanStringConverter() - Could not parse date string {0} ({1})", pDatetimeString, formatStringItem) + End Try + Next + + If oConvertResult = True Then + ' In deutsches Format umwandeln (dd.MM.yyyy) + Dim germanDateFormat As String = dateStringResult.ToString("dd.MM.yyyy") + Return germanDateFormat + Else + ' Wenn nichts konvertiert werden konnte, geben wir den ursprünglichen Wert zurück + Return pDatetimeString + End If + + End Function End Class diff --git a/Jobs/ZUGFeRD/XRechnungViewDocument.vb b/Jobs/ZUGFeRD/XRechnungViewDocument.vb index 7a910bea..8e011bc7 100644 --- a/Jobs/ZUGFeRD/XRechnungViewDocument.vb +++ b/Jobs/ZUGFeRD/XRechnungViewDocument.vb @@ -215,7 +215,7 @@ Public Class XRechnungViewDocument Else 'INDIVIDUELLES VERHALTEN BEI Folge-ITEMS _logger.Debug($"FollowItem - Area: [{oArea}] - ItemSpecname: [{oItemSPECNAME}] - ItemValue: [{oItemValue}]") - Dim otextBoxYPos As Integer + 'Dim otextBoxYPos As Integer If oArea = "POSITION" Then If oItemSPECNAME = "INVOICE_POSITION_AMOUNT" Then oPosCount += 1 @@ -295,9 +295,7 @@ Public Class XRechnungViewDocument oItemValue = oPosTerm ElseIf oArea = "HEAD" Then If oItemSPECNAME = "INVOICE_DATE" Or oItemSPECNAME = "INVOICE_SERVICE_DATE" Then - Dim oDateString As String = oItemValue - Dim oParsedDate As DateTime = DateTime.ParseExact(oDateString, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) - oItemValue = oParsedDate.ToString("dd.MM.yyyy") + oItemValue = StringFunctions.DatetimeStringToGermanStringConverter(oItemValue, _logger) End If ElseIf oArea = "TAXPOS" Then If oItemSPECNAME = "INVOICE_TAXPOS_RATE" Then