Skip to content

Commit

Permalink
Patch dirty king dates (#524)
Browse files Browse the repository at this point in the history
* Patch & update tests

* Clean up

* Format tests
  • Loading branch information
khoidt authored Jan 22, 2025
1 parent 5ee41d1 commit 10c8b78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/chronology/domain/Date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ describe('MesopotamianDate', () => {
expect(date.ur3Calendar).toBeUndefined()
})
})

describe('converts to string', () => {
it('returns the correct string representation (standard)', () => {
const date = new MesopotamianDate({
Expand Down Expand Up @@ -347,3 +346,21 @@ describe('MesopotamianDate', () => {
expect(date.toModernDate()).toBe('')
})
})

describe('handles king date with non-numeric characters', () => {
it('parses and processes king date correctly', () => {
const kingWithDirtyDate = {
...king,
date: 'c. 818–c. 813',
}

const date = new MesopotamianDate({
year: { value: '5' },
month: { value: '3' },
day: { value: '10' },
king: kingWithDirtyDate,
})

expect(date.toModernDate()).toBe('ca. 814 BCE PJC')
})
})
13 changes: 11 additions & 2 deletions src/chronology/domain/DateBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,22 @@ export class MesopotamianDateBase {
year,
calendar = 'Julian',
}: Pick<DateProps, 'year' | 'calendar'>): string {
const firstReignYear = this.king?.date?.split('-')[0]
const parseKingDate = (date: string): string => {
return date.replace(/[^\d-]/g, '')
}

const firstReignYear = this.king?.date
? parseKingDate(this.king.date).split(/[-]/)[0]
: undefined

return firstReignYear !== undefined && year > 0
? `ca. ${
parseInt(firstReignYear) - year + 1
} BCE ${calendarToAbbreviation(calendar)}`
: this.king?.date && !['', '?'].includes(this.king?.date)
? `ca. ${this.king?.date} BCE ${calendarToAbbreviation(calendar)}`
? `ca. ${parseKingDate(this.king?.date)} BCE ${calendarToAbbreviation(
calendar
)}`
: ''
}

Expand Down

0 comments on commit 10c8b78

Please sign in to comment.