Skip to content

Commit

Permalink
Fix cjdn calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Oct 5, 2023
1 parent 6bec43b commit 674f3be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/chronology/domain/DateConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class DateConverter extends DateConverterBase {

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

offsetMonth(offset: number): void {
Expand All @@ -53,18 +53,17 @@ export default class DateConverter extends DateConverterBase {
month,
day: this.calendar.day,
})
this.updateBabylonDate()
this.updateBabylonianDate()
}

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

setToModernDate(year: number, month: number, day: number): void {
console.log('!!!', [year, month, day])
this.applyModernDate({ year, month, day })
this.updateBabylonDate()
this.updateBabylonianDate()
}

setSeBabylonianDate(
Expand Down
18 changes: 12 additions & 6 deletions src/chronology/domain/DateConverterBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class DateConverterBase {
setFromCjdn(cjdn: number): void {
const [year, month, day] = this.computeModernDateFromCjnd(cjdn)
this.applyModernDate({ year, month, day })
this.updateBabylonDate(cjdn)
this.updateBabylonianDate(cjdn)
}

applyModernDate({
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class DateConverterBase {
return ((currentMonth + offset + 11) % 12) + 1
}

updateBabylonDate(
updateBabylonianDate(
cjdn: number = this.computeCjdnFromModernDate(
this.calendar.year,
this.calendar.month,
Expand Down Expand Up @@ -142,11 +142,17 @@ export default class DateConverterBase {
month: number,
day: number
): number {
const a = Math.floor((14 - month) / 12)
const y = year + 4800 - a
const m = month + 12 * a - 3
return (
Math.floor(365.25 * (month < 3 ? year - 1 : year + 4716)) +
Math.floor(30.6001 * (month < 3 ? month + 12 : month + 1)) +
day -
1524
day +
Math.floor((153 * m + 2) / 5) +
365 * y +
Math.floor(y / 4) -
Math.floor(y / 100) +
Math.floor(y / 400) -
32045
)
}

Expand Down
6 changes: 4 additions & 2 deletions src/chronology/ui/DateConverterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import MarkupService from 'markup/application/MarkupService'
import Markup from 'markup/ui/markup'

// ToDo:
// - Fix errors. Selecting December - February.
// - General range: 29 March 626 BCE - 22 February 76 CE. Update description.
// - Month: 626 BCE - until March only, 76 CE - until February (incl.)
// - Day: Count the days in the month and implement selectable options. Special: March 626 BCE - until the 29. February 76 CE (both incl.)
// - Mesopotamian month & day should be selectable. Month displayed as text with latin number. Days (both modern & Mes.) should be restricted to the actual number.
// - Regnal years should be selectable and restricted too.
// - Check the valid range and adjust
Expand Down Expand Up @@ -182,7 +184,7 @@ function DateConverterForm(): JSX.Element {

function getOptions(field: Field): JSX.Element[] {
if (field.name === 'year') {
return getNumberRangeOptions(-624, 75, getYearOptionLabel)
return getNumberRangeOptions(-625, 76, getYearOptionLabel)
}
const namesArray =
field.name === 'month'
Expand Down

0 comments on commit 674f3be

Please sign in to comment.