List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(int year, int monthOfYear, int dayOfMonth)
ISOChronology
. From source file:com.kripesh.springhibernate4.MyApp.java
public static void main(String args[]) { AbstractApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); EmployeeService service = (EmployeeService) context.getBean("employeeService"); /*/*w w w . java 2s .c o m*/ * Create Employee1 */ Employee employee1 = new Employee(); employee1.setName("Kripesh Bista"); employee1.setJoiningDate(new LocalDate(2011, 11, 11)); employee1.setSalary(new BigDecimal(12000)); employee1.setSsn("ssn00000001"); /* * Create Employee2 */ Employee employee2 = new Employee(); employee2.setName("Suman Heuju"); employee2.setJoiningDate(new LocalDate(2012, 12, 12)); employee2.setSalary(new BigDecimal(25000)); employee2.setSsn("ssn00000002"); /* * Persist both Employees */ service.saveEmployee(employee1); service.saveEmployee(employee2); /* * Get all employees list from database */ List<Employee> employees = service.findAllEmployees(); for (Employee emp : employees) { System.out.println(emp); } /* * delete an employee */ service.deleteEmployeeBySsn("ssn00000002"); /* * update an employee */ Employee employee = service.findBySsn("ssn00000001"); employee.setSalary(new BigDecimal(40000)); service.updateEmployee(employee); /* * Get all employees list from database */ List<Employee> employeeList = service.findAllEmployees(); for (Employee emp : employeeList) { System.out.println(emp); } context.close(); }
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;/*w w w. ja v a 2 s. com*/ 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;/*from w w w .ja v a 2 s. c om*/ } 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.metinkale.prayerapp.calendar.Adapter.java
License:Apache License
@NonNull @Override/* w ww.j a v a 2 s . co m*/ public View getView(int pos, @Nullable View convertView, @NonNull ViewGroup parent) { ViewHolder vh; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.calendar_item, parent, false); vh = new ViewHolder(); vh.name = (TextView) convertView.findViewById(R.id.name); vh.date = (TextView) convertView.findViewById(R.id.date); vh.hicri = (TextView) convertView.findViewById(R.id.hicri); vh.next = (ImageView) convertView.findViewById(R.id.next); vh.next.setVisibility(hasInfo ? View.VISIBLE : View.GONE); convertView.setTag(R.id.viewholder, vh); } else { vh = (ViewHolder) convertView.getTag(R.id.viewholder); } int[] h = days.get(pos); vh.hicri.setText(Utils.format(new HicriDate(h[HicriDate.HY], h[HicriDate.HM], h[HicriDate.HD]))); vh.date.setText(Utils.format(new LocalDate(h[HicriDate.GY], h[HicriDate.GM], h[HicriDate.GD]))); vh.name.setText(Utils.getHolyday(h[HicriDate.DAY] - 1)); convertView.setTag(h[HicriDate.DAY]); return convertView; }
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);/* w w w . j a v a 2 s . co 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
@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 {/*from ww w. ja va 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); }
From source file:com.metinkale.prayerapp.vakit.times.CSVTimes.java
License:Apache License
protected boolean parseResult(@NonNull String result) { int i = 0;//from w ww . j a v a 2 s. com String[] lines = result.replace("\"", "").split("\n"); FOR: for (String line : lines) { try { String sep1 = null, sep2 = null; if (line.contains(";")) sep1 = ";"; else if (line.contains(",")) sep1 = ","; else if (line.contains("\t")) sep1 = "\t"; else if (line.contains(" ")) sep1 = " "; if (sep1 == null) continue; if (!sep1.equals(" ")) line = line.replace(" ", ""); String parts[] = line.split(sep1); if (parts[0].contains("-")) sep2 = "-"; else if (parts[0].contains(".")) sep2 = "."; else if (parts[0].contains("_")) sep2 = "."; if (sep2 == null) continue; String date[] = parts[i].split(sep2); int year = Integer.parseInt(date[2]); int month = Integer.parseInt(date[1]); int day = Integer.parseInt(date[0]); for (int l = 1; l < 7; l++) { if (parts[l].length() != 5 || parts[l].charAt(2) != ':' || !Character.isDigit(parts[l].charAt(0)) || !Character.isDigit(parts[l].charAt(1)) || !Character.isDigit(parts[l].charAt(3)) || !Character.isDigit(parts[l].charAt(4))) continue FOR; } setTimes(new LocalDate(Math.max(year, day), month, Math.min(year, day)), new String[] { parts[1], parts[2], parts[3], parts[4], parts[5], parts[6] }); i++; } catch (Exception ignore) { } } if (firstSync && i == 0) { Toast.makeText(App.get(), "Invalid CSV", Toast.LENGTH_LONG).show(); delete(); } firstSync = false; return i > 0; }
From source file:com.metinkale.prayerapp.vakit.times.DiyanetTimes.java
License:Apache License
protected boolean parseResult(String result) { result = result.substring(result.indexOf("<a:NamazVakti>") + 14); result = result.substring(0, result.indexOf("</AylikNamazVaktiResult>")); String[] days = result.split("</a:NamazVakti><a:NamazVakti>"); int i = 0;/*from w ww .j av a2s.c o m*/ for (String day : days) { String[] parts = day.split("><a:"); String[] times = new String[6]; String date = null; for (String part : parts) { if (!part.contains(">")) continue; String name = part.substring(0, part.indexOf(">")); if (name.contains(":")) name = name.substring(name.indexOf(":") + 1); String content = part.substring(part.indexOf(">") + 1); content = content.substring(0, content.indexOf("<")); if ("Imsak".equals(name)) { times[0] = content; } else if ("Gunes".equals(name)) { times[1] = content; } else if ("Ogle".equals(name)) { times[2] = content; } else if ("Ikindi".equals(name)) { times[3] = content; } else if ("Aksam".equals(name)) { times[4] = content; } else if ("Yatsi".equals(name)) { times[5] = content; } else if ("MiladiTarihKisa".equals(name)) { date = content; } } String[] d = date.split("\\."); setTimes(new LocalDate(Integer.parseInt(d[2]), Integer.parseInt(d[1]), Integer.parseInt(d[0])), times); i++; } return i > 25; }
From source file:com.metinkale.prayerapp.vakit.times.FaziletTimes.java
License:Apache License
protected boolean parseResult(@NonNull String result) { List<String> ay = new ArrayList<>(); ay.add("Ocak"); ay.add("ubat"); ay.add("Mart"); ay.add("Nisan"); ay.add("Mays"); ay.add("Haziran"); ay.add("Temmuz"); ay.add("Austos"); ay.add("Eyll"); ay.add("Ekim"); ay.add("Kasm"); ay.add("Aralk"); int c = 0;/* www. j a va 2s. c o m*/ String lines[] = result.split("\n"); for (int i = 0; i < lines.length; i++) { String line = lines[i]; if (line.contains("<tr class=\"acik\">") || line.contains("<tr class=\"koyu\">")) { String date = extractLine(lines[++i]); String[] dd = date.split(" "); int d = Integer.parseInt(dd[0]); int m = ay.indexOf(dd[1]) + 1; int y = Integer.parseInt(dd[2]); String[] times = new String[6]; times[0] = extractLine(lines[++i]);//2 i++;//3 times[1] = extractLine(lines[++i]);//4 i++;//5 times[2] = extractLine(lines[++i]);//6 times[3] = extractLine(lines[++i]);//7 i++;//8 times[4] = extractLine(lines[++i]);//9 times[5] = extractLine(lines[++i]);//10 setTimes(new LocalDate(y, m, d), times); c++; } } return c > 25; }