ThreeTen / threeten-extra

Provides additional date-time classes that complement those in JDK 8
http://www.threeten.org/threeten-extra/
BSD 3-Clause "New" or "Revised" License
387 stars 77 forks source link

Calculation problem #149

Closed lsgmkk closed 4 years ago

lsgmkk commented 4 years ago

I have a question, when using this library to calculate HijrahDate, sometimes it is a day late. E.g Convert today 2020-1-7 to HijrahDate: 1441-5-12 But the result calculated using this library is: 1441-5-11 What is the reason at this time?

catull commented 4 years ago

Can you show some code ?

Java 8+ bases the Hijrah calendar of the "Umm al-Qura". It is a calculation-based calendar.

It is therefore not based on the actual sighting of the lunar crescent (hilāl).

I see you already asked the question here: https://github.com/JakeWharton/ThreeTenABP/issues/118 There the platform is Android, which is based on Java 6.

I see you are not specifying any time zone, not sure if it changes anything. Also, Androids DateTimeFormatter may be based on UTC, and thus a day starts at midnight, whereas the Islamic calendar considers sunset to be cut-off.

Do you remember when exactly you tried your code ?

catull commented 4 years ago

This page https://www.al-habib.info/islamic-calendar/ummulqura/islamic-calendar-ummulqura-2020-ce.htm gives Jan 7th 2020 as 1441-05-12, as you expect it.

lsgmkk commented 4 years ago

I have a problem using JakeWharton / ThreeTenABP I configured the source code using java8 JakeWharton called me here to find the answer Any suggestions for Android?

lsgmkk commented 4 years ago

This is my code:

@RequiresApi(Build.VERSION_CODES.O)
fun test() {
    var hijrahDate = HijrahDate.now()
    var of1 = org.threeten.bp.LocalDate.of(2020, 2, 24)
    var date1 = HijrahDate.from(of1)
    var pattern = org.threeten.bp.format.DateTimeFormatter.ofPattern("MM/dd/yyyy")
    var s = pattern.format(date1)

    Log.e("TAG", "test 1-------->$s")

    var ofPattern = DateTimeFormatter.ofPattern("MM/dd/yyyy")
    var now = java.time.chrono.HijrahDate.now()
    var of = LocalDate.of(2020, 2, 24)
    var date = java.time.chrono.HijrahDate.from(of)
    var format = ofPattern.format(date)
    Log.e("TAG", "test 2--------->$format")
}

test 2 is the acquisition method provided by Android 8.0, which can get correct results

catull commented 4 years ago

JakeWarton actually referred you to https://github.com/ThreeTen/threetenbp/. This is the back-port of jsr-310 to Java 6+.

This is https://github.com/ThreeTen/threeten-extra. This is a "playground" to develop calendar models for Java 8+.

Look into timezone, see if that changes anything.

E.g.

fun test() {
    var hijrahDate = HijrahDate.now()
    var of1 = org.threeten.bp.LocalDate.of(2020, 2, 24)
    var date1 = HijrahDate.from(of1)
    var pattern = org.threeten.bp.format.DateTimeFormatter.ofPattern("MM/dd/yyyy")
    var s = date1.format(pattern.withZone(ZoneId.of("Asia/Riyadh")))

    Log.e("TAG", "test 1-------->$s")
}

Good luck. Can't help you with Android, I am afraid.

lsgmkk commented 4 years ago

no change.....

jodastephen commented 4 years ago

FWIW, I can't guarantee the quality of the Hijrah date code is as high as the ISO date code. This is because Oracle did most of the work on HijrahDate after the project went GPL licensed. As such, I'm unable to work on HijrahDate without polluting this codebase with GPL licensed code.