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

Approximate dates patch #394

Merged
merged 43 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
956b29e
Implement Mesopotamian date, editing component & date converter (WiP)
khoidt Jul 19, 2023
4b3111e
Improve
khoidt Jul 19, 2023
c150438
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jul 19, 2023
bec1458
Extend (WiP)
khoidt Jul 31, 2023
84c3d60
Fix and update tests
khoidt Aug 1, 2023
d5d212a
Fix tsc
khoidt Aug 1, 2023
36b15ad
Improve & update tests
khoidt Aug 1, 2023
357fdda
Fix tsc
khoidt Aug 1, 2023
0492249
Refactor
khoidt Aug 1, 2023
92dd7c9
Adjust and unify
khoidt Aug 2, 2023
5c1f265
Update & fix
khoidt Aug 5, 2023
1b9279f
Implement date display in fragmentarium search
khoidt Aug 5, 2023
8546d86
Date paleography
khoidt Aug 7, 2023
81e1ccb
Fix tests
khoidt Aug 7, 2023
5b42cba
Make `date` optional in `CroppedAnnotation`
khoidt Aug 7, 2023
3123ba0
Update style
khoidt Aug 7, 2023
e505fd6
Refactor & update
khoidt Aug 7, 2023
e41636e
Add tests & update
khoidt Aug 7, 2023
c3d21d5
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 10, 2023
bb435be
Implement date delete & fix display issue
khoidt Aug 14, 2023
fc1a5d7
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 16, 2023
525ed06
Implement dates in text
khoidt Aug 24, 2023
ad96479
Add tests
khoidt Aug 25, 2023
b0bfd7c
Add more tests
khoidt Aug 25, 2023
22166ea
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 28, 2023
fbfedb7
Adjust date display
khoidt Aug 28, 2023
bf526e1
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 29, 2023
41a0257
Implement eponyms (WiP)
khoidt Sep 4, 2023
5b6675c
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 4, 2023
4df82dc
Add phases and improve selection
khoidt Sep 4, 2023
7460ee8
Extend eponym
khoidt Sep 5, 2023
088c5d3
Improve & add tests
khoidt Sep 5, 2023
111df01
Add & update tests
khoidt Sep 6, 2023
03fc524
Add test for date with eponym string
khoidt Sep 6, 2023
ba52efd
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 7, 2023
ae397c3
Implement date converter
khoidt Sep 21, 2023
b325ede
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 22, 2023
4768f48
Refactor
khoidt Sep 22, 2023
c3fa9fb
Refactor more
khoidt Sep 22, 2023
2f4d3e9
Refactor more
khoidt Sep 22, 2023
1a875b6
Add tests
khoidt Sep 22, 2023
bb5cdcf
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 23, 2023
da5a92a
Patch approximate dates conversion
khoidt Sep 23, 2023
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
99 changes: 99 additions & 0 deletions src/fragmentarium/domain/Date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ const eponym = {
phase: 'NA',
} as Eponym

const nabonassarEraKing = {
orderGlobal: 172,
dynastyNumber: '14',
dynastyName: 'Persian Rulers',
orderInDynasty: '3',
name: 'Darius I',
date: '521–486',
totalOfYears: '36',
notes: '',
}

describe('MesopotamianDate', () => {
describe('converts from json', () => {
it('initializes from JSON', () => {
Expand Down Expand Up @@ -99,6 +110,94 @@ describe('MesopotamianDate', () => {
expect(date.toString()).toBe('12.V.10 SE (30 August 302 BCE)')
})

it('returns the correct string representation (Seleucid, no day)', () => {
const date = new MesopotamianDate(
{ value: '10' },
{ value: '5' },
{ value: '' },
undefined,
undefined,
true
)
expect(date.toString()).toBe('∅.V.10 SE (ca. 19 August 302 BCE)')
})

it('returns the correct string representation (Seleucid, no month)', () => {
const date = new MesopotamianDate(
{ value: '10' },
{ value: '' },
{ value: '12' },
undefined,
undefined,
true
)
expect(date.toString()).toBe('12.∅.10 SE (ca. 4 May 302 BCE)')
})

it('returns the correct string representation (Seleucid, no year)', () => {
const date = new MesopotamianDate(
{ value: '' },
{ value: '5' },
{ value: '12' },
undefined,
undefined,
true
)
expect(date.toString()).toBe('12.V.∅ SE')
})

it('returns the correct string representation (Nabonassar era)', () => {
const date = new MesopotamianDate(
{ value: '10' },
{ value: '5' },
{ value: '12' },
nabonassarEraKing,
undefined,
undefined,
false
)
expect(date.toString()).toBe('12.V.10 Darius I (11 August 512 BCE)')
})

it('returns the correct string representation (Nabonassar era, no year)', () => {
const date = new MesopotamianDate(
{ value: '10' },
{ value: '5' },
{ value: '' },
nabonassarEraKing,
undefined,
undefined,
false
)
expect(date.toString()).toBe('∅.V.10 Darius I (ca. 31 July 512 BCE)')
})

it('returns the correct string representation (Nabonassar era, no month)', () => {
const date = new MesopotamianDate(
{ value: '10' },
{ value: '' },
{ value: '12' },
nabonassarEraKing,
undefined,
undefined,
false
)
expect(date.toString()).toBe('12.∅.10 Darius I (ca. 16 April 512 BCE)')
})

it('returns the correct string representation (Nabonassar era, no day)', () => {
const date = new MesopotamianDate(
{ value: '10' },
{ value: '5' },
{ value: '' },
nabonassarEraKing,
undefined,
undefined,
false
)
expect(date.toString()).toBe('∅.V.10 Darius I (ca. 31 July 512 BCE)')
})

it('returns the correct string representation (Ur III)', () => {
const date = new MesopotamianDate(
{ value: '10' },
Expand Down
90 changes: 78 additions & 12 deletions src/fragmentarium/domain/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,20 @@ export class MesopotamianDate {
}

toModernDate(): string {
const year = parseInt(this.year.value)
const month = parseInt(this.month.value)
const day = parseInt(this.day.value)
const { year, month, day, isApproximate } = this.getDateApproximation()
let result = ''
if (this.isSeleucidEra) {
result = this.seleucidToModernDate(year, month, day)
if (this.isSeleucidEra && year > 0) {
result = this.seleucidToModernDate(year, month, day, isApproximate)
} else if (
this.king?.orderGlobal &&
Object.values(data.rulerToBrinkmanKings).includes(this.king?.orderGlobal)
) {
result = this.nabonassarEraToModernDate(year, month, day)
result = this.nabonassarEraToModernDate(
year > 0 ? year : 1,
month,
day,
isApproximate
)
} else if (this.isAssyrianDate && this.eponym?.date) {
result = `ca. ${this.eponym?.date} BCE`
} else if (this.king?.date) {
Expand All @@ -170,34 +173,97 @@ export class MesopotamianDate {
return result
}

private insertDateApproximation(
dateString: string,
isApproximate: boolean
): string {
return `${isApproximate ? 'ca. ' : ''}${dateString}`
}

private getDateApproximation(): {
year: number
month: number
day: number
isApproximate: boolean
} {
let year = parseInt(this.year.value)
let month = parseInt(this.month.value)
let day = parseInt(this.day.value)
const isApproximate = this.isApproximate()
if (isNaN(month) || this.month.isBroken) {
month = 1
}
if (isNaN(day) || this.day.isBroken) {
day = 1
}
if (isNaN(year) || this.year.isBroken) {
year = -1
}
return {
year,
month,
day,
isApproximate: isApproximate,
}
}

private isApproximate(): boolean {
return [
_.some(
[
parseInt(this.year.value),
parseInt(this.month.value),
parseInt(this.day.value),
],
_.isNaN
),
[
this.year.isBroken,
this.month.isBroken,
this.day.isBroken,
this.year.isUncertain,
this.month.isUncertain,
this.day.isUncertain,
].includes(true),
].includes(true)
}

private seleucidToModernDate(
year: number,
month: number,
day: number
day: number,
isApproximate: boolean
): string {
const converter = new DateConverter()
converter.setSeBabylonianDate(year, month, day)
return converter.toModernDateString()
return this.insertDateApproximation(
converter.toModernDateString(),
isApproximate
)
}

private nabonassarEraToModernDate(
year: number,
month: number,
day: number
day: number,
isApproximate: boolean
): string {
const kingName = Object.keys(data.rulerToBrinkmanKings).find(
(key) => data.rulerToBrinkmanKings[key] === this.king?.orderGlobal
)
if (kingName) {
const converter = new DateConverter()
converter.setMesopotamianDate(kingName, year, month, day)
return converter.toModernDateString()
return this.insertDateApproximation(
converter.toModernDateString(),
isApproximate
)
}
return ''
}
private kingToModernDate(year?: number): string {
private kingToModernDate(year: number): string {
const firstReignYear = this.king?.date?.split('-')[0]
return firstReignYear !== undefined && year && !this.year.isBroken
return firstReignYear !== undefined && year > 0
? `ca. ${parseInt(firstReignYear) - year + 1} BCE`
: this.king?.date && !['', '?'].includes(this.king?.date)
? `ca. ${this.king?.date} BCE`
Expand Down
Loading