List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:io.github.protino.codewatch.ui.OnBoardActivity.java
License:Apache License
@SuppressLint("ApplySharedPref") private void onSetupComplete() { //download whole leaderboards data asynchronously new FetchLeaderBoardDataAsync(this).execute(); //schedule daily sync at 3:00 am local time FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this)); DateTime now = new DateTime(); DateTime tomorrow = now.plusDays(1).withTimeAtStartOfDay().plusHours(3); int windowStart = Hours.hoursBetween(now, tomorrow).getHours() * 60 * 60; Job synJob = dispatcher.newJobBuilder().setService(SyncScheduler.class) .setTag(Constants.PERIODIC_SYNC_SCHEDULE_KEY).setReplaceCurrent(true) .setTrigger(Trigger.executionWindow(windowStart, windowStart + 10)) .setConstraints(Constraint.ON_ANY_NETWORK).setRetryStrategy(RetryStrategy.DEFAULT_LINEAR).build(); dispatcher.mustSchedule(synJob);/*from w ww. jav a 2s . c o m*/ sharedPreferences.edit().putBoolean(Constants.PREF_FIREBASE_SETUP, true).commit(); startActivity(new Intent(this, PreChecksActivity.class)); finish(); }
From source file:io.renren.common.utils.DateUtils.java
License:Apache License
/** * ?/?//from w w w .j a v a 2s . co m * * @param date * @param days ? * @return /?? */ public static Date addDateDays(Date date, int days) { DateTime dateTime = new DateTime(date); return dateTime.plusDays(days).toDate(); }
From source file:io.warp10.script.functions.ADDDAYS.java
License:Apache License
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object top = stack.pop();/*from ww w.j a va 2s .c o m*/ if (!(top instanceof Long)) { throw new WarpScriptException(getName() + " expects a number of days on top of the stack."); } int days = ((Number) top).intValue(); top = stack.pop(); String tz = null; if (top instanceof String) { tz = top.toString(); top = stack.pop(); if (!(top instanceof Long)) { throw new WarpScriptException( getName() + " operates on a tselements list, timestamp, or timestamp and timezone."); } } else if (!(top instanceof List) && !(top instanceof Long)) { throw new WarpScriptException( getName() + " operates on a tselements list, timestamp, or timestamp and timezone."); } if (top instanceof Long) { long instant = ((Number) top).longValue(); if (null == tz) { tz = "UTC"; } DateTimeZone dtz = DateTimeZone.forID(null == tz ? "UTC" : tz); DateTime dt = new DateTime(instant / Constants.TIME_UNITS_PER_MS, dtz); dt = dt.plusDays(days); long ts = dt.getMillis() * Constants.TIME_UNITS_PER_MS + (instant % Constants.TIME_UNITS_PER_MS); stack.push(ts); } else { List<Object> elts = new ArrayList<Object>((List<Object>) top); int year = ((Number) elts.get(0)).intValue(); int month = ((Number) elts.get(1)).intValue(); int day = ((Number) elts.get(2)).intValue(); if (days < 0) { while (days < 0) { days++; day = day - 1; if (day < 1) { month--; if (month < 1) { year--; month = 12; } if (1 == month || 3 == month || 5 == month || 7 == month || 8 == month || 10 == month || 12 == month) { day = 31; } else if (4 == month || 6 == month || 9 == month || 11 == month) { day = 30; } else if (0 == year % 100 || 0 != year % 4) { day = 28; } else { day = 29; } } } } else { while (days > 0) { days--; day = day + 1; if ((1 == month || 3 == month || 5 == month || 7 == month || 8 == month || 10 == month || 12 == month) && day > 31) { month++; day = 1; } else if ((4 == month || 6 == month || 9 == month || 11 == month) && day > 30) { month++; day = 1; } else if (2 == month && (0 == year % 100 || 0 != year % 4) && day > 28) { month++; day = 1; } else if (2 == month && day > 29) { month++; day = 1; } if (month > 12) { month = 1; year++; } } } elts.set(0, (long) year); elts.set(1, (long) month); elts.set(2, (long) day); stack.push(elts); } return stack; }
From source file:it.jugpadova.blo.EventBo.java
License:Apache License
public List<NewsMessage> buildNewsMessages(String baseUrl) { List<NewsMessage> messages = new ArrayList<NewsMessage>(); DateTime dt = new DateTime(); List<Event> upcomings = eventDao.findUpcomingEvents(dt.plusDays(conf.getUpcomingEventDays()).toDate()); for (Event event : upcomings) { messages.add(new NewsMessage(NewsMessage.TYPE_UPCOMING_EVENT, event.getStartDate(), event, baseUrl)); }//from ww w . j a v a 2s .c om List<Event> newEvents = eventDao.findNewEvents(dt.minusDays(conf.getNewEventDays()).toDate()); for (Event event : newEvents) { if (!upcomings.contains(event)) { messages.add(new NewsMessage(NewsMessage.TYPE_NEW_EVENT, event.getStartDate(), event, baseUrl)); } } List<LinkedEvent> linkedEvents = linkedEventDao.findExposedEvents(); for (LinkedEvent linkedEvent : linkedEvents) { messages.add(new NewsMessage(NewsMessage.TYPE_LINKED_EVENT, linkedEvent.getStartDate(), linkedEvent, baseUrl)); } return messages; }
From source file:it.polimi.se.calcare.service.EventFacadeREST.java
private List<Forecast> forecastCreator(Date s, Date e, City city) throws JSONException, IOException { DateTime start = new DateTime(s); DateTime end = new DateTime(e); int cnt = Days.daysBetween(start, end).getDays(); List<Forecast> toUpdate = new ArrayList<>(); for (int i = 0; i <= cnt; i++) { Forecast forecast = new Forecast(new ForecastPK(start.plusDays(i).toDate(), city.getId()), 0, 0, 0, 0); toUpdate.add(forecast);/*from w w w . ja v a2 s .c om*/ } List<Forecast> toPush = new GetWeather().updateForecast(city, toUpdate); for (Forecast item : toPush) { em.merge(item); } em.flush(); return toPush; }
From source file:it.webappcommon.lib.DateUtils.java
License:Open Source License
public static List<Date> calcolaDateIntermedie(Date start, Date end) { List<Date> res = new ArrayList<Date>(); DateTime startDate = new DateTime(start); DateTime endDate = new DateTime(end); if (differenzaInGiorni(start, end) > 0) { res.add(startDate.toDate());//from w ww . java 2 s.com startDate = startDate.plusDays(1); while (differenzaInGiorni(startDate.toDate(), end) != 0) { res.add(startDate.toDate()); startDate = startDate.plusDays(1); } res.add(startDate.toDate()); } else { res.add(start); } return res; }
From source file:jarvis.Jarvis.java
private void alarmAtTime(int hour, int min) { hour = hour % 24;/* ww w . ja va2 s .co m*/ min = min % 60; try { System.out.println("activate alarm"); String fullTime = ""; if (hour < 10) { fullTime += "0"; } fullTime += hour + ":"; if (min < 10) { fullTime += "0"; } fullTime += min + ":00"; Calendar cal = Calendar.getInstance(); int curentHour = cal.get(cal.HOUR_OF_DAY); int curentMin = cal.get(cal.MINUTE); int curentDayOfMonth = cal.get(Calendar.DAY_OF_MONTH); // Calendar c = Calendar.getInstance(); // DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); // //get current date time with Date() // Date date = new Date(); // System.out.println(dateFormat.format(date)); // // //get current date time with Calendar() // dateFormat.format(cal.getTime()); //c.setTime(date); //c.add(Calendar.DATE, 1); //date = c.getTime(); Date targetDateAlarm; DateTime usingTimeDate; String extraInfo = "today"; if (curentHour > hour || curentHour == hour && curentMin >= min) { System.out.println("tomorrow date"); extraInfo = "tomorrow"; // org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID("America/Los_Angeles"); DateTime now = new DateTime(); usingTimeDate = now.plusDays(1); // int year = tomorrowAsJUDate.getYear(); // int month = tomorrowAsJUDate.getMonth(); // int day = tomorrowAsJUDate.getDate(); // System.out.println(year + "/" + month + "/" + day); // targetDateAlarm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(year + "/" + month + "/" + day + " " + fullTime); // System.out.println(targetDateAlarm); } else { usingTimeDate = new DateTime(); // targetDateAlarm = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(fullTime); } targetDateAlarm = usingTimeDate.toDate(); targetDateAlarm.setHours(hour); targetDateAlarm.setMinutes(min); targetDateAlarm.setSeconds(0); System.out.println(targetDateAlarm); DateTime now = new DateTime(); long diffInMillis = (targetDateAlarm.getTime() - now.toDate().getTime()) / 1000; System.out.println(diffInMillis + " seconds"); dospeak("alarm will ring at " + hour + " and " + min + " o'clock " + extraInfo + " sir."); alarmInNTime((int) diffInMillis, "seconds", false); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:jp.co.ntt.atrs.domain.service.b0.TicketSharedServiceImpl.java
License:Apache License
/** * {@inheritDoc}/*from w ww . j a v a 2 s . c om*/ */ @Override public void validateDepatureDate(Date departureDate) throws BusinessException { Assert.notNull(departureDate); DateTime sysDateMidnight = dateFactory.newDateTime().withTimeAtStartOfDay(); DateTime limitDateMidnight = getSearchLimitDate().toDateTimeAtStartOfDay(); // ???????????? Interval reservationAvailableInterval = new Interval(sysDateMidnight, limitDateMidnight.plusDays(1)); if (!reservationAvailableInterval.contains(departureDate.getTime())) { throw new AtrsBusinessException(TicketSearchErrorCode.E_AR_B1_2001); } }
From source file:jp.co.ntt.atrs.domain.service.b0.TicketSharedServiceImpl.java
License:Apache License
/** * {@inheritDoc}//from ww w . ja va 2s .c o m */ @Override public boolean isAvailableFareType(FareType fareType, Date depDate) { Assert.notNull(fareType); Assert.notNull(depDate); DateTime depDateMidnight = new DateTime(depDate).withTimeAtStartOfDay(); // DateTime rsrvAvailableStartDate = depDateMidnight.minusDays(fareType.getRsrvAvailableStartDayNum()); // DateTime rsrvAvailableEndDate = depDateMidnight.minusDays(fareType.getRsrvAvailableEndDayNum()); // ? DateTime sysDateMidnight = dateFactory.newDateTime().withTimeAtStartOfDay(); // ????????? return new Interval(rsrvAvailableStartDate, rsrvAvailableEndDate.plusDays(1)).contains(sysDateMidnight); }
From source file:json.Calendar2Servlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// ww w. j a v a2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { CalendarDates2 cal; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat nor = new SimpleDateFormat("dd-MM-yyyy"); DateTime fin; CalendarDTO c[] = new CalendarDTO[1344]; // capasidad de 1344 int t = 0; List l = new ArrayList(); try { cal = new CalendarDates2(); while (cal.getDatos().getResultSet().next()) { c[t] = new CalendarDTO(); c[t].setId(t); c[t].setStart("" + cal.getDatos().getResultSet().getDate("Incextr")); fin = DateTime.parse(cal.getDatos().getResultSet().getDate("Finextr").toString()); fin = fin.plusDays(1); c[t].setEnd("" + f.format(fin.toLocalDate().toDate())); c[t].setTitle("" + cal.getDatos().getResultSet().getInt("Orden") + " " + cal.getDatos().getResultSet().getString("Responsable").trim()); if (!f.format(cal.getDatos().getResultSet().getDate("Finreal")).equals("2001-01-01")) { c[t].setDescription("<h2 align='center'>" + cal.getDatos().getResultSet().getString("AREA").trim() + " </h2>" + "<h4> Ubicacion Tecnica : </h4>" + cal.getDatos().getResultSet().getString("Denominacion").trim() + "<h4> Responsable : </h4>" + cal.getDatos().getResultSet().getString("PtoTrbRes").trim() + "<h4> Operarios :</h4>" + cal.getDatos().getResultSet().getString("ayudantes").trim() + "<h4> TextoBreveOperacion : </h4> <p>" + cal.getDatos().getResultSet().getString("TextoOperacion") + "</p>" + "<h4> TextoBreve : </h4> <p> " + cal.getDatos().getResultSet().getString("Textobreve").trim() + "</p>" + "<h4> Periodo: </h4> <p> " + nor.format(cal.getDatos().getResultSet().getDate("Incextr")) + " AL " + nor.format(cal.getDatos().getResultSet().getDate("Finextr")) + "</p>" + "<h4> Estado : </h4>" + cal.getDatos().getResultSet().getString("Estado").trim() + "<h4> Finaliz el : </h4> <p>" + nor.format(cal.getDatos().getResultSet().getDate("Finreal")) + "</p>"); } else { c[t].setDescription("<h2 align='center'>" + cal.getDatos().getResultSet().getString("AREA").trim() + " </h2>" + "<h4> Ubicacion Tecnica : </h4>" + cal.getDatos().getResultSet().getString("Denominacion").trim() + "<h4> Responsable : </h4>" + cal.getDatos().getResultSet().getString("PtoTrbRes").trim() + "<h4> Operarios :</h4>" + cal.getDatos().getResultSet().getString("ayudantes").trim() + "<h4> TextoBreveOperacion : </h4> <p>" + cal.getDatos().getResultSet().getString("TextoOperacion") + "</p>" + "<h4> TextoBreve : </h4> <p> " + cal.getDatos().getResultSet().getString("Textobreve").trim() + "</p>" + "<h4> Periodo: </h4> <p> " + nor.format(cal.getDatos().getResultSet().getDate("Incextr")) + " AL " + nor.format(cal.getDatos().getResultSet().getDate("Finextr")) + "</p>" + "<h4> Estado : </h4>" + cal.getDatos().getResultSet().getString("Estado").trim() + "<h4> Finaliz el : </h4> <p> </p>"); } if (!f.format(cal.getDatos().getResultSet().getDate("Finreal")).equals("2001-01-01")) { c[t].setColor("white"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("MANTENIMIENTO")) { c[t].setColor("skyblue"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("OPERACION")) { c[t].setColor("black"); c[t].setBorderColor("skyblue"); c[t].setTextColor("white"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("SEGURIDAD")) { c[t].setColor("#ff6347"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("UAT")) { c[t].setColor("gray"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } l.add(c[t]); t++; } cal.getConexion().close(); } catch (SQLException ex) { Logger.getLogger(CalendarJsonServlet.class.getName()).log(Level.SEVERE, null, ex); } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.write(new Gson().toJson(l)); }