List of usage examples for org.joda.time LocalDate getYear
public int getYear()
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 ww w. java2 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.jseppa.mql4java.util.DateUtil.java
License:Apache License
public static DateTime addDateAndTime(LocalDate date, LocalTime time) { return new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), DATE_TZ); }
From source file:com.mbc.jfin.daycount.impl.calculator.AFBActualActualDaycountCalculator.java
License:Open Source License
public double calculateDaycountFraction(SchedulePeriod period) { int daysBetween = DateUtils.daysBetween(period.getStart(), period.getEnd()); if (daysBetween == 0) return 0; LocalDate newD2 = period.getEnd(); LocalDate temp = period.getEnd(); double sum = 0.0; while (temp.isAfter(period.getStart())) { temp = newD2;/*from w w w . ja va 2s .c om*/ temp = temp.minus(Years.ONE); if (temp.getDayOfMonth() == 28 && temp.getMonthOfYear() == 2 && DateUtils.isLeapYear(temp)) { temp = temp.plus(Days.ONE); } if (temp.isAfter(period.getStart()) || temp.equals(period.getStart())) { sum += 1.0; newD2 = temp; } } double den = 365.0; if (DateUtils.isLeapYear(newD2)) { temp = newD2; temp = new LocalDate(temp.getYear(), 2, 29); if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp))) den += 1.0; } else if (DateUtils.isLeapYear(period.getStart())) { temp = new LocalDate(period.getStart().getYear(), 2, 29); if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp))) den += 1.0; } return sum + DateUtils.daysBetween(period.getStart(), newD2) / den; }
From source file:com.mbc.jfin.daycount.impl.calculator.ISDAActualActualDaycountCalculator.java
License:Open Source License
public List<SchedulePeriod> getPeriods(SchedulePeriod period) { LocalDate hold = period.getStart(); LocalDate end = period.getEnd(); List<SchedulePeriod> periods = new ArrayList<SchedulePeriod>(); while (hold.getYear() < end.getYear()) { LocalDate holdEnd = new LocalDate(hold.getYear() + 1, 1, 1); periods.add(new SchedulePeriod(hold, holdEnd)); hold = holdEnd;// w ww .j ava 2 s . co m } periods.add(new SchedulePeriod(hold, end)); return periods; }
From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java
License:Open Source License
private LocalDate monthEndReference(LocalDate calendar, HolidayCalendar holidayCalendar) { LocalDate d1 = new LocalDate(calendar.getYear(), calendar.getMonthOfYear(), DateUtils.getDaysInMonth(calendar)); return preceding(d1, holidayCalendar); }
From source file:com.mbc.jfin.util.DateUtils.java
License:Open Source License
public static boolean isLeapYear(LocalDate date) { int year = date.getYear(); return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); }
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);//from ww w.ja v a 2 s .com } 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.HicriDate.java
License:Apache License
public static int isHolyday() { LocalDate day = LocalDate.now(); for (int[] date : mDates) { if (date[GD] == day.getDayOfMonth() && (date[GM] == day.getMonthOfYear()) && (date[GY] == day.getYear())) { return date[DAY]; }/*from w ww .j a va 2 s .c o m*/ } return 0; }
From source file:com.metinkale.prayerapp.Utils.java
License:Apache License
@Nullable public static String format(@NonNull LocalDate date) { String format = getDateFormat(false); format = format.replace("DD", az(date.getDayOfMonth(), 2)); try {// w ww. j a v a2 s. c o m format = format.replace("MMM", getGregMonth(date.getMonthOfYear() - 1)); } catch (ArrayIndexOutOfBoundsException ex) { Crashlytics.logException(ex); return ""; } format = format.replace("MM", az(date.getMonthOfYear(), 2)); format = format.replace("YYYY", az(date.getYear(), 4)); format = format.replace("YY", az(date.getYear(), 2)); return toArabicNrs(format); }
From source file:com.metinkale.prayerapp.vakit.fragments.MainFragment.java
License:Apache License
@Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.notification: Fragment frag = getActivity().getSupportFragmentManager().findFragmentByTag("notPrefs"); if (frag == null) { ((Main) getActivity()).setFooterText("", false); getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragContainer, NotificationPrefs.create(mTimes), "notPrefs") .commitAllowingStateLoss(); } else {/* w w w .j av a 2 s . c o m*/ ((Main) getActivity()).setFooterText(getString(R.string.monthly), true); getActivity().getSupportFragmentManager().beginTransaction().remove(frag).commitAllowingStateLoss(); } AppRatingDialog.addToOpenedMenus("notPrefs"); break; case R.id.export: AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.export).setItems(new CharSequence[] { "CSV", "PDF" }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, final int which) { long minDate = 0; long maxDate = Long.MAX_VALUE; if (mTimes instanceof WebTimes) { minDate = ((WebTimes) mTimes).getFirstSyncedDay().toDateTimeAtCurrentTime() .getMillis(); maxDate = ((WebTimes) mTimes).getLastSyncedDay().toDateTimeAtCurrentTime() .getMillis(); } final LocalDate ld = LocalDate.now(); final long finalMaxDate = maxDate; DatePickerDialog dlg = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int y, int m, int d) { final LocalDate from = new LocalDate(y, m + 1, d); DatePickerDialog dlg1 = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int y1, int m1, int d1) { final LocalDate to = new LocalDate(y1, m1 + 1, d1); try { export(which, from, to); } catch (IOException e) { e.printStackTrace(); Crashlytics.logException(e); Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show(); } } }, ld.getYear(), ld.getMonthOfYear() - 1, ld.getDayOfMonth()); DateTime startDate = DateTime.now().withDate(y, m + 1, d); long start = startDate.getMillis(); if (which == 1) dlg1.getDatePicker().setMaxDate( Math.min(finalMaxDate, startDate.plusDays(31).getMillis())); else dlg1.getDatePicker().setMaxDate(finalMaxDate); dlg1.getDatePicker().setMinDate( Math.min(start, dlg1.getDatePicker().getMaxDate()) - 1); dlg1.setTitle(R.string.to); dlg1.show(); } }, ld.getYear(), ld.getMonthOfYear() - 1, ld.getDayOfMonth()); dlg.getDatePicker().setMinDate(minDate); dlg.getDatePicker().setMaxDate(maxDate); dlg.setTitle(R.string.from); dlg.show(); } }); builder.show(); break; case R.id.refresh: if (mTimes instanceof WebTimes) { ((WebTimes) mTimes).syncAsync(); } break; case R.id.share: String txt = getString(R.string.shareTimes, mTimes.getName()) + ":"; LocalDate date = LocalDate.now(); String[] times = { mTimes.getTime(date, 0), mTimes.getTime(date, 1), mTimes.getTime(date, 2), mTimes.getTime(date, 3), mTimes.getTime(date, 4), mTimes.getTime(date, 5) }; for (int i = 0; i < times.length; i++) { txt += "\n " + Vakit.getByIndex(i).getString() + ": " + times[i]; } Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name)); sharingIntent.putExtra(Intent.EXTRA_TEXT, txt); startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share))); } return super.onOptionsItemSelected(item); }