diff --git a/library/build.gradle b/library/build.gradle index 3c68db6..4627a83 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -11,6 +11,7 @@ compileTestKotlin { } dependencies { + implementation dep.threetenbp testImplementation dep.junit.core } diff --git a/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendar.kt b/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendar.kt index f0fd2aa..b1e820f 100644 --- a/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendar.kt +++ b/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendar.kt @@ -4,8 +4,17 @@ import com.aminography.primecalendar.base.BaseCalendar import com.aminography.primecalendar.common.CalendarType import com.aminography.primecalendar.common.DateHolder import java.text.DateFormatSymbols -import java.util.* -import java.util.Calendar.* +import java.util.Calendar.DAY_OF_MONTH +import java.util.Calendar.DAY_OF_WEEK +import java.util.Calendar.DAY_OF_WEEK_IN_MONTH +import java.util.Calendar.DAY_OF_YEAR +import java.util.Calendar.MONTH +import java.util.Calendar.SATURDAY +import java.util.Calendar.WEEK_OF_MONTH +import java.util.Calendar.WEEK_OF_YEAR +import java.util.Calendar.YEAR +import java.util.Locale +import java.util.TimeZone /** @@ -138,6 +147,9 @@ class HijriCalendar @JvmOverloads constructor( @Suppress("unused") companion object { + @JvmStatic + var shiftDate: Int = 0 + const val DEFAULT_FIRST_DAY_OF_WEEK = SATURDAY const val DEFAULT_LOCALE = "ar" diff --git a/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendarUtils.kt b/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendarUtils.kt index 06c494c..0ff7e70 100644 --- a/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendarUtils.kt +++ b/library/src/main/java/com/aminography/primecalendar/hijri/HijriCalendarUtils.kt @@ -2,11 +2,18 @@ package com.aminography.primecalendar.hijri import com.aminography.primecalendar.common.DateHolder import com.aminography.primecalendar.hijri.HijriCalendar.Companion.DEFAULT_LOCALE -import java.time.LocalDate -import java.time.chrono.HijrahDate -import java.time.temporal.ChronoField -import java.util.* -import java.util.Calendar.* +import com.aminography.primecalendar.hijri.HijriCalendar.Companion.shiftDate +import org.threeten.bp.LocalDate +import org.threeten.bp.chrono.HijrahDate +import org.threeten.bp.temporal.ChronoField +import java.util.Calendar.FRIDAY +import java.util.Calendar.MONDAY +import java.util.Calendar.SATURDAY +import java.util.Calendar.SUNDAY +import java.util.Calendar.THURSDAY +import java.util.Calendar.TUESDAY +import java.util.Calendar.WEDNESDAY +import java.util.Locale /** * @author aminography @@ -231,6 +238,7 @@ object HijriCalendarUtils { internal fun gregorianToHijri(gregorian: DateHolder): DateHolder { val gregorianDate = LocalDate.of(gregorian.year, gregorian.month + 1, gregorian.dayOfMonth) + .run { plusDays(shiftDate.toLong()) } val hijriDate = HijrahDate.from(gregorianDate) return DateHolder(hijriDate.get(ChronoField.YEAR), hijriDate.get(ChronoField.MONTH_OF_YEAR) - 1, hijriDate.get(ChronoField.DAY_OF_MONTH)) } @@ -238,7 +246,7 @@ object HijriCalendarUtils { internal fun hijriToGregorian(hijri: DateHolder): DateHolder { val hijriDate = HijrahDate.of(hijri.year, hijri.month + 1, hijri.dayOfMonth) val gregorianDate = LocalDate.from(hijriDate) + .run { minusDays(shiftDate.toLong()) } return DateHolder(gregorianDate.get(ChronoField.YEAR), gregorianDate.get(ChronoField.MONTH_OF_YEAR) - 1, gregorianDate.get(ChronoField.DAY_OF_MONTH)) } - } diff --git a/library/src/test/java/com/aminography/primecalendar/ExampleUnitTest.kt b/library/src/test/java/com/aminography/primecalendar/ExampleUnitTest.kt index 3c24560..5116926 100644 --- a/library/src/test/java/com/aminography/primecalendar/ExampleUnitTest.kt +++ b/library/src/test/java/com/aminography/primecalendar/ExampleUnitTest.kt @@ -274,6 +274,8 @@ class ExampleUnitTest { val persian = PersianCalendar() println(persian.longDateString) + HijriCalendar.shiftDate = 1 + val hijri = HijriCalendar() println(hijri.longDateString) diff --git a/settings.gradle b/settings.gradle index 7e5ec7e..a09f2b2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,6 +5,7 @@ enableFeaturePreview('VERSION_CATALOGS') dependencyResolutionManagement { versionCatalogs { dep { + alias('threetenbp').to('org.threeten:threetenbp:1.5.2') alias('junit-core').to('junit:junit:4.13.2') }