List of usage examples for org.joda.time LocalDate plusDays
public LocalDate plusDays(int days)
From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
private LocalDate moveToNextRequestedWeekdayByDirection(FixedWeekdayInMonth fwm, LocalDate date, int direction) { int weekDay = xmlUtil.getWeekday(fwm.getWeekday()); while (date.getDayOfWeek() != weekDay) { date = date.plusDays(direction); }//from w w w.ja v a2 s . c o m return date; }
From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java
License:Apache License
/** * Parses the provided configuration and creates holidays for the provided * year.// w w w .j a v a 2s.c om */ public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (FixedWeekdayRelativeToFixed f : config.getFixedWeekdayRelativeToFixed()) { if (!isValid(f, year)) { continue; } LocalDate day = calendarUtil.create(year, f.getDay()); day = moveDateToFirstOccurenceOfWeekday(f, day); int days = determineNumberOfDays(f); day = f.getWhen() == When.AFTER ? day.plusDays(days) : day.minusDays(days); HolidayType type = xmlUtil.getType(f.getLocalizedType()); holidays.add(new Holiday(day, f.getDescriptionPropertiesKey(), type)); } }
From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayRelativeToFixedParser.java
License:Apache License
/** * Moves the day to the first/next occurrence of the weekday and direction specified * @param f the specification of the weekday and direction of movement * @param day the day to move/*from w w w. ja v a 2s. c o m*/ * @return the day moved to the weekday and in the direction as specified */ private LocalDate moveDateToFirstOccurenceOfWeekday(FixedWeekdayRelativeToFixed f, LocalDate day) { LocalDate movingDay = day; do { movingDay = f.getWhen() == When.AFTER ? movingDay.plusDays(1) : movingDay.minusDays(1); } while (movingDay.getDayOfWeek() != xmlUtil.getWeekday(f.getWeekday())); return movingDay; }
From source file:com.jjlharrison.jollyday.parser.impl.RelativeToFixedParser.java
License:Apache License
/** {@inheritDoc} */ public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (RelativeToFixed rf : config.getRelativeToFixed()) { if (!isValid(rf, year)) { continue; }/*w w w . ja v a 2 s . c o m*/ LocalDate fixed = calendarUtil.create(year, rf.getDate()); if (rf.getWeekday() != null) { // if weekday is set -> move to weekday int day = xmlUtil.getWeekday(rf.getWeekday()); int direction = (rf.getWhen() == When.BEFORE ? -1 : 1); while (fixed.getDayOfWeek() != day) { fixed = fixed.plusDays(direction); } } else if (rf.getDays() != null) { // if number of days set -> move number of days fixed = fixed.plusDays(rf.getWhen() == When.BEFORE ? -rf.getDays() : rf.getDays()); } HolidayType type = xmlUtil.getType(rf.getLocalizedType()); holidays.add(new Holiday(fixed, rf.getDescriptionPropertiesKey(), type)); } }
From source file:com.jjlharrison.jollyday.parser.impl.RelativeToWeekdayInMonthParser.java
License:Apache License
/** {@inheritDoc} */ @Override/* w w w . j av a 2s. c o m*/ public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (RelativeToWeekdayInMonth rtfw : config.getRelativeToWeekdayInMonth()) { if (!isValid(rtfw, year)) { continue; } LocalDate date = parse(year, rtfw.getFixedWeekday()); int direction = (rtfw.getWhen() == When.BEFORE ? -1 : 1); while (date.getDayOfWeek() != xmlUtil.getWeekday(rtfw.getWeekday())) { date = date.plusDays(direction); } HolidayType type = xmlUtil.getType(rtfw.getLocalizedType()); holidays.add(new Holiday(date, rtfw.getDescriptionPropertiesKey(), type)); } }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year./*from www. ja va2 s .c o m*/ * * @param targetMonth * @param targetDay * @param gregorianYear * @param targetChrono * @return the list of gregorian dates. */ private Set<LocalDate> getDatesFromChronologyWithinGregorianYear(int targetMonth, int targetDay, int gregorianYear, Chronology targetChrono) { Set<LocalDate> holidays = new HashSet<LocalDate>(); LocalDate firstGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.JANUARY, 1, ISOChronology.getInstance()); LocalDate lastGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.DECEMBER, 31, ISOChronology.getInstance()); LocalDate firstTargetDate = new LocalDate(firstGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); LocalDate lastTargetDate = new LocalDate(lastGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); Interval interv = new Interval(firstTargetDate.toDateTimeAtStartOfDay(), lastTargetDate.plusDays(1).toDateTimeAtStartOfDay()); int targetYear = firstTargetDate.getYear(); for (; targetYear <= lastTargetDate.getYear();) { LocalDate d = new LocalDate(targetYear, targetMonth, targetDay, targetChrono); if (interv.contains(d.toDateTimeAtStartOfDay())) { holidays.add(convertToISODate(d)); } targetYear++; } return holidays; }
From source file:com.marintek.tpm.fixture.todo.ToDoItemsFixture.java
License:Apache License
private static LocalDate daysFromToday(final int i) { final LocalDate date = new LocalDate(Clock.getTimeAsDateTime()); return date.plusDays(i); }
From source file:com.metinkale.prayerapp.HicriDate.java
License:Apache License
public HicriDate(LocalDate greg) { // int[] key = {d, m, y}; //int[] ret = mCache.get(key); //if (ret != null) return ret; int hfix = Prefs.getHijriFix(); if (hfix != 0) { greg = greg.plusDays(hfix); }/* ww w . j ava 2 s . c o m*/ int d = greg.getDayOfMonth(); int m = greg.getMonthOfYear(); int y = greg.getYear(); int[] last = null; for (int[] date : mDates) { if (date[GY] < y) { last = date; } else if ((date[GY] == y) && (date[GM] < m)) { last = date; } else if ((date[GY] == y) && (date[GM] == m) && (date[GD] <= d)) { last = date; } else { break; } } if (last == null) { LocalDate date = greg.toDateTimeAtStartOfDay().withChronology(IslamicChronology.getInstance()) .toLocalDate(); Year = date.getYear(); Month = date.getMonthOfYear(); Day = date.getDayOfMonth(); } else { int[] h = { last[HD], last[HM], last[HY] }; h[0] += new LocalDate(y, m, d).getDayOfYear() - new LocalDate(last[GY], last[GM], last[GD]).getDayOfYear(); if ((h[0] >= 30) || (h[0] <= 0)) { LocalDate date = greg.toDateTimeAtStartOfDay().withChronology(IslamicChronology.getInstance()) .toLocalDate(); Year = date.getYear(); Month = date.getMonthOfYear(); Day = date.getDayOfMonth(); } else { Year = h[HY]; Month = h[HM]; Day = h[HD]; } } }
From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java
License:Apache License
private void export(int csvpdf, @NonNull LocalDate from, @NonNull LocalDate to) throws IOException { File outputDir = getActivity().getCacheDir(); if (!outputDir.exists()) outputDir.mkdirs();//w w w. j ava 2s .c om File outputFile = new File(outputDir, mTimes.getName().replace(" ", "_") + (csvpdf == 0 ? ".csv" : ".pdf")); if (outputDir.exists()) outputFile.delete(); FileOutputStream outputStream; outputStream = new FileOutputStream(outputFile); if (csvpdf == 0) { outputStream.write("Date;Fajr;Shuruq;Dhuhr;Asr;Maghrib;Ishaa\n".getBytes()); do { outputStream.write((from.toString("yyyy-MM-dd") + ";").getBytes()); outputStream.write((mTimes.getTime(from, 0) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 1) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 2) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 3) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 4) + ";").getBytes()); outputStream.write((mTimes.getTime(from, 5) + "\n").getBytes()); } while (!(from = from.plusDays(1)).isAfter(to)); outputStream.close(); } else { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { PdfDocument document = new PdfDocument(); PdfDocument.PageInfo pageInfo = null; int pw = 595; int ph = 842; pageInfo = new PdfDocument.PageInfo.Builder(pw, ph, 1).create(); PdfDocument.Page page = document.startPage(pageInfo); Drawable launcher = Drawable.createFromStream(getActivity().getAssets().open("pdf/launcher.png"), null); Drawable qr = Drawable.createFromStream(getActivity().getAssets().open("pdf/qrcode.png"), null); Drawable badge = Drawable.createFromStream( getActivity().getAssets().open("pdf/badge_" + Prefs.getLanguage() + ".png"), null); launcher.setBounds(30, 30, 30 + 65, 30 + 65); qr.setBounds(pw - 30 - 65, 30 + 65 + 5, pw - 30, 30 + 65 + 5 + 65); int w = 100; int h = w * badge.getIntrinsicHeight() / badge.getIntrinsicWidth(); badge.setBounds(pw - 30 - w, 30 + (60 / 2 - h / 2), pw - 30, 30 + (60 / 2 - h / 2) + h); Canvas canvas = page.getCanvas(); Paint paint = new Paint(); paint.setARGB(255, 0, 0, 0); paint.setTextSize(10); paint.setTextAlign(Paint.Align.CENTER); canvas.drawText("com.metinkale.prayer", pw - 30 - w / 2, 30 + (60 / 2 - h / 2) + h + 10, paint); launcher.draw(canvas); qr.draw(canvas); badge.draw(canvas); paint.setARGB(255, 61, 184, 230); canvas.drawRect(30, 30 + 60, pw - 30, 30 + 60 + 5, paint); if (mTimes.getSource().resId != 0) { Drawable source = getResources().getDrawable(mTimes.getSource().resId); h = 65; w = h * source.getIntrinsicWidth() / source.getIntrinsicHeight(); source.setBounds(30, 30 + 65 + 5, 30 + w, 30 + 65 + 5 + h); source.draw(canvas); } paint.setARGB(255, 0, 0, 0); paint.setTextSize(40); paint.setTextAlign(Paint.Align.LEFT); canvas.drawText(getText(R.string.appName).toString(), 30 + 65 + 5, 30 + 50, paint); paint.setTextAlign(Paint.Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(mTimes.getName(), pw / 2.0f, 30 + 65 + 50, paint); paint.setTextSize(12); int y = 30 + 65 + 5 + 65 + 30; int p = 30; int cw = (pw - p - p) / 7; canvas.drawText(getString(R.string.date), 30 + (0.5f * cw), y, paint); canvas.drawText(Vakit.IMSAK.getString(), 30 + (1.5f * cw), y, paint); canvas.drawText(Vakit.GUNES.getString(), 30 + (2.5f * cw), y, paint); canvas.drawText(Vakit.OGLE.getString(), 30 + (3.5f * cw), y, paint); canvas.drawText(Vakit.IKINDI.getString(), 30 + (4.5f * cw), y, paint); canvas.drawText(Vakit.AKSAM.getString(), 30 + (5.5f * cw), y, paint); canvas.drawText(Vakit.YATSI.getString(), 30 + (6.5f * cw), y, paint); paint.setFakeBoldText(false); do { y += 20; canvas.drawText((from.toString("dd.MM.yyyy")), 30 + (0.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 0)), 30 + (1.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 1)), 30 + (2.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 2)), 30 + (3.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 3)), 30 + (4.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 4)), 30 + (5.5f * cw), y, paint); canvas.drawText((mTimes.getTime(from, 5)), 30 + (6.5f * cw), y, paint); } while (!(from = from.plusDays(1)).isAfter(to)); document.finishPage(page); document.writeTo(outputStream); // close the document document.close(); } else { Toast.makeText(getActivity(), R.string.versionNotSupported, Toast.LENGTH_LONG).show(); } } Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType(csvpdf == 0 ? "text/csv" : "application/pdf"); Uri uri = FileProvider.getUriForFile(getActivity(), "com.metinkale.prayer.fileprovider", outputFile); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.export))); }
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--;//from www . j ava2s .co 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; }