Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add morocco calcution #123

Open
K687-aG opened this issue Mar 23, 2024 · 1 comment
Open

add morocco calcution #123

K687-aG opened this issue Mar 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@K687-aG
Copy link

K687-aG commented Mar 23, 2024

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

/*

  • Copyright (c) 2016 Metin Kale
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
    */

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("<"));
}

}

@K687-aG K687-aG added the enhancement New feature or request label Mar 23, 2024
@meypod
Copy link
Owner

meypod commented Mar 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants