From 6649d5330ed71f7087818e291fb65c9e30c9eb4c Mon Sep 17 00:00:00 2001 From: Marian Zeis <13335743+marianfoo@users.noreply.github.com> Date: Wed, 24 Jul 2024 21:36:12 +0200 Subject: [PATCH] fix: `Edm.DateTimeOffset` parsing with and without precision (#603) --- .../ui5-cc-spreadsheetimporter/src/controller/Parser.ts | 8 +++++++- .../src/controller/odata/MetadataHandlerV4.ts | 1 + packages/ui5-cc-spreadsheetimporter/src/types.d.ts | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts b/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts index 9c8abf13..a6a2909c 100644 --- a/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts +++ b/packages/ui5-cc-spreadsheetimporter/src/controller/Parser.ts @@ -57,7 +57,13 @@ export default class Parser extends ManagedObject { } try { this.checkDate(date, metadataColumn, util, messageHandler, index); - payload[columnKey] = date; + if(!metadataColumn.precision){ + // If precision is not defined, remove milliseconds from date (from '2023-11-25T00:00:00Z' to '2023-11-25T00:00:00.000Z') + // see https://github.com/spreadsheetimporter/ui5-cc-spreadsheetimporter/issues/600 + payload[columnKey] = date.toISOString().replace(/\.\d{3}/, '') + } else { + payload[columnKey] = date; + } } catch (error) { this.addMessageToMessages("spreadsheetimporter.errorWhileParsing", util, messageHandler, index, [metadataColumn.label], rawValue); } diff --git a/packages/ui5-cc-spreadsheetimporter/src/controller/odata/MetadataHandlerV4.ts b/packages/ui5-cc-spreadsheetimporter/src/controller/odata/MetadataHandlerV4.ts index 1e382fb9..97fd76c9 100644 --- a/packages/ui5-cc-spreadsheetimporter/src/controller/odata/MetadataHandlerV4.ts +++ b/packages/ui5-cc-spreadsheetimporter/src/controller/odata/MetadataHandlerV4.ts @@ -50,6 +50,7 @@ export default class MetadataHandlerV4 extends MetadataHandler { } propertyObject.type = property.$Type; propertyObject.maxLength = property.$MaxLength; + propertyObject.precision = property.$Precision; listObject.set(propertyName, propertyObject); } else { Log.warning(`SpreadsheetUpload: Property ${propertyName} not found`, undefined, "SpreadsheetUpload: MetadataHandler"); diff --git a/packages/ui5-cc-spreadsheetimporter/src/types.d.ts b/packages/ui5-cc-spreadsheetimporter/src/types.d.ts index 609942e7..6faa93c1 100644 --- a/packages/ui5-cc-spreadsheetimporter/src/types.d.ts +++ b/packages/ui5-cc-spreadsheetimporter/src/types.d.ts @@ -8,9 +8,10 @@ export interface Tags { } export interface Property { - maxLength: number; + maxLength?: number; type: string; label: string; + precision?: number; } export type ListObject = Map; export type PropertyArray = { [key: string]: any }[];