Skip to content

Commit

Permalink
Hide empty year-month-date
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Feb 8, 2024
1 parent 837ad53 commit 802ac9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/chronology/domain/Date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ describe('MesopotamianDate', () => {
{ value: '' },
king
)
expect(date.toString()).toBe('∅.∅.∅ Sargon (ca. 2334–2279 BCE)')
expect(date.toString()).toBe('Sargon (ca. 2334–2279 BCE)')
})

it('returns the correct string representation (empty)', () => {
it('returns the correct string representation (empty, uncertain)', () => {
const date = new MesopotamianDate(
{ value: '' },
{ value: '', isUncertain: true },
{ value: '' },
{ value: '' },
king
)
expect(date.toString()).toBe('∅.∅.∅ Sargon (ca. 2334–2279 BCE)')
expect(date.toString()).toBe('∅.∅.∅? Sargon (ca. 2334–2279 BCE)')
})

it('returns the correct string representation (broken, missing)', () => {
Expand Down
30 changes: 22 additions & 8 deletions src/chronology/domain/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,29 @@ export class MesopotamianDate extends MesopotamianDateBase {
}

toString(): string {
const dateParts = ['day', 'month', 'year'].map((field) =>
this.datePartToString(field as 'year' | 'day' | 'month')
)
const dayMonthYear = this.dayMonthYearToString().join('.')
let julianDate = this.toJulianDate()
julianDate = julianDate ? ` (${julianDate})` : ''
return `${dateParts.join(
'.'
)}${this.kingEponymOrEraToString()}${this.ur3CalendarToString()}${julianDate}`
const dateTail = `${this.kingEponymOrEraToString()}${this.ur3CalendarToString()}${julianDate}`
console.log([dayMonthYear, dateTail].filter((string) => !_.isEmpty(string)))
return [dayMonthYear, dateTail]
.filter((string) => !_.isEmpty(string))
.join(' ')
}

private dayMonthYearToString(): string[] {
const fields = ['day', 'month', 'year']
const emptyParams = fields.map((field) => {
const { isBroken, isUncertain, value } = this[field]
return !isBroken && !isUncertain && _.isEmpty(value)
})
console.log(emptyParams)
if (!emptyParams.includes(false)) {
return []
}
return fields.map((field) =>
this.datePartToString(field as 'year' | 'day' | 'month')
)
}

private parameterToString(
Expand Down Expand Up @@ -98,7 +113,7 @@ export class MesopotamianDate extends MesopotamianDateBase {
}

kingEponymOrEraToString(): string {
const eraEponymOrKing = this.isSeleucidEra
return this.isSeleucidEra
? 'SE'
: this.isAssyrianDate && this.eponym?.name
? `${this.getBrokenAndUncertainString({
Expand All @@ -111,7 +126,6 @@ export class MesopotamianDate extends MesopotamianDateBase {
...this.king,
})
: ''
return eraEponymOrKing ? ' ' + eraEponymOrKing : eraEponymOrKing
}

ur3CalendarToString(): string {
Expand Down

0 comments on commit 802ac9e

Please sign in to comment.