Closed hsravat-4590 closed 2 years ago
Wa3laikum alsalam, I can't repro this - here's what I did (modifying the sample of both the KMP and non-KMP versions) -
Kotlin Multiplatform
object Example {
private fun Instant.asDate() = Date(toEpochMilliseconds())
@JvmStatic
fun main(args: Array<String>) {
val coordinates = Coordinates(57.1499, 2.0938)
val dateComponents = DateComponents(2022, 6, 25)
val parameters: CalculationParameters = CalculationMethod.KARACHI.parameters
val prayerTimes = PrayerTimes(coordinates, dateComponents, parameters)
val formatter = SimpleDateFormat("hh:mm a")
formatter.timeZone = TimeZone.getTimeZone("Asia/Riyadh")
println("Fajr: " + formatter.format(prayerTimes.fajr.asDate()))
println("Sunrise: " + formatter.format(prayerTimes.sunrise.asDate()))
println("Dhuhr: " + formatter.format(prayerTimes.dhuhr.asDate()))
println("Asr: " + formatter.format(prayerTimes.asr.asDate()))
println("Maghrib: " + formatter.format(prayerTimes.maghrib.asDate()))
println("Isha: " + formatter.format(prayerTimes.isha.asDate()))
}
}
output:
Fajr: 02:54 AM
Sunrise: 05:57 AM
Dhuhr: 02:55 PM
Asr: 07:29 PM
Maghrib: 11:52 PM
Isha: 02:54 AM
Java:
public class Example {
public static void main(String[] args) {
final Coordinates coordinates = new Coordinates(57.1499, 2.0938);
final DateComponents dateComponents = new DateComponents(2022, 6, 25);
final CalculationParameters parameters =
CalculationMethod.KARACHI.getParameters();
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm a");
formatter.setTimeZone(TimeZone.getTimeZone("Asia/Riyadh"));
PrayerTimes prayerTimes = new PrayerTimes(coordinates, dateComponents, parameters);
System.out.println("Fajr: " + formatter.format(prayerTimes.fajr));
System.out.println("Sunrise: " + formatter.format(prayerTimes.sunrise));
System.out.println("Dhuhr: " + formatter.format(prayerTimes.dhuhr));
System.out.println("Asr: " + formatter.format(prayerTimes.asr));
System.out.println("Maghrib: " + formatter.format(prayerTimes.maghrib));
System.out.println("Isha: " + formatter.format(prayerTimes.isha));
}
}
output:
Fajr: 02:54 AM
Sunrise: 05:57 AM
Dhuhr: 02:55 PM
Asr: 07:29 PM
Maghrib: 11:52 PM
Isha: 02:54 AM
I would be curious as to the implementation of your DateComponents.fromLocalDate(testDate)
function, since that's the only piece that seems to be different.
For what it's worth, I also tried using the built in method for converting a LocalDateTime
to a DateComponents
(which got me the correct result also):
DateComponents.fromLocalDateTime(LocalDateTime(year = 2022, monthNumber = 6, dayOfMonth = 25, hour = 12, minute = 0, 0))
closing since this is working for me
Assalam Mualaykum,
I've been trying to implement the Kotlin Multiplatform branch and have come across some disrepencies between the Java Version and KMP versions:
Java
Test Code:
This produces the following result:
Kotlin Multi Platfrom
note: I added a simple method to DateComponents to allow creation with
LocalDate
This produces the following result:
Can anyone offer a hand on why this might be? I suspect it's to do with
LocalDate
converisons as I wasn't able to find anything different in theAstronomical
andCalendricalHelper
Classes