Skip to content

Commit

Permalink
Julian and Gregorian dates correction (WiP)
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Oct 9, 2023
1 parent 674f3be commit 20f9ce2
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 124 deletions.
10 changes: 5 additions & 5 deletions src/chronology/domain/Date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ describe('MesopotamianDate', () => {
expect(date.toString()).toBe('[3]?.[II²]?.[1]? Sargon (ca. 2334 BCE)')
})

describe('toModernDate branching', () => {
describe('toJulianDate branching', () => {
it('returns empty when none of the conditions are met', () => {
const date = new MesopotamianDate(
{ value: '1' },
{ value: '1' },
{ value: '1' }
)
expect(date.toModernDate()).toBe('')
expect(date.toJulianDate()).toBe('')
})

it('returns the correct modern date for a king without orderGlobal', () => {
Expand All @@ -309,7 +309,7 @@ describe('MesopotamianDate', () => {
{ value: '12' },
unorderedKing
)
expect(date.toModernDate()).toBe('ca. 2325 BCE')
expect(date.toJulianDate()).toBe('ca. 2325 BCE')
})
})

Expand All @@ -322,7 +322,7 @@ describe('MesopotamianDate', () => {
kingWithSpecificOrder
)

const result = date.toModernDate()
const result = date.toJulianDate()
expect(result).toBe('ca. 2334 BCE')
})

Expand All @@ -335,6 +335,6 @@ describe('MesopotamianDate', () => {
kingWithoutDate
)

expect(date.toModernDate()).toBe('')
expect(date.toJulianDate()).toBe('')
})
})
24 changes: 12 additions & 12 deletions src/chronology/domain/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export class MesopotamianDate {
this.monthToString(),
this.yearToString(),
]
let modernDate = this.toModernDate()
modernDate = modernDate ? ` (${modernDate})` : ''
let julianDate = this.toJulianDate()
julianDate = julianDate ? ` (${julianDate})` : ''
return `${dateParts.join(
'.'
)}${this.kingEponymOrEraToString()}${this.ur3CalendarToString()}${modernDate}`
)}${this.kingEponymOrEraToString()}${this.ur3CalendarToString()}${julianDate}`
}

private parameterToString(
Expand Down Expand Up @@ -150,16 +150,16 @@ export class MesopotamianDate {
return this.ur3Calendar ? `, ${this.ur3Calendar} calendar` : ''
}

toModernDate(): string {
toJulianDate(): string {
const { year, month, day, isApproximate } = this.getDateApproximation()
let result = ''
if (this.isSeleucidEra && year > 0) {
result = this.seleucidToModernDate(year, month, day, isApproximate)
result = this.seleucidToJulianDate(year, month, day, isApproximate)
} else if (
this.king?.orderGlobal &&
Object.values(data.rulerToBrinkmanKings).includes(this.king?.orderGlobal)
) {
result = this.nabonassarEraToModernDate(
result = this.nabonassarEraToJulianDate(
year > 0 ? year : 1,
month,
day,
Expand All @@ -168,7 +168,7 @@ export class MesopotamianDate {
} else if (this.isAssyrianDate && this.eponym?.date) {
result = `ca. ${this.eponym?.date} BCE`
} else if (this.king?.date) {
result = this.kingToModernDate(year)
result = this.kingToJulianDate(year)
}
return result
}
Expand Down Expand Up @@ -228,7 +228,7 @@ export class MesopotamianDate {
].includes(true)
}

private seleucidToModernDate(
private seleucidToJulianDate(
year: number,
month: number,
day: number,
Expand All @@ -237,12 +237,12 @@ export class MesopotamianDate {
const converter = new DateConverter()
converter.setSeBabylonianDate(year, month, day)
return this.insertDateApproximation(
converter.toModernDateString(),
converter.toJulianDateString(),
isApproximate
)
}

private nabonassarEraToModernDate(
private nabonassarEraToJulianDate(
year: number,
month: number,
day: number,
Expand All @@ -255,13 +255,13 @@ export class MesopotamianDate {
const converter = new DateConverter()
converter.setMesopotamianDate(kingName, year, month, day)
return this.insertDateApproximation(
converter.toModernDateString(),
converter.toJulianDateString(),
isApproximate
)
}
return ''
}
private kingToModernDate(year: number): string {
private kingToJulianDate(year: number): string {
const firstReignYear = this.king?.date?.split('-')[0]
return firstReignYear !== undefined && year > 0
? `ca. ${parseInt(firstReignYear) - year + 1} BCE`
Expand Down
48 changes: 24 additions & 24 deletions src/chronology/domain/DateConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ describe('DateConverter', () => {
mesopotamianDate = new DateConverter()
})

test('Set modern date', () => {
test('Set to Julian date', () => {
const expected = {
year: -560,
month: 4,
day: 3,
bcYear: 561,
julianYear: -560,
julianMonth: 4,
julianDay: 3,
bcJulianYear: 561,
cjdn: 1516611,
weekDay: 7,
mesopotamianDay: 28,
Expand All @@ -23,17 +23,17 @@ describe('DateConverter', () => {
seBabylonianYear: -250,
lunationNabonassar: 2302,
}
mesopotamianDate.setToModernDate(-560, 4, 3)
mesopotamianDate.setToJulianDate(-560, 4, 3)
expect(mesopotamianDate.calendar).toEqual(expected)
expect(mesopotamianDate.toModernDateString()).toEqual('3 April 561 BCE')
expect(mesopotamianDate.toJulianDateString()).toEqual('3 April 561 BCE')
})

test('Set Mesopotamian date', () => {
const expected = {
year: -580,
month: 1,
day: 3,
bcYear: 581,
julianYear: -580,
julianMonth: 1,
julianDay: 3,
bcJulianYear: 581,
cjdn: 1509215,
weekDay: 3,
mesopotamianDay: 14,
Expand All @@ -46,7 +46,7 @@ describe('DateConverter', () => {
}
mesopotamianDate.setMesopotamianDate('Nebuchadnezzar II', 23, 10, 14)
expect(mesopotamianDate.calendar).toEqual(expected)
expect(mesopotamianDate.toModernDateString()).toEqual('3 January 581 BCE')
expect(mesopotamianDate.toJulianDateString()).toEqual('3 January 581 BCE')
})

test('Set Seleucid date', () => {
Expand All @@ -55,39 +55,39 @@ describe('DateConverter', () => {
lunationNabonassar: 6631,
ruler: 'Antiochus III [the Great]',
regnalYear: 11,
bcYear: 211,
day: 3,
bcJulianYear: 211,
julianDay: 3,
cjdn: 1644448,
month: 4,
julianMonth: 4,
seBabylonianYear: 100,
seMacedonianYear: 101,
seArsacidYear: 36,
mesopotamianDay: 26,
mesopotamianMonth: 12,
mesopotamianMonthLength: 29,
weekDay: 3,
year: -210,
julianYear: -210,
}
expect(mesopotamianDate.calendar).toEqual(expected)
expect(mesopotamianDate.toModernDateString()).toEqual('3 April 211 BCE')
expect(mesopotamianDate.toJulianDateString()).toEqual('3 April 211 BCE')
})

test('Offset year', () => {
mesopotamianDate.offsetYear(100)
expect(mesopotamianDate.calendar.year).toBe(-210)
expect(mesopotamianDate.toModernDateString()).toEqual('3 March 211 BCE')
expect(mesopotamianDate.calendar.julianYear).toBe(-210)
expect(mesopotamianDate.toJulianDateString()).toEqual('3 March 211 BCE')
})

test('Offset month', () => {
mesopotamianDate.offsetMonth(5)
expect(mesopotamianDate.calendar.month).toBe(8)
expect(mesopotamianDate.calendar.year).toBe(-310)
expect(mesopotamianDate.toModernDateString()).toEqual('3 August 311 BCE')
expect(mesopotamianDate.calendar.julianMonth).toBe(8)
expect(mesopotamianDate.calendar.julianYear).toBe(-310)
expect(mesopotamianDate.toJulianDateString()).toEqual('3 August 311 BCE')
})

test('Offset day', () => {
mesopotamianDate.offsetDay(10)
expect(mesopotamianDate.calendar.day).toBe(13)
expect(mesopotamianDate.toModernDateString()).toEqual('13 March 311 BCE')
expect(mesopotamianDate.calendar.julianDay).toBe(13)
expect(mesopotamianDate.toJulianDateString()).toEqual('13 March 311 BCE')
})
})
42 changes: 26 additions & 16 deletions src/chronology/domain/DateConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,50 @@ export const weekDayNames = [
export default class DateConverter extends DateConverterBase {
constructor() {
super()
this.setToModernDate(-310, 3, 3)
this.setToJulianDate(-310, 3, 3)
}

toModernDateString(): string {
const { day, month, year, bcYear } = this.calendar
const suffix = year < 0 ? ' BCE' : ' CE'
return `${day} ${monthNames[month - 1]} ${
year < 0 ? bcYear : year
toJulianDateString(): string {
const { julianDay, julianMonth, julianYear, bcJulianYear } = this.calendar
const suffix = julianYear < 0 ? ' BCE' : ' CE'
return `${julianDay} ${monthNames[julianMonth - 1]} ${
julianYear < 0 ? bcJulianYear : julianYear
}${suffix}`
}

offsetYear(offset: number): void {
this.calendar.year += offset
this.calendar.julianYear += offset
this.updateBabylonianDate()
}

offsetMonth(offset: number): void {
const yearOffset = this.calculateYearOffset(this.calendar.month, offset)
const month = this.calculateNewMonth(this.calendar.month, offset)
this.applyModernDate({
year: this.calendar.year + yearOffset,
month,
day: this.calendar.day,
const yearOffset = this.calculateYearOffset(
this.calendar.julianMonth,
offset
)
const julianMonth = this.calculateNewMonth(
this.calendar.julianMonth,
offset
)
this.applyJulianDate({
julianYear: this.calendar.julianYear + yearOffset,
julianMonth,
julianDay: this.calendar.julianDay,
})
this.updateBabylonianDate()
}

offsetDay(offset: number): void {
this.calendar.day += offset
this.calendar.julianDay += offset
this.updateBabylonianDate()
}

setToModernDate(year: number, month: number, day: number): void {
this.applyModernDate({ year, month, day })
setToJulianDate(
julianYear: number,
julianMonth: number,
julianDay: number
): void {
this.applyJulianDate({ julianYear, julianMonth, julianDay })
this.updateBabylonianDate()
}

Expand Down
Loading

0 comments on commit 20f9ce2

Please sign in to comment.