Skip to content

Commit

Permalink
Implement broken date display
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Oct 3, 2023
1 parent cac6554 commit 596a84a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/chronology/domain/Date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,24 @@ describe('MesopotamianDate', () => {
expect(date.toString()).toBe('∅.∅.∅ Sargon (ca. 2334–2279 BCE)')
})

it('returns the correct string representation (broken)', () => {
it('returns the correct string representation (broken, missing)', () => {
const date = new MesopotamianDate(
{ value: '', isBroken: true },
{ value: '', isBroken: true, isIntercalary: true },
{ value: '', isBroken: true },
king
)
expect(date.toString()).toBe('[x].[x]².[x] Sargon (ca. 2334–2279 BCE)')
})

it('returns the correct string representation (broken, reconstructed)', () => {
const date = new MesopotamianDate(
{ value: '1', isBroken: true },
{ value: '2', isBroken: true, isIntercalary: true },
{ value: '3', isBroken: true },
king
)

expect(date.toString()).toBe('[x].[x]².[x] Sargon (ca. 2334–2279 BCE)')
expect(date.toString()).toBe('[3].[II²].[1] Sargon (ca. 2334 BCE)')
})

it('returns the correct string representation (uncertain)', () => {
Expand All @@ -279,7 +288,7 @@ describe('MesopotamianDate', () => {
{ value: '3', isBroken: true, isUncertain: true },
king
)
expect(date.toString()).toBe('[x]?.[x]²?.[x]? Sargon (ca. 2334–2279 BCE)')
expect(date.toString()).toBe('[3]?.[II²]?.[1]? Sargon (ca. 2334 BCE)')
})

describe('toModernDate branching', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/chronology/domain/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export class MesopotamianDate {
parameter: 'year' | 'day' | 'month',
element: string
): string {
const { isBroken, isUncertain } = this[parameter]
const { isBroken, isUncertain, value } = this[parameter]
let brokenIntercalary = ''
if (isBroken) {
if (isBroken && !value) {
element = 'x'
brokenIntercalary =
parameter === 'month' && this.month.isIntercalary ? '²' : ''
Expand Down Expand Up @@ -190,13 +190,13 @@ export class MesopotamianDate {
let month = parseInt(this.month.value)
let day = parseInt(this.day.value)
const isApproximate = this.isApproximate()
if (isNaN(month) || this.month.isBroken) {
if (isNaN(month)) {
month = 1
}
if (isNaN(day) || this.day.isBroken) {
if (isNaN(day)) {
day = 1
}
if (isNaN(year) || this.year.isBroken) {
if (isNaN(year)) {
year = -1
}
return {
Expand Down

0 comments on commit 596a84a

Please sign in to comment.