From 2f4d3e9ca8a9db1864a70266832449a6dda09ef2 Mon Sep 17 00:00:00 2001 From: Ilya Khait Date: Fri, 22 Sep 2023 14:02:42 +0000 Subject: [PATCH] Refactor more --- src/fragmentarium/domain/DateConverterBase.ts | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/fragmentarium/domain/DateConverterBase.ts b/src/fragmentarium/domain/DateConverterBase.ts index 5b12d1982..3f76dc5b0 100644 --- a/src/fragmentarium/domain/DateConverterBase.ts +++ b/src/fragmentarium/domain/DateConverterBase.ts @@ -200,14 +200,11 @@ export default class DateConverterBase { private applySeleucidDate(props: CalendarUpdateProps): void { const { seBabylonianYear, mesopotamianMonth } = props - const seMacedonianYear = - seBabylonianYear > 0 && mesopotamianMonth < 7 - ? seBabylonianYear - : seBabylonianYear > -1 && mesopotamianMonth > 6 - ? seBabylonianYear + 1 - : undefined - const seArsacidYear = - seBabylonianYear >= 65 ? seBabylonianYear - 64 : undefined + const seMacedonianYear = this.calculateSeMacedonianYear( + seBabylonianYear, + mesopotamianMonth + ) + const seArsacidYear = this.calculateSeArsacidYear(seBabylonianYear) this.calendar = { ...this.calendar, seBabylonianYear, @@ -215,4 +212,21 @@ export default class DateConverterBase { seArsacidYear, } } + + private calculateSeMacedonianYear( + seBabylonianYear: number, + mesopotamianMonth: number + ): number | undefined { + if (seBabylonianYear > 0 && mesopotamianMonth < 7) { + return seBabylonianYear + } + if (seBabylonianYear > -1 && mesopotamianMonth > 6) { + return seBabylonianYear + 1 + } + return undefined + } + + private calculateSeArsacidYear(seBabylonianYear: number): number | undefined { + return seBabylonianYear >= 65 ? seBabylonianYear - 64 : undefined + } }