Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch dirty king dates #524

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading