batoulapps / adhan-js

High precision Islamic prayer time library for JavaScript
MIT License
376 stars 86 forks source link

feat(calculation params): adds shafaq parameter #79

Closed z3bi closed 2 years ago

z3bi commented 2 years ago

Adds a new property to calculation parameters shafaq that is used by the MoonsightingCommittee method to calculate Isha.

Fixes #78

korbav commented 2 years ago

Great enhancement.

I just ran through the code and did some tests, the code itself and the appropriate tests look fine.

I noticed a one minute offset for Asr running the 3 tests below (in comparison to https://moonsighting.com/pray.php) This offset might not at all be related to the MoonsightingCommittee method and might rather be related to a different rounding since it's not more than 1 minute, which seems absolutely fine to be honest, I just wanted to let you know in the case it's nastier than it looks to be :

describe("Moonsighting Committee method Toronto", () => {
    test('Shafaq general', () => {
        const date = new Date(2021, 2, 28);
        const params = adhan.CalculationMethod.MoonsightingCommittee();
        params.shafaq = Shafaq.General;
        params.madhab = adhan.Madhab.Hanafi;
        const p = new adhan.PrayerTimes(new adhan.Coordinates(43.494443,-79.843998), date, params);
        expect(moment(p.fajr).tz("America/Toronto").format("h:mm A")).toBe("5:36 AM");
        expect(moment(p.sunrise).tz("America/Toronto").format("h:mm A")).toBe("7:08 AM");
        expect(moment(p.dhuhr).tz("America/Toronto").format("h:mm A")).toBe("1:29 PM");
        // expect(moment(p.asr).tz("America/Toronto").format("h:mm A")).toBe("5:49 PM"); // Will return 5:50 PM instead
        expect(moment(p.maghrib).tz("America/Toronto").format("h:mm A")).toBe("7:45 PM");
        expect(moment(p.isha).tz("America/Toronto").format("h:mm A")).toBe("8:57 PM");
    });

    test('Shafaq ahmer', () => {
        const date = new Date(2021, 2, 28);
        const params = adhan.CalculationMethod.MoonsightingCommittee();
        params.shafaq = Shafaq.Ahmer;
        const p = new adhan.PrayerTimes(new adhan.Coordinates(43.494443,-79.843998), date, params);
        expect(moment(p.fajr).tz("America/Toronto").format("h:mm A")).toBe("5:36 AM");
        expect(moment(p.sunrise).tz("America/Toronto").format("h:mm A")).toBe("7:08 AM");
        expect(moment(p.dhuhr).tz("America/Toronto").format("h:mm A")).toBe("1:29 PM");
        // expect(moment(p.asr).tz("America/Toronto").format("h:mm A")).toBe("4:56 PM"); // Will return 4:57 PM instead
        expect(moment(p.maghrib).tz("America/Toronto").format("h:mm A")).toBe("7:45 PM");
        expect(moment(p.isha).tz("America/Toronto").format("h:mm A")).toBe("8:39 PM");
    });

    test('Shafaq Abyad', () => {
        const date = new Date(2021, 2, 28);
        const params = adhan.CalculationMethod.MoonsightingCommittee();
        params.shafaq = Shafaq.Abyad;
        params.madhab = adhan.Madhab.Hanafi;
        const p = new adhan.PrayerTimes(new adhan.Coordinates(43.494443,-79.843998), date, params);
        expect(moment(p.fajr).tz("America/Toronto").format("h:mm A")).toBe("5:36 AM");
        expect(moment(p.sunrise).tz("America/Toronto").format("h:mm A")).toBe("7:08 AM");
        expect(moment(p.dhuhr).tz("America/Toronto").format("h:mm A")).toBe("1:29 PM");
        // expect(moment(p.asr).tz("America/Toronto").format("h:mm A")).toBe("5:49 PM"); // Will return 5:50 PM instead
        expect(moment(p.maghrib).tz("America/Toronto").format("h:mm A")).toBe("7:45 PM");
        expect(moment(p.isha).tz("America/Toronto").format("h:mm A")).toBe("9:05 PM");
    });
});

If it's, as I think, neglectable, then it looks totally mergeable as it is.

codecov[bot] commented 2 years ago

Codecov Report

Merging #79 (4c62bdf) into develop (4139073) will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #79      +/-   ##
===========================================
+ Coverage    99.26%   99.28%   +0.01%     
===========================================
  Files           18       19       +1     
  Lines          546      558      +12     
  Branches        96       98       +2     
===========================================
+ Hits           542      554      +12     
  Misses           4        4              
Impacted Files Coverage Δ
src/Astronomical.js 100.00% <100.00%> (ø)
src/CalculationParameters.js 100.00% <100.00%> (ø)
src/PrayerTimes.js 100.00% <100.00%> (ø)
src/Shafaq.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 73e3c87...4c62bdf. Read the comment docs.

z3bi commented 2 years ago

@korbav thank you for double checking the time values, yes I noticed the 1 minute discrepancy in the Asr times. It doesn't seem to be a consistent issue and is most likely explained by rounding differences. Since this change is unrelated to the Asr times I think we're ok to proceed.

github-actions[bot] commented 2 years ago

:tada: This PR is included in version 4.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: