From f047543e0eeb95ab9f484b977ef164d5c03bbf4a Mon Sep 17 00:00:00 2001 From: Ilya Khait Date: Tue, 3 Oct 2023 17:12:03 +0000 Subject: [PATCH] Implement broken date display --- src/fragmentarium/domain/Date.test.ts | 17 +++++++++++++---- src/fragmentarium/domain/Date.ts | 10 +++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/fragmentarium/domain/Date.test.ts b/src/fragmentarium/domain/Date.test.ts index cf508aed7..d2e34bb66 100644 --- a/src/fragmentarium/domain/Date.test.ts +++ b/src/fragmentarium/domain/Date.test.ts @@ -251,15 +251,24 @@ describe('MesopotamianDate', () => { expect(date.toString()).toBe('∅.∅.∅ Sargon (ca. 2334–2279 BCE)') }) - it('returns the correct string representation (broken)', () => { + it('returns the correct string representation (broken, missing)', () => { + const date = new MesopotamianDate( + { value: '', isBroken: true }, + { value: '', isBroken: true, isIntercalary: true }, + { value: '', isBroken: true }, + king + ) + expect(date.toString()).toBe('[x].[x]².[x] Sargon (ca. 2334–2279 BCE)') + }) + + it('returns the correct string representation (broken, reconstructed)', () => { const date = new MesopotamianDate( { value: '1', isBroken: true }, { value: '2', isBroken: true, isIntercalary: true }, { value: '3', isBroken: true }, king ) - - expect(date.toString()).toBe('[x].[x]².[x] Sargon (ca. 2334–2279 BCE)') + expect(date.toString()).toBe('[3].[II²].[1] Sargon (ca. 2334 BCE)') }) it('returns the correct string representation (uncertain)', () => { @@ -279,7 +288,7 @@ describe('MesopotamianDate', () => { { value: '3', isBroken: true, isUncertain: true }, king ) - expect(date.toString()).toBe('[x]?.[x]²?.[x]? Sargon (ca. 2334–2279 BCE)') + expect(date.toString()).toBe('[3]?.[II²]?.[1]? Sargon (ca. 2334 BCE)') }) describe('toModernDate branching', () => { diff --git a/src/fragmentarium/domain/Date.ts b/src/fragmentarium/domain/Date.ts index f39076a37..26aede440 100644 --- a/src/fragmentarium/domain/Date.ts +++ b/src/fragmentarium/domain/Date.ts @@ -109,9 +109,9 @@ export class MesopotamianDate { parameter: 'year' | 'day' | 'month', element: string ): string { - const { isBroken, isUncertain } = this[parameter] + const { isBroken, isUncertain, value } = this[parameter] let brokenIntercalary = '' - if (isBroken) { + if (isBroken && !value) { element = 'x' brokenIntercalary = parameter === 'month' && this.month.isIntercalary ? '²' : '' @@ -190,13 +190,13 @@ export class MesopotamianDate { let month = parseInt(this.month.value) let day = parseInt(this.day.value) const isApproximate = this.isApproximate() - if (isNaN(month) || this.month.isBroken) { + if (isNaN(month)) { month = 1 } - if (isNaN(day) || this.day.isBroken) { + if (isNaN(day)) { day = 1 } - if (isNaN(year) || this.year.isBroken) { + if (isNaN(year)) { year = -1 } return {