diff --git a/pkg/abaputils/abaputils.go b/pkg/abaputils/abaputils.go index 9b944cdc31..d548ee8a30 100644 --- a/pkg/abaputils/abaputils.go +++ b/pkg/abaputils/abaputils.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" "regexp" - "strconv" "strings" "time" @@ -244,17 +243,6 @@ func GetErrorDetailsFromResponse(resp *http.Response) (errorString string, error } -// ConvertTime formats an ABAP timestamp string from format /Date(1585576807000+0000)/ into a UNIX timestamp and returns it -func ConvertTime(logTimeStamp string) time.Time { - seconds := strings.TrimPrefix(strings.TrimSuffix(logTimeStamp, "000+0000)/"), "/Date(") - n, error := strconv.ParseInt(seconds, 10, 64) - if error != nil { - return time.Unix(0, 0).UTC() - } - t := time.Unix(n, 0).UTC() - return t -} - // AddDefaultDashedLine adds 25 dashes func AddDefaultDashedLine(j int) { for i := 1; i <= j; i++ { diff --git a/pkg/abaputils/abaputils_test.go b/pkg/abaputils/abaputils_test.go index 8bfc272f93..56688f7aec 100644 --- a/pkg/abaputils/abaputils_test.go +++ b/pkg/abaputils/abaputils_test.go @@ -271,27 +271,6 @@ func TestReadServiceKeyAbapEnvironment(t *testing.T) { }) } -func TestTimeConverter(t *testing.T) { - t.Run("Test example time", func(t *testing.T) { - inputDate := "/Date(1585576809000+0000)/" - expectedDate := "2020-03-30 14:00:09 +0000 UTC" - result := ConvertTime(inputDate) - assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") - }) - t.Run("Test Unix time", func(t *testing.T) { - inputDate := "/Date(0000000000000+0000)/" - expectedDate := "1970-01-01 00:00:00 +0000 UTC" - result := ConvertTime(inputDate) - assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") - }) - t.Run("Test unexpected format", func(t *testing.T) { - inputDate := "/Date(0012300000001+0000)/" - expectedDate := "1970-01-01 00:00:00 +0000 UTC" - result := ConvertTime(inputDate) - assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") - }) -} - func TestHandleHTTPError(t *testing.T) { t.Run("Test", func(t *testing.T) { diff --git a/pkg/abaputils/manageGitRepositoryUtils.go b/pkg/abaputils/manageGitRepositoryUtils.go index 7d6b8224de..09854c5400 100644 --- a/pkg/abaputils/manageGitRepositoryUtils.go +++ b/pkg/abaputils/manageGitRepositoryUtils.go @@ -58,7 +58,7 @@ func PrintLogs(api SoftwareComponentApiInterface) { return results[i].Index < results[j].Index }) - printOverview(results) + printOverview(results, api) // Print Details for _, logEntryForDetails := range results { @@ -80,7 +80,7 @@ func printExecutionLogs(executionLogs ExecutionLog) { AddDefaultDashedLine(1) } -func printOverview(results []LogResultsV2) { +func printOverview(results []LogResultsV2, api SoftwareComponentApiInterface) { logOutputPhaseLength, logOutputLineLength := calculateLenghts(results) @@ -93,7 +93,7 @@ func printOverview(results []LogResultsV2) { printDashedLine(logOutputLineLength) for _, logEntry := range results { - log.Entry().Infof("| %-"+fmt.Sprint(logOutputPhaseLength)+"s | %"+fmt.Sprint(logOutputStatusLength)+"s | %-"+fmt.Sprint(logOutputTimestampLength)+"s |", logEntry.Name, logEntry.Status, ConvertTime(logEntry.Timestamp)) + log.Entry().Infof("| %-"+fmt.Sprint(logOutputPhaseLength)+"s | %"+fmt.Sprint(logOutputStatusLength)+"s | %-"+fmt.Sprint(logOutputTimestampLength)+"s |", logEntry.Name, logEntry.Status, api.ConvertTime(logEntry.Timestamp)) } printDashedLine(logOutputLineLength) } @@ -117,7 +117,7 @@ func printDashedLine(i int) { func printLog(logOverviewEntry LogResultsV2, api SoftwareComponentApiInterface) { page := 0 - printHeader(logOverviewEntry) + printHeader(logOverviewEntry, api) for { logProtocols, count, err := api.GetLogProtocol(logOverviewEntry, page) printLogProtocolEntries(logOverviewEntry, logProtocols) @@ -149,16 +149,16 @@ func allLogsHaveBeenPrinted(protocols []LogProtocol, page int, count int, err er return (err != nil || allPagesHaveBeenRead || reflect.DeepEqual(protocols, []LogProtocol{})) } -func printHeader(logEntry LogResultsV2) { +func printHeader(logEntry LogResultsV2, api SoftwareComponentApiInterface) { if logEntry.Status != `Success` { log.Entry().Infof("\n") AddDefaultDashedLine(1) - log.Entry().Infof("%s (%v)", logEntry.Name, ConvertTime(logEntry.Timestamp)) + log.Entry().Infof("%s (%v)", logEntry.Name, api.ConvertTime(logEntry.Timestamp)) AddDefaultDashedLine(1) } else { log.Entry().Debugf("\n") AddDebugDashedLine() - log.Entry().Debugf("%s (%v)", logEntry.Name, ConvertTime(logEntry.Timestamp)) + log.Entry().Debugf("%s (%v)", logEntry.Name, api.ConvertTime(logEntry.Timestamp)) AddDebugDashedLine() } } diff --git a/pkg/abaputils/sap_com_0510.go b/pkg/abaputils/sap_com_0510.go index b330224f66..ae88b467a6 100644 --- a/pkg/abaputils/sap_com_0510.go +++ b/pkg/abaputils/sap_com_0510.go @@ -387,3 +387,14 @@ func (api *SAP_COM_0510) getLogProtocolQuery(page int) string { return fmt.Sprintf("?$skip=%s&$top=%s&$inlinecount=allpages", fmt.Sprint(skip), fmt.Sprint(top)) } + +// ConvertTime formats an ABAP timestamp string from format /Date(1585576807000+0000)/ into a UNIX timestamp and returns it +func (api *SAP_COM_0510) ConvertTime(logTimeStamp string) time.Time { + seconds := strings.TrimPrefix(strings.TrimSuffix(logTimeStamp, "000+0000)/"), "/Date(") + n, error := strconv.ParseInt(seconds, 10, 64) + if error != nil { + return time.Unix(0, 0).UTC() + } + t := time.Unix(n, 0).UTC() + return t +} diff --git a/pkg/abaputils/sap_com_0510_test.go b/pkg/abaputils/sap_com_0510_test.go index 776aa28d7f..28c3af01e6 100644 --- a/pkg/abaputils/sap_com_0510_test.go +++ b/pkg/abaputils/sap_com_0510_test.go @@ -481,3 +481,27 @@ func TestSleepTime(t *testing.T) { assert.ErrorContains(t, err, "Exceeded max sleep time") }) } + +func TestTimeConverter(t *testing.T) { + + api := SAP_COM_0510{} + + t.Run("Test example time", func(t *testing.T) { + inputDate := "/Date(1585576809000+0000)/" + expectedDate := "2020-03-30 14:00:09 +0000 UTC" + result := api.ConvertTime(inputDate) + assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") + }) + t.Run("Test Unix time", func(t *testing.T) { + inputDate := "/Date(0000000000000+0000)/" + expectedDate := "1970-01-01 00:00:00 +0000 UTC" + result := api.ConvertTime(inputDate) + assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") + }) + t.Run("Test unexpected format", func(t *testing.T) { + inputDate := "/Date(0012300000001+0000)/" + expectedDate := "1970-01-01 00:00:00 +0000 UTC" + result := api.ConvertTime(inputDate) + assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") + }) +} diff --git a/pkg/abaputils/sap_com_0948.go b/pkg/abaputils/sap_com_0948.go index f6b7be68b5..18fd7bb672 100644 --- a/pkg/abaputils/sap_com_0948.go +++ b/pkg/abaputils/sap_com_0948.go @@ -406,3 +406,12 @@ func (api *SAP_COM_0948) getLogProtocolQuery(page int) string { return fmt.Sprintf("?$skip=%s&$top=%s&$count=true", fmt.Sprint(skip), fmt.Sprint(top)) } + +// ConvertTime formats an ISO 8601 timestamp string from format 2024-05-02T09:25:40Z into a UNIX timestamp and returns it +func (api *SAP_COM_0948) ConvertTime(logTimeStamp string) time.Time { + t, error := time.Parse(time.RFC3339, logTimeStamp) + if error != nil { + return time.Unix(0, 0).UTC() + } + return t +} diff --git a/pkg/abaputils/sap_com_0948_test.go b/pkg/abaputils/sap_com_0948_test.go index 24f7e6702c..8855e994ef 100644 --- a/pkg/abaputils/sap_com_0948_test.go +++ b/pkg/abaputils/sap_com_0948_test.go @@ -482,6 +482,30 @@ func TestSleepTime0948(t *testing.T) { }) } +func TestTimeConverter0948(t *testing.T) { + + api := SAP_COM_0948{} + + t.Run("Test example time", func(t *testing.T) { + inputDate := "2024-05-02T09:25:40Z" + expectedDate := "2024-05-02 09:25:40 +0000 UTC" + result := api.ConvertTime(inputDate) + assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") + }) + t.Run("Test Unix time", func(t *testing.T) { + inputDate := "2023-12-24T16:19:29.000Z" + expectedDate := "2023-12-24 16:19:29 +0000 UTC" + result := api.ConvertTime(inputDate) + assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") + }) + t.Run("Test unexpected format", func(t *testing.T) { + inputDate := "2024-05-02T09:254:40Z" + expectedDate := "1970-01-01 00:00:00 +0000 UTC" + result := api.ConvertTime(inputDate) + assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion") + }) +} + func TestGetExecutionLog(t *testing.T) { t.Run("Test Get Executionlog Success", func(t *testing.T) { diff --git a/pkg/abaputils/softwareComponentApiManager.go b/pkg/abaputils/softwareComponentApiManager.go index 813df3c3ef..c4d02e7115 100644 --- a/pkg/abaputils/softwareComponentApiManager.go +++ b/pkg/abaputils/softwareComponentApiManager.go @@ -67,6 +67,7 @@ type SoftwareComponentApiInterface interface { CreateTag(tag Tag) error GetLogOverview() ([]LogResultsV2, error) GetLogProtocol(LogResultsV2, int) (result []LogProtocol, count int, err error) + ConvertTime(logTimeStamp string) time.Time GetExecutionLog() (ExecutionLog, error) }