diff --git a/src/modules/connection/driver/grpc/service/EvitaValueConverter.ts b/src/modules/connection/driver/grpc/service/EvitaValueConverter.ts index d640478..0d1a0c3 100644 --- a/src/modules/connection/driver/grpc/service/EvitaValueConverter.ts +++ b/src/modules/connection/driver/grpc/service/EvitaValueConverter.ts @@ -216,8 +216,8 @@ export class EvitaValueConverter { throw new Error('DateTimeRange has undefined prop from and to') else return new DateTimeRange( - new OffsetDateTime(value.from!.timestamp!, value.from!.offset), - new OffsetDateTime(value.to!.timestamp!, value.to!.offset) + value.from != undefined ? new OffsetDateTime(value.from!.timestamp!, value.from!.offset) : undefined, + value.to != undefined ? new OffsetDateTime(value.to!.timestamp!, value.to!.offset) : undefined ) } @@ -368,14 +368,18 @@ export class EvitaValueConverter { ) { dateTimeRange.push( new DateTimeRange( - new OffsetDateTime( - grpcDateTimeRange.from!.timestamp!, - grpcDateTimeRange.from!.offset - ), - new OffsetDateTime( - grpcDateTimeRange.to!.timestamp!, - grpcDateTimeRange.to!.offset - ) + grpcDateTimeRange.from != undefined + ? new OffsetDateTime( + grpcDateTimeRange.from!.timestamp!, + grpcDateTimeRange.from!.offset + ) + : undefined, + grpcDateTimeRange.to != undefined + ? new OffsetDateTime( + grpcDateTimeRange.to!.timestamp!, + grpcDateTimeRange.to!.offset + ) + : undefined ) ) } @@ -529,15 +533,19 @@ export class EvitaValueConverter { to: GrpcOffsetDateTime | undefined, hasOffset: boolean ): boolean { - if (!from && !to) return false - else if (from && to && !from.timestamp && !to.timestamp) return false - else if ( + if (!from && !to) { + return false + } else if (from && to && !from.timestamp && !to.timestamp) { + return false + } else if ( hasOffset && ((from && from.timestamp && !from.offset) || (to && to.timestamp && !to.offset)) - ) + ) { return false - else return true + } else { + return true + } } private checkNumberRangeValidity( diff --git a/src/modules/connection/model/data-type/DateTimeRange.ts b/src/modules/connection/model/data-type/DateTimeRange.ts index 9018991..0089da4 100644 --- a/src/modules/connection/model/data-type/DateTimeRange.ts +++ b/src/modules/connection/model/data-type/DateTimeRange.ts @@ -3,6 +3,8 @@ import { OffsetDateTime } from "./OffsetDateTime" import { PrettyPrintable } from "./PrettyPrintable" import { Range } from "./Range" +const emptyRangeEndSymbol: any = '∞' + export class DateTimeRange extends Range implements PrettyPrintable { constructor(from?: OffsetDateTime, to?: OffsetDateTime) { @@ -14,7 +16,13 @@ export class DateTimeRange extends Range implements PrettyPrinta dateStyle: 'medium', timeStyle: 'long', }) - return `[${offsetDateTimeFormatter.format(this.from?.timestamp?.toDate()) ?? '∞'},${offsetDateTimeFormatter.format(this.to?.timestamp?.toDate()) ?? '∞'}]` + const formattedFrom: string = this.from != undefined + ? offsetDateTimeFormatter.format(this.from.timestamp!.toDate()) + : emptyRangeEndSymbol + const formattedTo: string = this.to != undefined + ? offsetDateTimeFormatter.format(this.to.timestamp!.toDate()) + : emptyRangeEndSymbol + return `[${formattedFrom},${formattedTo}]` } static until(to: OffsetDateTime): DateTimeRange { @@ -34,6 +42,6 @@ export class DateTimeRange extends Range implements PrettyPrinta } override toString():string{ - return `[${this.from ?? '∞'},${this.to ?? '∞'}]` + return `[${this.from ?? emptyRangeEndSymbol},${this.to ?? emptyRangeEndSymbol}]` } }