List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.prayer.vakit.times.Times.java
License:Apache License
Collection<Alarm> getAlarms() { Collection<Alarm> alarms = new ArrayList<>(); LocalDate cal = LocalDate.now(); for (int ii = 0; ii <= 1/* next day */; ii++) { for (Vakit v : Vakit.values()) { if (isNotificationActive(v)) { if (v != Vakit.SABAH) { int vakit = v.ordinal(); if (vakit != 0) { vakit--;/*from w w w . j av a2 s . c o m*/ } long mills = getTimeCal(cal, vakit).toDateTime().getMillis(); if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.early = false; a.cuma = false; a.time = mills; a.vakit = v; a.dayOffset = ii; alarms.add(a); } } else { long mills; if (isAfterImsak()) { mills = getTimeCal(cal, 0).toDateTime().getMillis() + getSabahTime() * 60 * 1000; } else { mills = getTimeCal(cal, 1).toDateTime().getMillis() - getSabahTime() * 60 * 1000; } if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.cuma = false; a.early = false; a.time = mills; a.vakit = v; a.dayOffset = ii; alarms.add(a); } } } if (isEarlyNotificationActive(v)) { if (v != Vakit.SABAH) { int vakit = v.ordinal(); if (vakit != 0) { vakit--; } int early = getEarlyTime(v); long mills = getTimeCal(cal, vakit).toDateTime().getMillis() - early * 60 * 1000; if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.early = true; a.cuma = false; a.time = mills; a.vakit = v; a.dayOffset = ii; alarms.add(a); } } } } cal = cal.plusDays(1); } if (isCumaActive()) { int early = getCumaTime(); DateTime c = DateTime.now().withDayOfWeek(DateTimeConstants.FRIDAY); if ((c.getMillis() + 1000) < System.currentTimeMillis()) { c = c.plusWeeks(1); } long mills = getTimeCal(c.toLocalDate(), 2).toDateTime().getMillis(); mills -= early * 60 * 1000; if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.cuma = true; a.early = false; a.time = mills; a.vakit = Vakit.OGLE; a.dayOffset = 0; alarms.add(a); } } return alarms; }
From source file:com.precioustech.fxtrading.oanda.restapi.marketdata.historic.OandaHistoricMarketDataProvider.java
License:Apache License
@Override public List<CandleStick<String>> getCandleSticks(TradeableInstrument<String> instrument, CandleStickGranularity granularity, DateTime from, DateTime to) { try {// w ww.j ava 2 s. co m return getCandleSticks(instrument, getFromToUrl(instrument, granularity, from, to), granularity); } catch (OandaLimitExceededException leex) { try { List<CandleStick<String>> allCandles = Lists.newArrayList(); allCandles = getCandleSticks(instrument, getFromCountUrl(instrument, granularity, from, MAX_CANDLES_COUNT), granularity); DateTime lastDate = allCandles.get(allCandles.size() - 1).getEventDate(); long batchesReqd = (to.getMillis() - lastDate.getMillis()) / (lastDate.getMillis() - from.getMillis()) + 1; DateTime start = lastDate.plusSeconds((int) granularity.getGranularityInSeconds()); for (long batch = 1; batch <= batchesReqd; batch++) { List<CandleStick<String>> batchCandles = null; if (batch == batchesReqd && start.isBefore(to)) { batchCandles = getCandleSticks(instrument, getFromToUrl(instrument, granularity, start, to), granularity); } else { batchCandles = getCandleSticks(instrument, getFromCountUrl(instrument, granularity, start, MAX_CANDLES_COUNT), granularity); } if (batchCandles == null || batchCandles.isEmpty()) { break; } start = batchCandles.get(batchCandles.size() - 1).getEventDate() .plusSeconds((int) granularity.getGranularityInSeconds()); allCandles.addAll(batchCandles); } return allCandles; } catch (OandaLimitExceededException e) { LOG.error("limit exceedeed error encountered again", e); } return Collections.emptyList(); } }
From source file:com.precioustech.fxtrading.utils.TradingUtils.java
License:Apache License
/** * /*from www . ja v a 2 s. c o m*/ * @param dateTime * @return a UNIX representation of the dateTime object which actually is in * fact a nanosecond representation obtained by multiplying the * millisecond representation with 1000; */ public static long toUnixTime(DateTime dateTime) { return dateTime.getMillis() * THOUSAND; }
From source file:com.predic8.membrane.core.interceptor.apimanagement.rateLimiter.AMRateLimiter.java
License:Apache License
public void setResponseToServiceUnavailable(Exchange exc, PolicyRateLimit prl) throws UnsupportedEncodingException { Header hd = new Header(); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'").withZoneUTC() .withLocale(Locale.US); hd.add("Date", dateFormatter.print(DateTime.now())); hd.add("X-LimitDuration", PeriodFormat.getDefault().print(prl.getInterval().toPeriod())); hd.add("X-LimitRequests", Integer.toString(prl.getRequests())); String ip = exc.getRemoteAddrIp(); DateTime availableAgainDateTime = prl.getNextCleanup(); hd.add("X-LimitReset", Long.toString(availableAgainDateTime.getMillis())); /*StringBuilder bodyString = new StringBuilder(); DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("HH:mm:ss aa"); bodyString.append(ip).append(" exceeded the rate limit of ").append(prl.getRequests()) .append(" requests per ")/*from w w w . ja va2s . c o m*/ .append(PeriodFormat.getDefault().print(prl.getInterval().toPeriod())) .append(". The next request can be made at ").append(dtFormatter.print(availableAgainDateTime));*/ DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("HH:mm:ss aa"); ByteArrayOutputStream os = new ByteArrayOutputStream(); JsonGenerator jgen = null; try { jgen = new JsonFactory().createGenerator(os); jgen.writeStartObject(); jgen.writeObjectField("Statuscode", 429); jgen.writeObjectField("Message", "The rate limit of " + prl.getRequests() + " requests in " + prl.getInterval().getStandardSeconds() + " seconds is exceeded. The next requests can be made at " + dtFormatter.print(availableAgainDateTime)); jgen.writeEndObject(); jgen.close(); } catch (IOException ignored) { } Response resp = Response.ResponseBuilder.newInstance().status(429, "Too Many Requests.").header(hd) .contentType("application/json").body(os.toByteArray()).build(); exc.setResponse(resp); }
From source file:com.predic8.membrane.core.interceptor.ratelimit.RateLimitInterceptor.java
License:Apache License
public void setResponseToServiceUnavailable(Exchange exc) throws UnsupportedEncodingException { Header hd = new Header(); DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'").withZoneUTC() .withLocale(Locale.US); hd.add("Date", dateFormatter.print(DateTime.now())); hd.add("X-LimitDuration", PeriodFormat.getDefault().print(rateLimitStrategy.requestLimitDuration.toPeriod())); hd.add("X-LimitRequests", Integer.toString(rateLimitStrategy.requestLimit)); String ip = exc.getRemoteAddrIp(); DateTime availableAgainDateTime = rateLimitStrategy.getServiceAvailableAgainTime(ip); hd.add("X-LimitReset", Long.toString(availableAgainDateTime.getMillis())); StringBuilder bodyString = new StringBuilder(); DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("HH:mm:ss aa"); bodyString.append(ip).append(" exceeded the rate limit of ").append(rateLimitStrategy.requestLimit) .append(" requests per ") .append(PeriodFormat.getDefault().print(rateLimitStrategy.requestLimitDuration.toPeriod())) .append(". The next request can be made at ").append(dtFormatter.print(availableAgainDateTime)); Response resp = ResponseBuilder.newInstance().status(429, "Too Many Requests.") .contentType(MimeType.TEXT_PLAIN_UTF8).header(hd).body(bodyString.toString()).build(); exc.setResponse(resp);// w w w. j a va 2 s . c o m }
From source file:com.qcadoo.mes.assignmentToShift.print.xls.AssignmentToShiftXlsService.java
License:Open Source License
private void createHeaderForAssignmentToShift(final HSSFSheet sheet, final Locale locale, final Entity entity) { List<DateTime> days = assignmentToShiftXlsHelper.getDaysBetweenGivenDates(entity); if (days != null) { HSSFRow headerAssignmentToShift = sheet.createRow(3); String occupationType = translationService.translate(COLUMN_HEADER_OCCUPATIONTYPE, locale); HSSFCell cell0 = headerAssignmentToShift.createCell(0); cell0.setCellValue(occupationType); int columnNumber = 1; for (DateTime day : days) { HSSFCell cellDay = headerAssignmentToShift.createCell(columnNumber); cellDay.setCellValue(translationService.translate(COLUMN_HEADER_DAY, locale, DateFormat.getDateInstance().format(new Date(day.getMillis())))); columnNumber += 3;/*w ww .j a v a 2 s . c o m*/ } headerAssignmentToShift.setHeightInPoints(14); assignmentToShiftXlsStyleHelper.addMarginsAndStylesForAssignmentToShift(sheet, 3, assignmentToShiftXlsHelper.getNumberOfDaysBetweenGivenDates(entity)); } }
From source file:com.querydsl.sql.types.LocalDateTimeType.java
License:Apache License
@Override public void setValue(PreparedStatement st, int index, LocalDateTime value) throws SQLException { DateTime dt = value.toDateTime(DateTimeZone.UTC); st.setTimestamp(index, new Timestamp(dt.getMillis()), utc()); }
From source file:com.quinsoft.zeidon.dbhandler.StandardJdbcTranslator.java
License:Open Source License
@Override public String bindAttributeValue(PreparedStatement ps, Object value, int idx) { try {//from w w w . ja v a 2 s .co m if (value instanceof DateTime) { DateTime d = (DateTime) value; ps.setObject(idx, new Date(d.getMillis())); } else if (value instanceof GeneratedKey) { GeneratedKey k = (GeneratedKey) value; ps.setObject(idx, k.getNativeValue()); } else { ps.setObject(idx, value); } if (value == null) return "<null>"; return value.toString(); } catch (Exception e) { String className = value == null ? "<null>" : value.getClass().getCanonicalName(); throw ZeidonException.wrapException(e).appendMessage("Col index: %d\nValue %s\nClass: %s", idx, value, className); } }
From source file:com.rapidminer.operator.GenerateDateSeries.java
License:Open Source License
private long calculateNumberOfExample(DateTime startTime, DateTime endTime) { // TODO Auto-generated method stub long valuetoReturn = 0; try {//w ww . j a v a 2s . c om //getParameterAsString(key) switch (getParameterAsString(PARAMETER_INTERVALTYPE)) { case "YEAR": Years year = Years.yearsBetween(startTime, endTime); valuetoReturn = year.getYears() / getParameterAsInt(INTERVAL); break; case "MONTH": Months month = Months.monthsBetween(startTime, endTime); valuetoReturn = month.getMonths() / getParameterAsInt(INTERVAL); break; case "DAY": Days days = Days.daysBetween(startTime, endTime); valuetoReturn = days.getDays() / getParameterAsInt(INTERVAL); break; case "HOUR": Hours hours = Hours.hoursBetween(startTime, endTime); valuetoReturn = hours.getHours() / getParameterAsInt(INTERVAL); break; case "MINUTE": Minutes minute = Minutes.minutesBetween(startTime, endTime); valuetoReturn = minute.getMinutes() / getParameterAsInt(INTERVAL); break; case "SECOND": Seconds second = Seconds.secondsBetween(startTime, endTime); valuetoReturn = second.getSeconds() / getParameterAsInt(INTERVAL); break; case "MILLISECOND": // Milliseconds millisecond = milli long milli = endTime.getMillis() - startTime.getMillis(); valuetoReturn = milli / getParameterAsInt(INTERVAL); break; default: valuetoReturn = 0; } } catch (Exception e) { valuetoReturn = 0; } return valuetoReturn; }
From source file:com.ren.security.token.claim.ExpireDate.java
public boolean after(DateTime date) { return date.isAfter(date.getMillis()); }