diff --git a/.github/workflows/opa5-test.yml b/.github/workflows/opa5-test.yml index 3166c490..66552e6e 100644 --- a/.github/workflows/opa5-test.yml +++ b/.github/workflows/opa5-test.yml @@ -35,7 +35,7 @@ jobs: with: ref: ${{ github.head_ref }} - - run: corepack enable + - run: corepack enable pnpm - name: use node 20 uses: actions/setup-node@v4 with: diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index de6d3ea0..a261e4ab 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -28,7 +28,7 @@ jobs: fetch-depth: 0 if: ${{ steps.release.outputs.releases_created }} - - run: corepack enable + - run: corepack enable pnpm - name: use node 20 uses: actions/setup-node@v4 with: @@ -89,7 +89,7 @@ jobs: run: | git config --global user.email "ops+robot@npmjs.com" git config --global user.name "npm team" - - run: corepack enable + - run: corepack enable pnpm - name: use node 20 uses: actions/setup-node@v4 with: diff --git a/.github/workflows/wdi5-test.yml b/.github/workflows/wdi5-test.yml index 2bca9641..dcfd9a3b 100644 --- a/.github/workflows/wdi5-test.yml +++ b/.github/workflows/wdi5-test.yml @@ -42,7 +42,7 @@ jobs: with: ref: ${{ github.head_ref }} - - run: corepack enable + - run: corepack enable pnpm - name: use node 20 uses: actions/setup-node@v4 with: diff --git a/examples/package.json b/examples/package.json index 882762c6..fcc04363 100644 --- a/examples/package.json +++ b/examples/package.json @@ -12,7 +12,6 @@ "engines": { "node": ">=16" }, - "packageManager": "pnpm@7.1.7", "scripts": { "start": "run-p watch:server start:uiv4fe start:uiv2fe start:uiv2freestyle start:uiv2fenondraft start:uiv4fpm", "start:uiv4fe": "pnpm --filter ordersv4fe start", diff --git a/examples/test/testFiles/TwoRowsNoErrors.xlsx b/examples/test/testFiles/TwoRowsNoErrors.xlsx index 710d72a3..f723ad3b 100644 Binary files a/examples/test/testFiles/TwoRowsNoErrors.xlsx and b/examples/test/testFiles/TwoRowsNoErrors.xlsx differ diff --git a/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts b/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts index 4418208e..9c8abf13 100644 --- a/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts +++ b/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts @@ -63,20 +63,22 @@ export default class Parser extends ManagedObject { } } else if (metadataColumn.type === "Edm.TimeOfDay" || metadataColumn.type === "Edm.Time") { let date = rawValue; + + // Only try to parse as Date if it's not marked as a date in sheet data if (value.sheetDataType !== "d") { - const parsedDate = new Date(rawValue); - if (isNaN(parsedDate.getTime())) { - this.addMessageToMessages("spreadsheetimporter.invalidDate", util, messageHandler, index, [metadataColumn.label], rawValue); - continue; - } - date = parsedDate; + date = new Date(rawValue); } - try { - this.checkDate(date, metadataColumn, util, messageHandler, index); - const spreadsheetDate = date.toISOString().substring(11, 19); - payload[columnKey] = spreadsheetDate; - } catch (error) { - this.addMessageToMessages("spreadsheetimporter.errorWhileParsing", util, messageHandler, index, [metadataColumn.label], rawValue); + + if (date && !isNaN(date.getTime())) { + // Successfully parsed to Date, format to only time part + const timeFormatted = date.toISOString().substring(11, 19); + payload[columnKey] = timeFormatted; + } else { + // Call the new method to parse time pattern if excel data is text not date + const parsedTime = this.parseTimePattern(rawValue, util, messageHandler, index, metadataColumn); + if (parsedTime) { + payload[columnKey] = parsedTime; + } } } else if ( metadataColumn.type === "Edm.UInt8" || @@ -193,4 +195,52 @@ export default class Parser extends ManagedObject { ui5type: MessageType.Error }); } + + /** + * Parses a time string according to specific patterns and returns the local time as a string. + * This method handles raw time strings and validates them against the expected format. + * The method supports time strings in the format "HH:mm:ss" and "HH:mm:ss.sss", where: + * - HH represents hours (00 to 23), + * - mm represents minutes (00 to 59), + * - ss represents seconds (00 to 59), + * - sss represents milliseconds (000 to 999). + * + * If the time string is valid and the components are within their respective ranges, + * it constructs a Date object and formats the time to respect the local timezone. + * If the time string does not match the expected pattern or components are out of range, + * it logs an appropriate error message. + * + * @param {string} rawValue - The raw time string to be parsed. + * @param {Util} util - Utility class instance for accessing helper functions like i18n. + * @param {MessageHandler} messageHandler - MessageHandler class instance for logging errors. + * @param {number} index - The row index of the data being parsed, used for error reporting. + * @param {Property} metadataColumn - The metadata for the column, including the type label. + * @returns {string|null} - Returns a formatted time string if successful, otherwise null. + */ + static parseTimePattern(rawValue: any, util: Util, messageHandler: MessageHandler, index: number, metadataColumn: Property) { + const timePattern = /^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?$/; + const match = rawValue.match(timePattern); + + if (match) { + const hours = parseInt(match[1], 10); + const minutes = parseInt(match[2], 10); + const seconds = match[3] ? parseInt(match[3], 10) : 0; + const milliseconds = match[4] ? parseInt(match[4], 10) : 0; + + // Validate time components + if (hours < 24 && minutes < 60 && seconds < 60) { + // Construct a Date object from time components + let today = new Date(); + today.setHours(hours, minutes, seconds, milliseconds); + // Format the time considering the local timezone + const timeFormatted = `${today.getHours().toString().padStart(2, "0")}:${today.getMinutes().toString().padStart(2, "0")}:${today.getSeconds().toString().padStart(2, "0")}`; + return timeFormatted; + } else { + this.addMessageToMessages("spreadsheetimporter.invalidTime", util, messageHandler, index, [metadataColumn.label], rawValue); + } + } else { + this.addMessageToMessages("spreadsheetimporter.invalidTimeFormat", util, messageHandler, index, [metadataColumn.label], rawValue); + } + return null; + } }