Skip to content

Commit

Permalink
change date datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
fsimonjetz committed Nov 6, 2023
1 parent 9fccb15 commit 3b0f68b
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/fragmentarium/domain/archaeology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export interface ExcavationPlan {
readonly references: readonly Reference[]
}
export type CommentedDateRange = {
start?: Date | null
end?: Date | null
start?: number
end?: number
notes?: string
}
export type CommentedDateRangeDto = {
start?: string
end?: string
start?: number
end?: number
notes?: string
}

Expand All @@ -58,18 +58,23 @@ export class Findspot {
readonly notes: string = ''
) {}

get buildingTypeValue(): string {
return this.buildingType === 'NOT_IN_BUILDING'
? 'Not in building'
: _.capitalize(this.buildingType)
private dateString(): string {
const start = this.dateRange?.start
const endYear = this.dateRange?.end
const end = endYear ? `-${endYear}` : ''

return _.some(this.dateRange) ? ` (${start}${end})` : ''
}

toString(): string {
const area = this.area ? `${this.area} > ` : ''
const dateInfo = this.dateRange
? ` (${this.dateRange.start || '?'}-${this.dateRange.end || '?'})`
: ''
return `${area}${this.building} (${this.buildingTypeValue}), ${this.levelLayerPhase}${dateInfo}.`
const dateInfo = this.dateString()
const buildingTypeInfo =
this.buildingType === 'NOT_IN_BUILDING'
? ' (Not in building)'
: ` (${_.capitalize(this.buildingType)})`
const sep = this.levelLayerPhase || dateInfo ? ', ' : ''
return `${area}${this.building}${buildingTypeInfo}${sep}${this.levelLayerPhase}${dateInfo}.`
}
}

Expand Down Expand Up @@ -115,17 +120,16 @@ export function fromDateRangeDto(
dto: CommentedDateRangeDto
): CommentedDateRange {
return {
start: dto.start ? new Date(dto.start) : null,
end: dto.end ? new Date(dto.end) : null,
...dto,
notes: dto.notes || '',
}
}
export function toDateRangeDto(
dateRange: CommentedDateRange
): CommentedDateRangeDto {
return {
start: dateRange.start?.toString(),
end: dateRange.end?.toString(),
start: dateRange.start,
end: dateRange.end,
notes: dateRange.notes,
}
}
Expand Down

0 comments on commit 3b0f68b

Please sign in to comment.