List of usage examples for org.joda.time LocalDate toString
public String toString(String pattern)
From source file:es.usc.citius.servando.calendula.scheduling.DailyAgenda.java
License:Open Source License
public void createScheduleForDate(LocalDate date) { Log.d(TAG, "Adding DailyScheduleItem to daily schedule for date: " + date.toString("dd/MM")); int items = 0; // create a list with all day doses for schedules bound to routines for (Routine r : Routine.findAll()) { for (ScheduleItem s : r.scheduleItems()) { if (s.schedule().enabledForDate(date)) { // create a dailyScheduleItem and save it DailyScheduleItem dsi = new DailyScheduleItem(s); dsi.setPatient(s.schedule().patient()); dsi.setDate(date);/*from w w w.j a v a 2 s .com*/ dsi.save(); items++; } } } // Do the same for hourly schedules for (Schedule s : DB.schedules().findHourly()) { // create an schedule item for each repetition today for (DateTime time : s.hourlyItemsAt(date.toDateTimeAtStartOfDay())) { LocalTime timeToday = time.toLocalTime(); DailyScheduleItem dsi = new DailyScheduleItem(s, timeToday); dsi.setPatient(s.patient()); dsi.setDate(date); dsi.save(); } } Log.d(TAG, items + " items added to daily schedule"); }
From source file:es.usc.citius.servando.calendula.util.PickupUtils.java
License:Open Source License
public Pair<LocalDate, List<PickupInfo>> getBestDay() { if (this.bestDay != null) { return this.bestDay; }/*from www. j av a2 s .c o m*/ HashMap<LocalDate, List<PickupInfo>> bestDays = new HashMap<>(); if (pickups.size() > 0) { LocalDate today = LocalDate.now(); LocalDate first = LocalDate.now(); LocalDate now = LocalDate.now().minusDays(MAX_DAYS); if (now.getDayOfWeek() == DateTimeConstants.SUNDAY) { now = now.plusDays(1); } // get the date of the first med we can take from 10 days ago for (PickupInfo p : pickups) { if (p.from().isAfter(now) && !p.taken()) { first = p.from(); break; } } for (int i = 0; i < 10; i++) { LocalDate d = first.plusDays(i); if (!d.isAfter(today) && d.getDayOfWeek() != DateTimeConstants.SUNDAY) { // only take care of days after today that are not sundays continue; } // compute the number of meds we cant take for each day for (PickupInfo p : pickups) { // get the pickup take secure interval DateTime iStart = p.from().toDateTimeAtStartOfDay(); DateTime iEnd = p.from().plusDays(MAX_DAYS - 1).toDateTimeAtStartOfDay(); Interval interval = new Interval(iStart, iEnd); // add the pickup to the daily list if we can take it if (!p.taken() && interval.contains(d.toDateTimeAtStartOfDay())) { if (!bestDays.containsKey(d)) { bestDays.put(d, new ArrayList<PickupInfo>()); } bestDays.get(d).add(p); } } } // select the day with the highest number of meds int bestDayCount = 0; LocalDate bestOption = null; Set<LocalDate> localDates = bestDays.keySet(); ArrayList<LocalDate> sorted = new ArrayList<>(localDates); Collections.sort(sorted); for (LocalDate day : sorted) { List<PickupInfo> pks = bestDays.get(day); Log.d("PickupUtils", day.toString("dd/MM/YYYY") + ": " + pks.size()); if (pks.size() >= bestDayCount) { bestDayCount = pks.size(); bestOption = day; if (bestOption.getDayOfWeek() == DateTimeConstants.SUNDAY) { bestOption = bestOption.minusDays(1); } } } if (bestOption != null) { this.bestDay = new Pair<>(bestOption, bestDays.get(bestOption)); return this.bestDay; } } return null; }
From source file:eu.europa.ec.grow.espd.xml.LocalDateAdapter.java
License:EUPL
public static String marshal(LocalDate v) { if (v == null) { return null; }/* w w w .j a va 2s. c o m*/ return v.toString(DATE_FORMAT); }
From source file:eu.ggnet.dwoss.uniqueunit.op.UniqueUnitReporterOperation.java
License:Open Source License
@Override public FileJacket quality(Date start, Date end, TradeName contractor) { SubMonitor m = monitorFactory.newSubMonitor("Gertequalittsreport", 10); m.start();// w w w .j a va 2 s . c o m m.message("Loading reciepted Units"); LocalDate current = new LocalDate(start.getTime()); LocalDate endDate = new LocalDate(end.getTime()); List<UniqueUnit> units = new UniqueUnitEao(em).findBetweenInputDatesAndContractor(start, end, contractor); m.worked(5, "Sorting Data"); Set<String> months = new HashSet<>(); //prepare set of months while (current.isBefore(endDate)) { months.add(current.toString(MONTH_PATTERN)); current = current.plusDays(1); } //prepare Map sorted by months that contains a map sorted by condition SortedMap<String, UnitQualityContainer> unitMap = new TreeMap<>(); for (String month : months) { unitMap.put(month, new UnitQualityContainer()); } m.worked(1); //count monthly receipted units sorted by condition for (UniqueUnit uniqueUnit : units) { current = new LocalDate(uniqueUnit.getInputDate().getTime()); switch (uniqueUnit.getCondition()) { case AS_NEW: unitMap.get(current.toString(MONTH_PATTERN)).incrementAsNew(); break; case ALMOST_NEW: unitMap.get(current.toString(MONTH_PATTERN)).incrementAlmostNew(); break; case USED: unitMap.get(current.toString(MONTH_PATTERN)).incrementUsed(); break; } } m.worked(2, "Creating Document"); List<Object[]> rows = new ArrayList<>(); for (String month : unitMap.keySet()) { rows.add(new Object[] { month, unitMap.get(month).getAsNew(), unitMap.get(month).getAlmostNew(), unitMap.get(month).getUsed() }); m.worked(5); } STable table = new STable(); table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK))); table.setHeadlineFormat( new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT)); table.add(new STableColumn("Monat", 15)).add(new STableColumn("neuwertig", 15)) .add(new STableColumn("nahezu neuwerig", 15)).add(new STableColumn("gebraucht", 15)); table.setModel(new STableModelList(rows)); CCalcDocument cdoc = new TempCalcDocument("Qualitaet_"); cdoc.add(new CSheet("Sheet1", table)); File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc); m.finish(); return new FileJacket("Aufnahme_nach_Qualitt_" + contractor + "_" + DateFormats.ISO.format(start) + "_" + DateFormats.ISO.format(end), ".xls", file); }
From source file:io.kahu.hawaii.util.json.JsonHelper.java
License:Apache License
public static void add(JSONObject json, String key, LocalDate value, String format) throws JSONException { if (value == null) { json.put(key, ""); } else {//w w w . j ava 2s .c o m add(json, key, value.toString(format), false); } }
From source file:liteshiftwindow.LSForm.java
public String getTabName() { // When using the JCalendar widget, its "selected day" output is in MMM dd, yyyy format. // This funciton takes that information, finds the first day of the week that selected day is in // and names the tab after it. // e.g. if the user selected Feb 2, a Monday. The following steps are executed: // 1. Find that the first day of that week is Sunday, Feb 1. // 2. Find that the last day of that week is Saturday, Feb 7. // 3. Return the following string: "02/01 - 02/07" // This returned information is later used in the program to "name" the schedule. org.joda.time.format.DateTimeFormatter MdYFormat = DateTimeFormat.forPattern("MMM dd, yyyy"); Date selectedDay = jDateChooser1.getDate(); if (selectedDay == null) return null; String strDay = DateFormat.getDateInstance().format(selectedDay); LocalDate jodaDate = LocalDate.parse(strDay, MdYFormat); LocalDate Sunday = getSunday(jodaDate); org.joda.time.format.DateTimeFormatter MdFormat = DateTimeFormat.forPattern("MM/dd"); String tabName = Sunday.toString(MdFormat) + " - " + Sunday.plusDays(6).toString(MdFormat); return tabName; }
From source file:managers.Config.java
/** * Changes date format from dd-mm-yyyy to mysql's yyyy-mm-dd in a result set for specified fields * THIS METHOD FAILS BECAUSE WE THE INPUT RESULTSET SELECTS DATA FROM MANY TABLES. HENCE CONCUR UPDATABLE FAILS. IT IS APPLICABLE TO ONLY 1 TABLE. * @param rs The resultSet whose date format are to be changed * @param fields String Array that stores the name of date fields * @return ResultSet rs with modified date formats * @throws java.sql.SQLException//from w ww . j ava 2 s. c o m */ public static TableModel changeResultSetDateFormat(ResultSet rs, TableModel model, Integer[] fields) throws SQLException { int i = 0; rs.beforeFirst(); while (rs.next()) { for (Integer field : fields) { try { if (model.getValueAt(i, field) != null || model.getValueAt(i, field).toString().compareTo("") != 0 || model.getValueAt(i, field).toString().length() > 3) // so that null date values are not affected by this method { System.out.println( "value at row " + i + " coloumn " + field + " : " + model.getValueAt(i, field)); LocalDate date = new LocalDate(model.getValueAt(i, field)); model.setValueAt(date.toString("dd-MM-yyyy"), i, field); } else { continue; } } catch (Exception e) { } } i++; } return model; }
From source file:module.regulation.dispatch.domain.RegulationDispatchQueue.java
License:Open Source License
public static Set<RegulationDispatchWorkflowMetaProcess> findEntriesBy(String sSearch) { Set<RegulationDispatchWorkflowMetaProcess> result = new HashSet<RegulationDispatchWorkflowMetaProcess>(); Set<RegulationDispatchWorkflowMetaProcess> activeEntries = RegulationDispatchSystem.getInstance() .getActiveProcessesSet();//w w w .j av a 2 s. c o m for (RegulationDispatchWorkflowMetaProcess dispatch : activeEntries) { String reference = dispatch.getReference(); LocalDate emissionDate = dispatch.getEmissionDate(); String dispatchDescription = dispatch.getInstanceDescription(); Person emissor = dispatch.getRequestorUser().getPerson(); String regulationReference = dispatch.getRegulationReference() != null ? dispatch.getRegulationReference() : ""; if (reference.toLowerCase().indexOf(sSearch.toLowerCase()) > -1) { result.add(dispatch); } else if (emissionDate.toString("dd/MM/yyyy").indexOf(sSearch.toLowerCase()) > -1) { result.add(dispatch); } else if (dispatchDescription.toLowerCase().indexOf(sSearch.toLowerCase()) > -1) { result.add(dispatch); } else if (emissor.getName().toLowerCase().indexOf(sSearch.toLowerCase()) > -1) { result.add(dispatch); } else if (regulationReference.toLowerCase().indexOf(sSearch.toLowerCase()) > -1) { result.add(dispatch); } } return result; }
From source file:module.regulation.dispatch.presentationTier.RegulationDispatchAction.java
License:Open Source License
private String serializeAjaxFilterResponse(String sEcho, Integer iTotalRecords, Integer iTotalDisplayRecords, java.util.List<RegulationDispatchWorkflowMetaProcess> limitedEntries, HttpServletRequest request) { StringBuilder stringBuilder = new StringBuilder("{"); stringBuilder.append("\"sEcho\": ").append(sEcho).append(", \n"); stringBuilder.append("\"iTotalRecords\": ").append(iTotalRecords).append(", \n"); stringBuilder.append("\"iTotalDisplayRecords\": ").append(iTotalDisplayRecords).append(", \n"); stringBuilder.append("\"aaData\": ").append("[ \n"); for (RegulationDispatchWorkflowMetaProcess entry : limitedEntries) { RegulationDispatchWorkflowMetaProcess meta = ((RegulationDispatchWorkflowMetaProcess) entry); boolean ableToAccessQueue = RegulationDispatchSystem .isRegulationDispatchManager(Authenticate.getUser()); String reference = entry.getReference(); LocalDate emissionDate = entry.getEmissionDate(); String dispatchDescription = entry.getInstanceDescription(); Person emissor = entry.getRequestorUser().getPerson(); String regulationReference = entry.getRegulationReference() != null ? entry.getRegulationReference() : ""; Boolean hasMainDocument = entry.getMainDocument() != null; stringBuilder.append("[ \"").append(reference).append("\", "); stringBuilder.append("\"").append(escapeQuotes(emissionDate.toString("dd/MM/yyyy"))).append("\", "); stringBuilder.append("\"").append(escapeQuotes(dispatchDescription)).append("\", "); stringBuilder.append("\"").append(escapeQuotes(emissor.getName())).append("\", "); stringBuilder.append("\"").append(escapeQuotes(regulationReference)).append("\", "); stringBuilder.append("\"") .append(ableToAccessQueue ? generateLinkForView(request, entry) : "permission_not_granted") .append(","); stringBuilder// www . j a v a 2s . co m .append(ableToAccessQueue ? generateLinkForEdition(request, entry) : "permission_not_granted") .append(","); stringBuilder.append(ableToAccessQueue && entry.isActive() ? generateLinkForRemoval(request, entry) : "permission_not_granted").append(","); stringBuilder.append(ableToAccessQueue && hasMainDocument ? generateLinkForMainDocument(request, entry) : "permission_not_granted").append("\","); stringBuilder.append("\"").append(entry.isActive()).append("\" ], "); } stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length()); stringBuilder.append(" ]\n }"); return stringBuilder.toString(); }
From source file:net.jrkatz.minero.BudgetPeriodView.java
License:Open Source License
public void updateView() { final TextView remainingAmt = (TextView) findViewById(R.id.remaining_amt); final Resources r = getResources(); final String remainingStr = r.getString(R.string.currency_fmt, r.getString(R.string.currency_symbol), Long.toString(mBudgetPeriod.getRemaining())); remainingAmt.setText(remainingStr);/* w w w . j av a2 s . c o m*/ remainingAmt.setTextColor(mBudgetPeriod.getRemaining() < 0 ? getResources().getColor(R.color.budget_bold_negative, getContext().getTheme()) : getResources().getColor(R.color.budget_bold_positive, getContext().getTheme())); final TextView periodView = (TextView) findViewById(R.id.period); final LocalDate end = mBudgetPeriod.getPeriod().getEnd(); final String untilDateString = String.format(getResources().getString(R.string.until_date_format), end.toString(getResources().getString(R.string.ymd_format))); periodView.setText(untilDateString); final TextView totalView = (TextView) findViewById(R.id.total_savings); final long totalSavings = mBudget.getRunningTotal() + mBudgetPeriod.getRemaining(); final String totalStr = r.getString(R.string.currency_fmt, "$", Long.toString(totalSavings)); totalView.setText(totalStr); totalView.setTextColor( totalSavings < 0 ? getResources().getColor(R.color.budget_negative, getContext().getTheme()) : getResources().getColor(R.color.budget_positive, getContext().getTheme())); }