Example usage for org.joda.time LocalDate now

List of usage examples for org.joda.time LocalDate now

Introduction

In this page you can find the example usage for org.joda.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.metinkale.prayerapp.vakit.times.MalaysiaTimes.java

License:Apache License

@NonNull
protected Builders.Any.F[] createIonBuilder() {
    LocalDate ldate = LocalDate.now();
    int rY = ldate.getYear();
    int Y = rY;// ww  w  .j a v a 2  s.co m
    int m = ldate.getMonthOfYear();
    String[] split = getId().split("_");
    if (split.length < 3)
        delete();
    split[1] = URLEncoder.encode(split[1]);
    split[2] = URLEncoder.encode(split[2]);

    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.get()).load("http://www.e-solat.gov.my/web/waktusolat.php?negeri=" + split[1]
                        + "&state=" + split[1] + "&zone=" + split[2] + "&year=" + Y + "&jenis=year&bulan=" + M)
                .setTimeout(3000));
    }

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

From source file:com.metinkale.prayerapp.vakit.times.MoroccoTimes.java

License:Apache License

@NonNull
protected Builders.Any.F[] createIonBuilder() {
    LocalDate ldate = LocalDate.now();
    int rY = ldate.getYear();
    int Y = rY;/*  w w w  .j  a  va 2s.c o m*/
    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.get()).load(
                "http://www.habous.gov.ma/prieres/defaultmois.php?ville=" + getId().substring(2) + "&mois=" + M)
                .setTimeout(3000));
    }

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

From source file:com.metinkale.prayerapp.vakit.times.NVCTimes.java

License:Apache License

protected boolean parseResult(@NonNull String result) {
    int i = 0;//from  ww  w.  j av a2  s  . c om
    String[] lines = result.split("\n");

    int y = LocalDate.now().getYear();
    for (String line : lines) {
        if (line.contains("<prayertimes")) {
            String day = line.substring(line.indexOf("day=") + 5);
            String month = line.substring(line.indexOf("month=") + 7);
            day = day.substring(0, day.indexOf("\""));
            month = month.substring(0, month.indexOf("\""));
            if (day.length() == 1) {
                day = "0" + day;
            }
            if (month.length() == 1) {
                month = "0" + month;
            }
            String data = line.substring(line.indexOf(">") + 1, line.lastIndexOf("<"));
            data = data.replace("*", "").replace("\t", " ");
            List<String> d = new ArrayList<>(Arrays.asList(data.split(" ")));
            d.remove(15);
            d.remove(14);
            d.remove(13);
            d.remove(12);
            d.remove(10);
            d.remove(8);
            d.remove(7);
            d.remove(4);
            d.remove(3);
            d.remove(1);

            data = "";
            for (String s : d) {
                if (s.length() == 4) {
                    data += " 0" + s;
                } else {
                    data += " " + s;
                }
            }
            setTimes(new LocalDate(y, Integer.parseInt(month), Integer.parseInt(day)),
                    data.substring(1).split(" "));
            i++;
        }

    }
    return i > 25;
}

From source file:com.metinkale.prayerapp.vakit.times.SemerkandTimes.java

License:Apache License

@NonNull
protected Builders.Any.F[] createIonBuilder() {
    String _id = getId();/*from w w w . j a v  a 2s .c om*/
    if (_id.equals("S_2_140_0")) {
        _id = "S_2_1052_0";
        setId(_id);
    }
    final int year = LocalDate.now().getYear();
    final String[] id = _id.split("_");
    return new Builders.Any.F[] {
            Ion.with(App.get()).load("http://77.79.123.10/semerkandtakvimi/query/SalaatTimes?year=" + year + "&"
                    + (id.length >= 3 || "0".equals(id[3]) ? "cityID=" + id[2] : "countyID=" + id[3])) };

}

From source file:com.metinkale.prayerapp.vakit.times.SemerkandTimes.java

License:Apache License

protected boolean parseResult(String r) {
    LocalDate date = LocalDate.now();
    List<Day> result = new Gson().fromJson(r, new TypeToken<List<Day>>() {
    }.getType());//from   ww w .  ja v a 2 s.c  om
    for (Day d : result) {
        date = date.withDayOfYear(d.Day);
        setTimes(date, new String[] { d.Fajr, d.Tulu, d.Zuhr, d.Asr, d.Maghrib, d.Isha });
    }
    return result.size() > 25;
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

@NonNull
private Collection<Alarm> getAlarms() {
    Collection<Alarm> alarms = new ArrayList<>();

    LocalDate cal = LocalDate.now();
    for (int ii = 0; ii <= 1/* next day */; ii++) {
        for (Vakit v : Vakit.values()) {
            if (isNotificationActive(v)) {
                if (v != Vakit.SABAH) {
                    int vakit = v.ordinal();
                    if (vakit != 0) {
                        vakit--;/* w  w  w .j  a v  a 2  s.c  o  m*/
                    }

                    long mills = getTimeCal(cal, vakit).toDateTime().getMillis();
                    if (System.currentTimeMillis() < mills) {
                        Alarm a = new Alarm();
                        a.city = getID();
                        a.early = false;
                        a.cuma = false;
                        a.time = mills;
                        a.vakit = v;
                        a.dayOffset = ii;
                        alarms.add(a);
                    }
                } else {
                    long mills;
                    if (isAfterImsak()) {
                        mills = getTimeCal(cal, 0).toDateTime().getMillis() + getSabahTime() * 60 * 1000;
                    } else {
                        mills = getTimeCal(cal, 1).toDateTime().getMillis() - getSabahTime() * 60 * 1000;
                    }
                    if (System.currentTimeMillis() < mills) {
                        Alarm a = new Alarm();
                        a.city = getID();
                        a.cuma = false;
                        a.early = false;
                        a.time = mills;
                        a.vakit = v;
                        a.dayOffset = ii;
                        alarms.add(a);
                    }
                }
            }

            if (isEarlyNotificationActive(v)) {
                if (v != Vakit.SABAH) {
                    int vakit = v.ordinal();
                    if (vakit != 0) {
                        vakit--;
                    }

                    int early = getEarlyTime(v);
                    long mills = getTimeCal(cal, vakit).toDateTime().getMillis() - early * 60 * 1000;
                    if (System.currentTimeMillis() < mills) {
                        Alarm a = new Alarm();
                        a.city = getID();
                        a.early = true;
                        a.cuma = false;
                        a.time = mills;
                        a.vakit = v;
                        a.dayOffset = ii;
                        alarms.add(a);
                    }
                }
            }
        }
        cal = cal.plusDays(1);
    }
    if (isCumaActive()) {

        int early = getCumaTime();

        DateTime c = DateTime.now().withDayOfWeek(DateTimeConstants.FRIDAY);
        if ((c.getMillis() + 1000) < System.currentTimeMillis()) {
            c = c.plusWeeks(1);
        }
        long mills = getTimeCal(c.toLocalDate(), 2).toDateTime().getMillis();
        mills -= early * 60 * 1000;
        if (System.currentTimeMillis() < mills) {
            Alarm a = new Alarm();
            a.city = getID();
            a.cuma = true;
            a.early = false;
            a.time = mills;
            a.vakit = Vakit.OGLE;
            a.dayOffset = 0;
            alarms.add(a);
        }
    }

    return alarms;
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

@NonNull
private LocalDateTime getTimeCal(@Nullable LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();
    }/*  w  w  w.j  av  a2 s  .  c  om*/
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time <= -1) {
            date = date.minusDays(1);
            time += 6;
        }
    }

    LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time)));
    int h = timeCal.getHourOfDay();
    if ((time >= 3) && (h < 5)) {
        timeCal = timeCal.plusDays(1);
    }
    return timeCal;
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

public String getTime(@Nullable LocalDate date, int time) {
    if (date == null) {
        date = LocalDate.now();
    }//  w w w  .jav  a 2  s  . c  om
    if ((time < 0) || (time > 5)) {
        while (time >= 6) {
            date = date.plusDays(1);
            time -= 6;
        }

        while (time == -1) {
            date = date.minusDays(1);
            time += 6;
        }

    }
    return adj(_getTime(date, time), time);
}

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

public int getNext() {
    LocalDate today = LocalDate.now();
    LocalDateTime now = LocalDateTime.now();
    for (int i = 0; i < 6; i++) {
        if (getTimeCal(today, i).isAfter(now)) {
            return i;
        }/*from  w  ww  . ja  v  a2s.  co m*/
    }
    return 6;
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

private int getSyncedDays() {
    LocalDate date = LocalDate.now().plusDays(1);
    int i = 0;/*ww  w.ja va 2s  .c  om*/
    while (i < 45) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String times[] = { this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2),
                this.times.get(prefix + 3), this.times.get(prefix + 4), this.times.get(prefix + 5) };
        for (String time : times) {
            if (time == null || time.contains("00:00"))
                return i;
        }
        i++;
        date = date.plusDays(1);
    }
    return i;

}