List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime(Object instant)
From source file:de.avanux.smartapplianceenabler.appliance.Schedule.java
License:Open Source License
/** * Returns the current or next timeframe if the remaining time is greater than maximum running time; otherwise the next timeframe is returned. * @param now the time reference// w w w .j av a 2 s . com * @param schedules the list of timeframes to choose from (current timeframe has to be first) * @param onlyAlreadyStarted consider only timeframe intervals already started * @param onlySufficient if true consider timeframe already started only if time to interval end exceeds min running time * @return the next timeframe becoming valid or null */ public static TimeframeInterval getCurrentOrNextTimeframeInterval(LocalDateTime now, List<Schedule> schedules, boolean onlyAlreadyStarted, boolean onlySufficient) { if (schedules == null || schedules.size() == 0) { return null; } Map<Long, TimeframeInterval> startDelayOfTimeframeInterval = new TreeMap<>(); for (Schedule schedule : schedules) { Timeframe timeframe = schedule.getTimeframe(); timeframe.setSchedule(schedule); List<TimeframeInterval> timeframeIntervals = timeframe.getIntervals(now); for (TimeframeInterval timeframeInterval : timeframeIntervals) { Interval interval = timeframeInterval.getInterval(); if (interval.contains(now.toDateTime())) { // interval already started ... if (onlySufficient) { if (now.plusSeconds(schedule.getMaxRunningTime()).plusSeconds(additionalRunningTime) .isBefore(new LocalDateTime(interval.getEnd()))) { // ... with remaining running time sufficient return timeframeInterval; } } else { return timeframeInterval; } } else if (!onlyAlreadyStarted) { // interval starts in future startDelayOfTimeframeInterval.put(interval.getStartMillis() - now.toDateTime().getMillis(), timeframeInterval); } } } if (startDelayOfTimeframeInterval.size() > 0) { Long startDelay = startDelayOfTimeframeInterval.keySet().iterator().next(); return startDelayOfTimeframeInterval.get(startDelay); } return null; }
From source file:de.avanux.smartapplianceenabler.semp.webservice.SempController.java
License:Open Source License
protected de.avanux.smartapplianceenabler.semp.webservice.Timeframe createSempTimeFrame( ApplianceLogger applianceLogger, String deviceId, Schedule schedule, Interval interval, long minRunningTime, long maxRunningTime, LocalDateTime now) { Long earliestStart = 0l;/*from w w w .jav a2s . co m*/ DateTime start = interval.getStart(); DateTime end = interval.getEnd(); if (start.isAfter(now.toDateTime())) { earliestStart = Double.valueOf(new Interval(now.toDateTime(), start).toDurationMillis() / 1000) .longValue(); } LocalDateTime nowBeforeEnd = new LocalDateTime(now); if (now.toDateTime().isAfter(end)) { nowBeforeEnd = now.minusHours(24); } Long latestEnd = Double.valueOf(new Interval(nowBeforeEnd.toDateTime(), end).toDurationMillis() / 1000) .longValue(); return createSempTimeFrame(applianceLogger, deviceId, earliestStart, latestEnd, minRunningTime, maxRunningTime); }
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
License:MIT License
private void export() { if (refreshing) { Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show(); if (!refreshing) { refresh();//w w w . jav a 2 s .c om } return; } Context ctx = getActivity() != null ? getActivity() : OpacClient.getEmergencyContext(); AccountDataSource adatasource = new AccountDataSource(ctx); AccountData data = adatasource.getCachedAccountData(account); LocalDateTime dt = new LocalDateTime(adatasource.getCachedAccountDataTime(account)); if (data == null) return; StringBuilder string = new StringBuilder(); DateTimeFormatter fmt1 = DateTimeFormat.shortDateTime() .withLocale(getResources().getConfiguration().locale); DateTimeFormatter fmt2 = DateTimeFormat.shortDate().withLocale(getResources().getConfiguration().locale); String dateStr = fmt1.print(dt); string.append(getResources().getString(R.string.accountdata_export_header, account.getLabel(), dateStr)); string.append("\n\n"); string.append(getResources().getString(R.string.lent_head)); string.append("\n\n"); for (LentItem item : data.getLent()) { appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title); appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author); appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format); appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status); appendIfNotEmpty(string, item.getBarcode(), R.string.accountdata_lent_barcode); if (item.getDeadline() != null) { appendIfNotEmpty(string, fmt2.print(item.getDeadline()), R.string.accountdata_lent_deadline); } appendIfNotEmpty(string, item.getHomeBranch(), R.string.accountdata_lent_home_branch); appendIfNotEmpty(string, item.getLendingBranch(), R.string.accountdata_lent_lending_branch); string.append("\n"); } if (data.getLent().size() == 0) { string.append(getResources().getString(R.string.lent_none)); } string.append(getResources().getString(R.string.reservations_head)); string.append("\n\n"); for (ReservedItem item : data.getReservations()) { appendIfNotEmpty(string, item.getTitle(), R.string.accountdata_title); appendIfNotEmpty(string, item.getAuthor(), R.string.accountdata_author); appendIfNotEmpty(string, item.getFormat(), R.string.accountdata_format); appendIfNotEmpty(string, item.getStatus(), R.string.accountdata_status); if (item.getReadyDate() != null) { appendIfNotEmpty(string, fmt2.print(item.getReadyDate()), R.string.accountdata_reserved_ready_date); } if (item.getExpirationDate() != null) { appendIfNotEmpty(string, fmt2.print(item.getExpirationDate()), R.string.accountdata_reserved_expiration_date); } appendIfNotEmpty(string, item.getBranch(), R.string.accountdata_reserved_branch); string.append("\n"); } if (data.getReservations().size() == 0) { string.append(getResources().getString(R.string.reservations_none)); } Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, string.toString()); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share_dialog_select))); }
From source file:de.iteratec.iteraplan.presentation.ajax.DojoUtils.java
License:Open Source License
public static Map<String, Object> convertToMap(Collection<? extends BuildingBlock> data, boolean escapeHtml, HttpServletRequest req) {//www. j a va 2 s . c om List<Map<String, String>> items = new ArrayList<Map<String, String>>(); for (BuildingBlock bb : data) { Map<String, String> item = new HashMap<String, String>(); item.put("id", String.valueOf(bb.getId().intValue())); String name = bb.getIdentityString(); if (escapeHtml) { name = TagUtils.filter(name); } item.put("name", name); LocalDateTime modificationTime = new LocalDateTime(bb.getLastModificationTime()); item.put("lastmodified", ISO_DATE_TIME_FORMATTER.print(modificationTime)); String bbJsonUri = URLBuilder.getEntityURL(bb, req, URLBuilder.EntityRepresentation.JSON); item.put("elementUri", bbJsonUri); items.add(item); } Map<String, Object> result = new HashMap<String, Object>(); result.put("identifier", "id"); result.put("label", "name"); result.put("items", items); return result; }
From source file:de.iteratec.iteraplan.presentation.ajax.DojoUtils.java
License:Open Source License
public static Map<String, Object> convertToMap(InformationSystemRelease entity, HttpServletRequest req) { Map<String, Object> result = new HashMap<String, Object>(); result.put("id", entity.getId()); result.put("name", entity.getNameWithoutVersion()); result.put("version", entity.getVersion()); result.put("description", entity.getDescription()); LocalDateTime modificationTime = new LocalDateTime(entity.getLastModificationTime()); result.put("lastModified", ISO_DATE_TIME_FORMATTER.print(modificationTime)); String status = MessageAccess.getString(entity.getTypeOfStatusAsString(), Locale.ENGLISH); result.put("status", status); if (entity.getRuntimePeriod() != null && entity.getRuntimePeriod().getStart() != null) { LocalDateTime startDate = new LocalDateTime(entity.getRuntimePeriod().getStart()); result.put("startDate", ISO_DATE_FORMATTER.print(startDate)); }/* www . j a va 2s . c o m*/ if (entity.getRuntimePeriod() != null && entity.getRuntimePeriod().getEnd() != null) { LocalDateTime endDate = new LocalDateTime(entity.getRuntimePeriod().getEnd()); result.put("endDate", ISO_DATE_FORMATTER.print(endDate)); } if (entity.getParent() != null) { String parentUri = URLBuilder.getEntityURL(entity.getParent(), req, URLBuilder.EntityRepresentation.JSON); result.put("parentUri", parentUri); } AttributesComponentModel attributesModel = new AttributesComponentModel(ComponentMode.READ, "") { private static final long serialVersionUID = 1L; @Override public boolean showATG(AttributeTypeGroup atg) { return true; } }; attributesModel.initializeFrom(entity); result.put("attributes", attributesModel.getAtgParts()); Set<String> buURIs = Sets.newTreeSet(); for (BusinessMapping bm : entity.getBusinessMappings()) { if (bm.getBusinessUnit() != null) { buURIs.add( URLBuilder.getEntityURL(bm.getBusinessUnit(), req, URLBuilder.EntityRepresentation.JSON)); } } if (!buURIs.isEmpty()) { result.put("connectedBusinessUnits", buURIs); } return result; }
From source file:de.iteratec.iteraplan.presentation.ajax.DojoUtils.java
License:Open Source License
/** * /*from w ww . j a v a 2 s . c o m*/ * @param entity * @param req * @return a Map containing the following attributes with their respective keys: * <ol> * <li>"id": the Id of the BusinessUnit</li> * <li>"name": the name of the BusinessUnit</li> * <li>"description": the description of</li> * <li>"lastModified": a String representation of the last modification date/time, formatted by the {@code ISO_DATE_TIME_FORMATTER} </li> * <li>"parentUri": the URI of the parent Building Block. Key only exists if there is a parent.</li> * <li>"attributes": all attributes of the BusinessUnit</li> * <li>"connectedInformationSystems": all InformationSystemReleases that are connected to the BusinessUnit via at least one BusinessMapping</li> * </ol> */ public static Map<String, Object> convertToMap(BusinessUnit entity, HttpServletRequest req) { Map<String, Object> result = Maps.newHashMap(); result.put("id", entity.getId()); result.put("name", entity.getName()); result.put("description", entity.getDescription()); LocalDateTime modificationTime = new LocalDateTime(entity.getLastModificationTime()); result.put("lastModified", ISO_DATE_TIME_FORMATTER.print(modificationTime)); if (entity.getParent() != null) { String parentUri = URLBuilder.getEntityURL(entity.getParent(), req, URLBuilder.EntityRepresentation.JSON); result.put("parentUri", parentUri); } Set<String> isURIs = Sets.newTreeSet(); for (BusinessMapping bm : entity.getBusinessMappings()) { if (bm.getInformationSystemRelease() != null) { isURIs.add(URLBuilder.getEntityURL(bm.getInformationSystemRelease(), req, URLBuilder.EntityRepresentation.JSON)); } } AttributesComponentModel attributesModel = new AttributesComponentModel(ComponentMode.READ, "") { private static final long serialVersionUID = 1L; @Override public boolean showATG(AttributeTypeGroup atg) { return true; } }; attributesModel.initializeFrom(entity); result.put("attributes", attributesModel.getAtgParts()); if (!isURIs.isEmpty()) { result.put("connectedInformationSystems", isURIs); } return result; }
From source file:de.symeda.sormas.api.utils.DateHelper.java
License:Open Source License
public static Date getStartOfDay(Date date) { return new LocalDateTime(date).withTime(0, 0, 0, 0).toDate(); }
From source file:de.symeda.sormas.api.utils.DateHelper.java
License:Open Source License
public static Date getEndOfDay(Date date) { return new LocalDateTime(date).withTime(23, 59, 59, 999).toDate(); }
From source file:de.symeda.sormas.api.utils.DateHelper.java
License:Open Source License
public static Date getStartOfWeek(Date date) { return new LocalDateTime(getStartOfDay(date)).withDayOfWeek(1).toDate(); }
From source file:de.symeda.sormas.api.utils.DateHelper.java
License:Open Source License
public static Date getEndOfWeek(Date date) { return new LocalDateTime(getEndOfDay(date)).withDayOfWeek(7).toDate(); }