Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into colophons
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Mar 7, 2024
2 parents ed80897 + 4511ee8 commit 5926372
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 13 additions & 0 deletions src/chronology/domain/Date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
4 changes: 4 additions & 0 deletions src/chronology/domain/DateBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 6 additions & 8 deletions src/chronology/domain/DateRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5926372

Please sign in to comment.