meypod / al-azan

Privacy focused ad-free open-source muslim Adhan (islamic prayer times) and qibla app
https://meypod.github.io/al-azan/
GNU Affero General Public License v3.0
183 stars 26 forks source link

add morocco calcution #123

Open K687-aG opened 8 months ago

K687-aG commented 8 months ago

Hi, it's a great and simple app, but I'm encountering a problem with the Morocco time being consistently delayed by 4 minutes. Could you please add Morocco time calculation to the app?

I found some code on GitHub that I believe might help resolve this issue. I hope it works, and you're able to integrate it into the app. Thank you

/*

package com.metinkale.prayerapp.vakit.times;

import com.koushikdutta.ion.Ion; import com.koushikdutta.ion.builder.Builders; import com.metinkale.prayerapp.App;

import org.joda.time.LocalDate;

import java.util.ArrayList; import java.util.List;

class MoroccoTimes extends WebTimes {

@SuppressWarnings("unused")
MoroccoTimes() {
    super();
}

MoroccoTimes(long id) {
    super(id);
}

@Override
public Source getSource() {
    return Source.Morocco;
}

protected Builders.Any.F[] createIonBuilder() {
    LocalDate ldate = LocalDate.now();
    int rY = ldate.getYear();
    int Y = rY;
    int m = ldate.getMonthOfYear();

    final List<Builders.Any.B> queue = new ArrayList<>();
    for (int M = m; (M <= (m + 1)) && (rY == Y); M++) {
        if (M == 13) {
            M = 1;
            Y++;
        }
        queue.add(Ion.with(App.getContext())
                .load("http://www.habous.gov.ma/prieres/defaultmois.php?ville=" + getId() + "&mois=" + M)
                .setTimeout(3000)
        );
    }

    return queue.toArray(new Builders.Any.F[queue.size()]);
}

protected boolean parseResult(String result) {
    String temp = result.substring(result.indexOf("colspan=\"4\" class=\"cournt\""));
    temp = temp.substring(temp.indexOf(">") + 1);
    temp = temp.substring(0, temp.indexOf("<")).replace(" ", "");
    int month = Integer.parseInt(temp.substring(0, temp.indexOf("/")));
    int year = Integer.parseInt(temp.substring(temp.indexOf("/") + 1));
    result = result.substring(result.indexOf("<td>") + 4);
    result = result.replace(" ", "").replace("\t", "").replace("\n", "").replace("\r", "");
    String[] zeiten = result.split("<td>");
    int x = 0;
    for (int i = 0; i < zeiten.length; i++) {
        int day = Integer.parseInt(extract(zeiten[i]));
        String imsak = extract(zeiten[++i]);
        String gunes = extract(zeiten[++i]);
        String ogle = extract(zeiten[++i]);
        String ikindi = extract(zeiten[++i]);
        String aksam = extract(zeiten[++i]);
        String yatsi = extract(zeiten[++i]);

        setTimes(new LocalDate(year, month, day), new String[]{imsak, gunes, ogle, ikindi, aksam, yatsi});
        x++;
    }

    return x > 0;
}

private String extract(String s) {
    return s.substring(0, s.indexOf("<"));
}

}

meypod commented 8 months ago

Hi the code you provided does not contain the calculation parameters for Morocco, it simply loads times from a server the app calculates the times completely offline, so it needs calculation parameters that Morocco uses to generate the prayer times

the best you can do is find the parameters that produces the correct times all year round when compared and use that

I'm not sure, but I think I did not manage to find them back when I was adding calculation times, along with some other methods. some of them may have some special calculation process that simply can't be done with the way app works.