List of usage examples for org.joda.time LocalDateTime toDate
@SuppressWarnings("deprecation") public Date toDate()
java.util.Date
. From source file:eu.trentorise.game.managers.QuartzTaskManager.java
License:Apache License
private Date calculateStartDate(Date initialStart, long period) { if (period <= 0) { return initialStart; }/*from w ww.j a v a 2 s . c o m*/ LocalDateTime start = new LocalDateTime(initialStart); while (start.toDateTime().isBeforeNow()) { start = start.plusMillis((int) period); } return start.toDate(); }
From source file:eu.trentorise.game.model.PointConcept.java
License:Apache License
/** * The method returns the PeriodInstance relative to the index. * /*from w ww . jav a2 s. c o m*/ * @param periodIdentifier * identifier of period * @param instanceIndex * index of instance * @return PeriodInstance bound to the index or null if there is not * PeriodInstance at that index */ public PeriodInstance getPeriodInstance(String periodIdentifier, int instanceIndex) { PeriodInstance result = null; PeriodInternal p = periods.get(periodIdentifier); if (p != null) { if (p.period == -1 && instanceIndex > 0) { result = new PeriodInstanceImpl(p.getEnd().map(e -> e.getTime()).orElse(-1L), -1L); } else { LocalDateTime dateCursor = new LocalDateTime(p.start); dateCursor = dateCursor.withPeriodAdded(new org.joda.time.Period(p.period), instanceIndex); result = getPeriodInstance(periodIdentifier, dateCursor.toDate().getTime()); } } return result; }
From source file:io.github.benas.randombeans.randomizers.jodatime.range.JodaTimeLocalDateTimeRangeRandomizer.java
License:Open Source License
/** * Create a new {@link JodaTimeLocalDateTimeRangeRandomizer}. * @param min date//from w w w.j a va 2 s . co m * @param max date * @param seed initial seed */ public JodaTimeLocalDateTimeRangeRandomizer(final LocalDateTime min, final LocalDateTime max, final long seed) { super(min.toDate(), max.toDate(), seed); }
From source file:io.personium.core.model.impl.es.doc.OEntityDocHandler.java
License:Apache License
/** * Create a DocHandler without ID from OEntityWrapper. * @param typeName ES type name//from www. j a v a2s . c om * @param oEntityWrapper OEntityWrapper * @param metadata schema information */ @SuppressWarnings("unchecked") protected void initInstance(String typeName, OEntityWrapper oEntityWrapper, EdmDataServices metadata) { this.type = typeName; //Set the specified uuid as ES ID this.id = oEntityWrapper.getUuid(); //When OEntity Wrapper is used, add Version, hidden field this.hiddenFields = oEntityWrapper.getMetadata(); //Set UnitUser name only when accessing Cell resolveUnitUserName(); String etag = oEntityWrapper.getEtag(); if (etag != null && etag.length() > 1) { this.version = Long.valueOf(etag.substring(0, etag.indexOf("-"))); } //Retrieve schema information EdmEntitySet entitySet = oEntityWrapper.getEntitySet(); EdmEntityType eType = entitySet.getType(); //Get the NavProp defined in the schema List<EdmNavigationProperty> navProps = eType.getDeclaredNavigationProperties().toList(); for (EdmNavigationProperty np : navProps) { //About each NavProp EdmMultiplicity mf = np.getFromRole().getMultiplicity(); EdmMultiplicity mt = np.getToRole().getMultiplicity(); //As Association's Multiplicity, when this side is MANY and the opponent is ONE, //From the value (URL) of NavigationProperty, the item of l is determined and packed if (EdmMultiplicity.ONE.equals(mt) && EdmMultiplicity.MANY.equals(mf)) { //TODO not implemented yet log.debug("many to one"); } } //For all properties that came up, for (OProperty<?> prop : oEntityWrapper.getProperties()) { //Checks whether it is defined in the schema, and switches processing between Dynamic Property and Declared Property String propName = prop.getName(); EdmProperty edmProperty = eType.findProperty(propName); //Branch processing by predefined Property or DynamicProperty if (edmProperty != null) { //Schema-defined properties //TODO It is unknown whether to do here, but check whether data corresponding to the type defined in the schema is coming //You should do it earlier. //Refill the values for each type. Object value = prop.getValue(); if ("__published".equals(propName)) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); this.published = ldt.toDateTime().getMillis(); } else if ("__updated".equals(propName)) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); this.updated = ldt.toDateTime().getMillis(); } else { CollectionKind ck = edmProperty.getCollectionKind(); if (edmProperty.getType().isSimple()) { if (ck.equals(CollectionKind.List)) { //Error if invalid type if (value == null || value instanceof OCollection<?>) { this.staticFields.put(prop.getName(), getSimpleList(edmProperty.getType(), (OCollection<OObject>) value)); } else { throw PersoniumCoreException.OData.REQUEST_FIELD_FORMAT_ERROR .params(prop.getName()); } } else { value = getSimpleValue(prop, edmProperty.getType()); //If Property is Simple type, add it as defined item as it is this.staticFields.put(prop.getName(), value); } } else { String complexTypeName = edmProperty.getType().getFullyQualifiedTypeName(); if (ck.equals(CollectionKind.List)) { //If CollectionKind is List, add by array this.staticFields.put(prop.getName(), getComplexList( (OCollection<OComplexObject>) prop.getValue(), metadata, complexTypeName)); } else { //If Property is Complex type, read and add ComplexType property recursively this.staticFields.put(prop.getName(), getComplexType(prop, metadata, complexTypeName)); } } } } else { //Dynamic property receives String, Integer, Float, Boolean Object propValue = prop.getValue(); if ("Edm.DateTime".equals(prop.getType().getFullyQualifiedTypeName())) { OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop; LocalDateTime ldt = propD.getValue(); if (ldt != null) { propValue = "\\/Date(" + ldt.toDateTime().toDate().getTime() + ")\\/"; } } this.dynamicFields.put(prop.getName(), propValue); } } }
From source file:it.smartcommunitylab.climb.domain.model.gamification.PointConcept.java
License:Apache License
/** * The method returns the PeriodInstance relative to the index. * /*from ww w .j av a 2s . c o m*/ * @param periodIdentifier * identifier of period * @param instanceIndex * index of instance * @return PeriodInstance bound to the index or null if there is not * PeriodInstance at that index */ public PeriodInstance getPeriodInstance(String periodIdentifier, int instanceIndex) { PeriodInstance result = null; PeriodInternal p = periods.get(periodIdentifier); if (p != null) { LocalDateTime dateCursor = new LocalDateTime(p.start); dateCursor = dateCursor.withPeriodAdded(new org.joda.time.Period(p.period), instanceIndex); result = getPeriodInstance(periodIdentifier, dateCursor.toDate().getTime()); } return result; }
From source file:ke.co.tawi.babblesms.server.sendsms.tawismsgw.PostSMS.java
License:Open Source License
/** * // w w w . ja va 2s . co m */ @Override public void run() { HttpEntity responseEntity = null; Map<String, String> params; if (urlValidator.isValid(smsGateway.getUrl())) { // Prepare the parameters to send params = new HashMap<>(); params.put("username", smsGateway.getUsername()); params.put("password", smsGateway.getPasswd()); params.put("source", smsSource.getSource()); params.put("message", message); switch (smsSource.getNetworkuuid()) { case Network.SAFARICOM_KE: params.put("network", "safaricom_ke"); break; case Network.AIRTEL_KE: params.put("network", "safaricom_ke"); // TODO: change to airtel_ke break; } // When setting the destination, numbers beginning with '07' are edited // to begin with '254' phoneMap = new HashMap<>(); StringBuffer phoneBuff = new StringBuffer(); String phoneNum; for (Phone phone : phoneList) { phoneNum = phone.getPhonenumber(); if (StringUtils.startsWith(phoneNum, "07")) { phoneNum = "254" + StringUtils.substring(phoneNum, 1); } phoneMap.put(phoneNum, phone); phoneBuff.append(phoneNum).append(";"); } params.put("destination", StringUtils.removeEnd(phoneBuff.toString(), ";")); // Push to the URL try { URL url = new URL(smsGateway.getUrl()); if (StringUtils.equalsIgnoreCase(url.getProtocol(), "http")) { responseEntity = doPost(smsGateway.getUrl(), params, retry); } // else if(StringUtils.equalsIgnoreCase(url.getProtocol(), "https")) { // doPostSecure(smsGateway.getUrl(), params, retry); // } } catch (MalformedURLException e) { logger.error("MalformedURLException for URL: '" + smsGateway.getUrl() + "'"); logger.error(ExceptionUtils.getStackTrace(e)); } } // end 'if(urlValidator.isValid(urlStr))' // Process the response from the SMS Gateway // Assuming all is ok, it would have the following pattern: // requestStatus=ACCEPTED&messageIds=254726176878:b265ce23;254728932844:367941a36d2e4ef195;254724300863:11fca3c5966d4d if (responseEntity != null) { OutgoingLog outgoingLog; try { String response = EntityUtils.toString(responseEntity); GatewayDAO.getInstance().logResponse(account, response, new Date()); String[] strTokens = StringUtils.split(response, '&'); String tmpStr = "", dateStr = ""; for (String str : strTokens) { if (StringUtils.startsWith(str, "messageIds")) { tmpStr = StringUtils.removeStart(str, "messageIds="); } else if (StringUtils.startsWith(str, "datetime")) { dateStr = StringUtils.removeStart(str, "datetime="); } } strTokens = StringUtils.split(tmpStr, ';'); String phoneStr, uuid; Phone phone; DateTimeFormatter timeFormatter = ISODateTimeFormat.dateTimeNoMillis(); for (String str : strTokens) { phoneStr = StringUtils.split(str, ':')[0]; uuid = StringUtils.split(str, ':')[1]; phone = phoneMap.get(phoneStr); outgoingLog = new OutgoingLog(); outgoingLog.setUuid(uuid); outgoingLog.setOrigin(smsSource.getSource()); outgoingLog.setMessage(message); outgoingLog.setDestination(phone.getPhonenumber()); outgoingLog.setNetworkUuid(phone.getNetworkuuid()); outgoingLog.setMessagestatusuuid(MsgStatus.SENT); outgoingLog.setSender(account.getUuid()); outgoingLog.setPhoneUuid(phone.getUuid()); // Set the date of the OutgoingLog to match the SMS Gateway time LocalDateTime datetime = timeFormatter.parseLocalDateTime(dateStr); outgoingLog.setLogTime(datetime.toDate()); outgoingLogDAO.put(outgoingLog); } } catch (ParseException e) { logger.error("ParseException when reading responseEntity"); logger.error(ExceptionUtils.getStackTrace(e)); } catch (IOException e) { logger.error("IOException when reading responseEntity"); logger.error(ExceptionUtils.getStackTrace(e)); } } }
From source file:ke.co.tawi.babblesms.server.servlet.sms.callback.Callback.java
License:Open Source License
/** * @param request /*w ww.j ava 2 s. c om*/ * @param response * @throws ServletException, IOException */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { DateTimeFormatter timeFormatter = ISODateTimeFormat.dateTimeNoMillis(); String callbackType = request.getParameter("callbackType"); String messageId; LocalDateTime datetime; switch (callbackType) { case "status": // A notification of an SMS Status change messageId = request.getParameter("messageId"); datetime = timeFormatter.parseLocalDateTime(request.getParameter("datetime")); String status = request.getParameter("status"); OutgoingLog log = outgoingLogDAO.get(messageId); log.setLogTime(datetime.toDate()); log.setMessagestatusuuid(dlrstatusMap.get(status)); outgoingLogDAO.put(log); break; case "incomingSms": String network = request.getParameter("network").toLowerCase(); datetime = timeFormatter.parseLocalDateTime(request.getParameter("datetime")); IncomingLog incomingLog = new IncomingLog(); incomingLog.setDestination(request.getParameter("destination")); incomingLog.setUuid(request.getParameter("messageId")); incomingLog.setMessage(request.getParameter("message")); incomingLog.setLogTime(datetime.toDate()); incomingLog.setNetworkUuid(networkMap.get(network)); // The source saved in the address book may begin with "07" // but the one received for Kenya would begin with "254" // We have to reconcile the two String source = request.getParameter("source"); String phoneNum = ""; if (StringUtils.startsWith(source, "254")) { phoneNum = "07" + StringUtils.substring(source, 4); } if (phoneDAO.getPhones(phoneNum).size() > 0) { incomingLog.setOrigin(phoneNum); } else { incomingLog.setOrigin(source); } // Determine the account that it is destined for // This assumes that the same shortcode number cannot // be owned by multiple accounts for (Shortcode shortcode : shortcodeList) { if (shortcode.getCodenumber().equals(incomingLog.getDestination())) { incomingLog.setRecipientUuid(shortcode.getAccountuuid()); break; } } incomingLogDAO.putIncomingLog(incomingLog); break; } }
From source file:nu.yona.app.utils.DateUtility.java
/** * Gets retrive week.//from www.j av a 2 s .c om * * @param week the week * @return the retrive week * @throws ParseException the parse exception */ public static String getRetriveWeek(String week) throws ParseException { String retriveWeek = ""; DateTime time = new DateTime(); int thisWeek = time.getWeekOfWeekyear(); int pastWeek = thisWeek - 1; if (week.endsWith("" + thisWeek)) { retriveWeek = YonaApplication.getAppContext().getString(R.string.this_week); } else if (week.endsWith("" + pastWeek)) { retriveWeek = YonaApplication.getAppContext().getString(R.string.last_week); } else { Calendar calendar = Calendar.getInstance(Locale.getDefault()); LocalDateTime localDateTime = LocalDateTime.parse(week, DateTimeFormat.forPattern("yyyy-'W'ww")); calendar.setTime(new Date(localDateTime.toDate().getTime())); calendar.add(Calendar.DAY_OF_WEEK, -1); Date startDate = calendar.getTime(); calendar.add(Calendar.DAY_OF_MONTH, 6); Date endDate = calendar.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM"); retriveWeek = sdf.format(startDate) + " - " + sdf.format(endDate); } return retriveWeek.toUpperCase(); }
From source file:nu.yona.app.utils.DateUtility.java
/** * Get Current weeks Days List. example: Sun 21, Mon 22, Tue 23 , Wed 24 ,Thu 25, Fri 26 * * @param currentYearWeek the current year week * @return week day/* w ww.ja v a 2 s.c om*/ */ public static Map<String, String> getWeekDay(String currentYearWeek) { LinkedHashMap<String, String> listOfdates = new LinkedHashMap<>(); try { Calendar calendar = Calendar.getInstance(Locale.getDefault()); LocalDateTime localDateTime = LocalDateTime.parse(currentYearWeek, DateTimeFormat.forPattern("yyyy-'W'ww")); calendar.setTime(new Date(localDateTime.toDate().getTime())); calendar.add(Calendar.DAY_OF_WEEK, -1); for (int i = 0; i < M_NO_OF_DAY_PER_WEEK; i++) { listOfdates.put(DAY_FORMAT.format(calendar.getTime()), DAY_NO_FORMAT.format(calendar.getTime())); calendar.add(Calendar.DAY_OF_WEEK, 1); } } catch (Exception e) { AppUtils.reportException(DateUtility.class.getSimpleName(), e, Thread.currentThread()); } return listOfdates; }
From source file:org.apache.fineract.infrastructure.scheduledemail.domain.EmailCampaign.java
License:Apache License
private EmailCampaign(final String campaignName, final Integer campaignType, final Report businessRuleId, final String paramValue, final String emailSubject, final String emailMessage, final LocalDate submittedOnDate, final AppUser submittedBy, final Report stretchyReport, final String stretchyReportParamMap, final ScheduledEmailAttachmentFileFormat emailAttachmentFileFormat, final String recurrence, final LocalDateTime localDateTime) { this.campaignName = campaignName; this.campaignType = EmailCampaignType.fromInt(campaignType).getValue(); this.businessRuleId = businessRuleId; this.paramValue = paramValue; this.status = EmailCampaignStatus.PENDING.getValue(); this.emailSubject = emailSubject; this.emailMessage = emailMessage; this.emailAttachmentFileFormat = emailAttachmentFileFormat.getValue(); this.stretchyReport = stretchyReport; this.stretchyReportParamMap = stretchyReportParamMap; this.submittedOnDate = submittedOnDate.toDate(); this.submittedBy = submittedBy; this.recurrence = recurrence; LocalDateTime recurrenceStartDate = new LocalDateTime(); this.isVisible = true; if (localDateTime != null) { this.recurrenceStartDate = localDateTime.toDate(); } else {/* w w w . ja v a 2 s. co m*/ this.recurrenceStartDate = recurrenceStartDate.toDate(); } }