Skip to content

Commit

Permalink
Merge pull request #256 from lukashornych/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
lukashornych authored Dec 18, 2024
2 parents 2003cc7 + d531210 commit 052e4ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
38 changes: 23 additions & 15 deletions src/modules/connection/driver/grpc/service/EvitaValueConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down Expand Up @@ -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
)
)
}
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 10 additions & 2 deletions src/modules/connection/model/data-type/DateTimeRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { OffsetDateTime } from "./OffsetDateTime"
import { PrettyPrintable } from "./PrettyPrintable"
import { Range } from "./Range"

const emptyRangeEndSymbol: any = '∞'

export class DateTimeRange extends Range<OffsetDateTime> implements PrettyPrintable {

constructor(from?: OffsetDateTime, to?: OffsetDateTime) {
Expand All @@ -14,7 +16,13 @@ export class DateTimeRange extends Range<OffsetDateTime> 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 {
Expand All @@ -34,6 +42,6 @@ export class DateTimeRange extends Range<OffsetDateTime> implements PrettyPrinta
}

override toString():string{
return `[${this.from ?? '∞'},${this.to ?? '∞'}]`
return `[${this.from ?? emptyRangeEndSymbol},${this.to ?? emptyRangeEndSymbol}]`
}
}

0 comments on commit 052e4ac

Please sign in to comment.