From 4511ee858ef3622ce03369aef9050c0f8b1d5808 Mon Sep 17 00:00:00 2001 From: Ilya Khait Date: Tue, 5 Mar 2024 23:27:54 +0100 Subject: [PATCH] Fix end year issue in Nabonassar ranges (#461) * Fix end year issue in Nabonassar ranges --- src/chronology/domain/Date.test.ts | 13 +++++++++++++ src/chronology/domain/DateBase.ts | 4 ++++ src/chronology/domain/DateRange.ts | 14 ++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/chronology/domain/Date.test.ts b/src/chronology/domain/Date.test.ts index 44b12a7d6..856297863 100644 --- a/src/chronology/domain/Date.test.ts +++ b/src/chronology/domain/Date.test.ts @@ -197,6 +197,19 @@ describe('MesopotamianDate', () => { ) }) + it('returns the correct string representation (Nabonassar era, king only)', () => { + const date = new MesopotamianDate({ + year: { value: '' }, + month: { value: '' }, + day: { value: '' }, + king: nabonassarEraKing, + isSeleucidEra: false, + }) + expect(date.toString()).toBe( + 'Darius I (ca. 14 April 521 - 5 April 485 BCE PJC | ca. 8 April 521 - 31 March 485 BCE PGC)' + ) + }) + it('returns the correct string representation (Ur III)', () => { const date = new MesopotamianDate({ year: { value: '10' }, diff --git a/src/chronology/domain/DateBase.ts b/src/chronology/domain/DateBase.ts index 123f4a28a..7630f4004 100644 --- a/src/chronology/domain/DateBase.ts +++ b/src/chronology/domain/DateBase.ts @@ -55,6 +55,10 @@ export class MesopotamianDateBase { this.isSeleucidEra = isSeleucidEra this.isAssyrianDate = isAssyrianDate this.ur3Calendar = ur3Calendar + this.setRange() + } + + private setRange(): void { if ( this.getEmptyFields().length > 0 && [DateType.nabonassarEraDate, DateType.seleucidDate].includes( diff --git a/src/chronology/domain/DateRange.ts b/src/chronology/domain/DateRange.ts index 1d890604b..1440742d9 100644 --- a/src/chronology/domain/DateRange.ts +++ b/src/chronology/domain/DateRange.ts @@ -125,7 +125,7 @@ export default class DateRange { }[field]() } else if (dateType === DateType.nabonassarEraDate) { return { - year: () => `${this.getNabonassarRangeEndYear}`, + year: () => `${this.getNabonassarRangeEndYear(date)}`, month: () => `${this.getNabonassarDateEndMonth(date)}`, day: () => `${this.getNabonassarDateEndDay(date)}`, }[field]() @@ -157,14 +157,12 @@ export default class DateRange { return this._converter.calendar.mesopotamianMonthLength ?? 28 } - private get nabonassarRangeEndYear(): number { - return this._converter.latestDate.regnalYears ?? 1 - } - private getNabonassarRangeEndYear(date: MesopotamianDateBase): number { - return date.getEmptyFields().includes('year') - ? this.nabonassarRangeEndYear - : parseInt(date.year.value) + if (!date.getEmptyFields().includes('year')) { + return parseInt(date.year.value) + } + this._converter.setToMesopotamianDate(date.kingName as string, 1, 1, 1) + return this._converter.calendar.regnalYears ?? 1 } private getNabonassarDateEndMonth(date: MesopotamianDateBase): number {