List of usage examples for java.util Calendar DAY_OF_WEEK
int DAY_OF_WEEK
To view the source code for java.util Calendar DAY_OF_WEEK.
Click Source Link
get
and set
indicating the day of the week. From source file:net.kamhon.ieagle.util.DateUtil.java
/** * given date and return first date and last date of the week * /*from ww w. j a va2 s . c o m*/ * @param date * @return */ public static Date[] getFirstAndLastDateOfWeek(Date date) { date = truncateTime(date); Calendar cal = Calendar.getInstance(); cal.setTime(date); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // Sunday is 1, if dayOfWeek>1 mean date is Monday & above. if (dayOfWeek > 1) cal.add(Calendar.DATE, 1 - dayOfWeek); Date firstDate = cal.getTime(); cal.add(Calendar.DATE, 6); Date lastDate = cal.getTime(); return new Date[] { firstDate, lastDate }; }
From source file:fr.paris.lutece.plugins.calendar.service.Utils.java
/** * Returns the first monday of a week as a formatted string corresponding to * the date code//w w w. ja v a 2 s . c o m * @param strDate The date code * @return The first day label */ public static Calendar getFirstDayOfWeek(String strDate) { Calendar calendar = new GregorianCalendar(); Calendar calendarFirstDay = new GregorianCalendar(); calendar.set(Utils.getYear(strDate), Utils.getMonth(strDate), Utils.getDay(strDate)); int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (nDayOfWeek == 1) { nDayOfWeek = 8; } calendarFirstDay = calendar; calendarFirstDay.add(Calendar.DATE, Calendar.MONDAY - nDayOfWeek); return calendarFirstDay; }
From source file:fm.krui.kruifm.KRUIScheduleActivity.java
@Override public void onTextDownloaded() { String[] urls = { MAIN_SCHEDULE_RR_URL, MAIN_SCHEDULE_MS_URL, MAIN_SCHEDULE_S_URL, MAIN_SCHEDULE_NT_URL, MAIN_SCHEDULE_SP_URL }; String[] filenames = { MAIN_SCHEDULE_RR_FILENAME, MAIN_SCHEDULE_MS_FILENAME, MAIN_SCHEDULE_S_FILENAME, MAIN_SCHEDULE_NT_FILENAME, MAIN_SCHEDULE_SP_FILENAME }; // Initialize a Priority Queue which will cache show objects before sorting into the final showList. pq = new PriorityQueue<Show>(11, new ShowComparator()); // For each day of the week, scan all five event categories // For each text file we downloaded, parse the show data inside and store them in showList. for (int k = 0; k < filenames.length; k++) { Log.v(TAG, "* Beginning scan of category: " + filenames[k]); // Read text file try {//from w w w .j a va 2s.c o m // Construct a JSONObject from the stored text file containing events of this category JSONObject calObj = new JSONObject(readTextFile(new File(getFilesDir(), filenames[k]))); // Store Sun-Sat events from this category in the Priority Queue parseShowData(calObj, k + 1); } catch (NullPointerException e) { Log.e(TAG, "No shows found for category: " + filenames[k]); } catch (JSONException e) { Log.e(TAG, "JSONException thrown when processing shows!"); } } Log.v(TAG, "All shows have been parsed, now sort into their proper place in showList."); // Initialize show storage sunday = new ArrayList<Show>(); monday = new ArrayList<Show>(); tuesday = new ArrayList<Show>(); wednesday = new ArrayList<Show>(); thursday = new ArrayList<Show>(); friday = new ArrayList<Show>(); saturday = new ArrayList<Show>(); // Pull every show off the Priority Queue and store them int size = pq.size(); for (int i = 0; i < size; i++) { storeShow(pq.poll()); Log.v(TAG, "PQ Count:" + pq.size()); } // Fill date list dateList = new ArrayList<String>(); cal.get(Calendar.DAY_OF_WEEK); //dateList.add(); // Hook up pager and pagerAdapter and hide loading screen pager = (ViewPager) findViewById(R.id.schedule_pager); pagerAdapter = new SchedulePagerAdapter(getSupportFragmentManager()); pager.setAdapter(pagerAdapter); showLoadingScreen(false); }
From source file:edu.usf.cutr.gtfs_realtime.bullrunner.GtfsRealtimeProviderImpl.java
/** * This method downloads the latest vehicle data, processes each vehicle in * turn, and create a GTFS-realtime feed of trip updates and vehicle * positions as a result.//from w ww.ja v a 2 s .co m */ private void refreshTripVehicle() throws IOException, JSONException { Pair pair = downloadVehicleDetails(); JSONArray stopIDsArray = pair.getArray1(); JSONArray vehicleArray = pair.getArray2(); if (stopIDsArray.length() == 0) { routeVehicleStartTimeMap.clear(); } Calendar cal = Calendar.getInstance(); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1; String serviceID = _providerConfig.serviceIds[dayOfWeek]; GtfsRealtimeFullUpdate tripUpdates = new GtfsRealtimeFullUpdate(); GtfsRealtimeFullUpdate vehiclePositions = new GtfsRealtimeFullUpdate(); VehicleDescriptor.Builder vehicleDescriptor = null; String route, trip; int entity = 0; int vehicleFeedID = 0; String stopId = ""; String startTime = ""; String stopSeq; long predictTime = 0; TripUpdate.Builder tripUpdate = null; TripDescriptor.Builder tripDescriptor = null; List<TripUpdate.Builder> tripUpdateArr = new ArrayList<>(); List<stopTimeUpdateRecord> records = new ArrayList<stopTimeUpdateRecord>(); routeVehiDirMap = new BiHashMap<String, String, Float>(); tripVehicleInfoMap = new BiHashMap<String, String, vehicleInfo>(); BiHashMap<String, String, TripUpdate.Builder> tripUpdateMap = new BiHashMap<String, String, TripUpdate.Builder>(); for (int i = 0; i < stopIDsArray.length(); i++) { JSONObject obj = stopIDsArray.getJSONObject(i); route = obj.getString("route").substring(6); trip = _providerConfig.tripIDMap.get(route, serviceID); if (trip.equals("") || trip == null) _log.error("Route " + route + "dosn't exit in GTFS file"); int stopId_int = obj.getInt("stop"); stopId = Integer.toString(stopId_int); JSONArray childArray = obj.getJSONArray("Ptimes"); for (int j = 0; j < childArray.length(); j++) { JSONObject child = childArray.getJSONObject(j); String predTimeStamp = child.getString("PredictionTime"); predictTime = convertTime(predTimeStamp); String vehicleId = child.getString("VehicleId"); if (!tripUpdateMap.containsKey(route, vehicleId)) { tripUpdate = TripUpdate.newBuilder(); vehicleDescriptor = VehicleDescriptor.newBuilder(); vehicleDescriptor.setId(vehicleId); tripDescriptor = TripDescriptor.newBuilder(); tripDescriptor.setRouteId(route); tripDescriptor.setTripId(trip); tripUpdate.setVehicle(vehicleDescriptor); tripUpdate.setTrip(tripDescriptor); tripUpdateMap.put(route, vehicleId, tripUpdate); tripUpdateArr.add(tripUpdate); } else { tripUpdate = tripUpdateMap.get(route, vehicleId); } StopTimeEvent.Builder arrival = StopTimeEvent.newBuilder(); arrival.setTime(predictTime); StopTimeUpdate.Builder stopTimeUpdate = StopTimeUpdate.newBuilder(); stopTimeUpdate.setArrival(arrival); stopTimeUpdate.setStopId(stopId); stopSeq = _providerConfig.stopSeqIDMap.get(trip, stopId); if (stopSeq == null) { stopSeq = "0"; _log.warn("Error stopID: " + stopId + " is not available in GTFS files"); System.out.println("Error: stopID: " + stopId + " is not available in GTFS files"); } if (stopSeq.equals("1")) { startTime = convert2FormattedTime(predTimeStamp); //System.out.println("stopSeq =1, route "+ route+ ", vehicleID = "+ vehicleId); tripDescriptor.setStartTime(startTime); tripDescriptor.setScheduleRelationship(ScheduleRelationship.UNSCHEDULED); tripUpdate.setTrip(tripDescriptor); if (routeVehicleStartTimeMap.containsKeys(route, vehicleId)) { StartTimes startTimes = routeVehicleStartTimeMap.get(route, vehicleId); startTimes.previousStartT = startTimes.currentStartT; startTimes.currentStartT = startTime; } else { StartTimes startTInstance = new StartTimes(startTime, "0"); routeVehicleStartTimeMap.put(route, vehicleId, startTInstance); } //System.out.println("current starttime = "+ tripUpdate.getTrip().getStartTime()); } stopTimeUpdate.setStopSequence(Integer.parseInt(stopSeq)); records.add(new stopTimeUpdateRecord(tripUpdate, stopTimeUpdate)); //tripUpdate.addStopTimeUpdate(stopTimeUpdate); } } Collections.sort(records); for (int i = 0; i < records.size(); i++) { records.get(i).tripUpdate.addStopTimeUpdate(records.get(i).stopTimeUpdate); } /** * Create a new feed entity to wrap the trip update and add it * to the GTFS-realtime trip updates feed. */ for (int j = 0; j < tripUpdateArr.size(); j++) { FeedEntity.Builder tripUpdateEntity = FeedEntity.newBuilder(); tripUpdate = tripUpdateArr.get(j); //System.out.println("-----size of trip Updates = " + tripUpdate.getStopTimeUpdateList().size()); int noStopTimes = tripUpdate.getStopTimeUpdateList().size(); route = tripUpdate.getTrip().getRouteId(); trip = tripUpdate.getTrip().getTripId(); String vehicleId = tripUpdate.getVehicle().getId(); if (tripUpdate.getStopTimeUpdate(0).getStopSequence() != 1) { StartTimes startTInstance; if (routeVehicleStartTimeMap.containsKeys(route, vehicleId)) { startTInstance = routeVehicleStartTimeMap.get(route, vehicleId); } else { //cold start startTInstance = new StartTimes("0", "0"); routeVehicleStartTimeMap.put(route, vehicleId, startTInstance); } TripDescriptor.Builder newTripDescriptor = TripDescriptor.newBuilder(); newTripDescriptor.setTripId(trip); newTripDescriptor.setRouteId(route); newTripDescriptor.setStartTime(startTInstance.currentStartT); newTripDescriptor.setScheduleRelationship(ScheduleRelationship.UNSCHEDULED); tripUpdate.setTrip(newTripDescriptor); } // System.out.println("responseTimeStamp: "+ responseTimeStamp + "change it to unix: "+ responseTimeStamp); int delay; long preTime = 0; for (int h = 0; h < noStopTimes; h++) { long timeStamp = tripUpdate.getStopTimeUpdate(h).getArrival().getTime(); if (timeStamp < preTime) { delay = calcDelayTime(timeStamp); if (60 < delay) { StopTimeEvent.Builder arrival = StopTimeEvent.newBuilder(); arrival.setTime(timeStamp); StopTimeUpdate preStopTime = tripUpdate.getStopTimeUpdate(h - 1); StopTimeUpdate.Builder newStopTimeUpdate = StopTimeUpdate.newBuilder(preStopTime); newStopTimeUpdate.setArrival(arrival); tripUpdate.setStopTimeUpdate(h - 1, newStopTimeUpdate); preTime = timeStamp; // System.out.println("** h = "+ h+ " is "+ timeStamp+ " routeID: "+tripUpdate.getTrip().getRouteId()+ " vehicle: "+tripUpdate.getVehicle().getId()); // System.out.println("\t DELAY:"+ delay + ", stop time of h-1 change to "+ tripUpdate.getStopTimeUpdate(h-1).getArrival().getTime()+ " from "+ preTime); } else { // System.out.println(" h = " + h+" routeID: "+tripUpdate.getTrip().getRouteId()+ " vehicle: "+tripUpdate.getVehicle().getId()); List<StopTimeUpdate> allStopUpdates = tripUpdate.getStopTimeUpdateList(); tripUpdate.clearStopTimeUpdate(); TripUpdate.Builder newTripUpdate = tripUpdate.clone(); // we have to send out the old tripUpdate, but before that the rest of stopTimes should be deleted from it newTripUpdate.addAllStopTimeUpdate(allStopUpdates.subList(0, h)); entity++; tripUpdateEntity.setId(Integer.toString(entity)); tripUpdateEntity.setTripUpdate(newTripUpdate); tripUpdates.addEntity(tripUpdateEntity.build()); //System.out.println("what has been sent: size = "+ newTripUpdate.getStopTimeUpdateList().size()+ " stoptime"); tripUpdate.addAllStopTimeUpdate(allStopUpdates.subList(h, noStopTimes)); //System.out.println("current tripUpdate size = "+ tripUpdate.getStopTimeUpdateList().size()+ " stoptime"); preTime = 0; noStopTimes = noStopTimes - h; h = -1; StartTimes startTimes; if (routeVehicleStartTimeMap.containsKeys(route, vehicleId)) startTimes = routeVehicleStartTimeMap.get(route, vehicleId); else { startTimes = new StartTimes(startTime, "0"); routeVehicleStartTimeMap.put(route, vehicleId, startTimes); } String previousStartT = startTimes.previousStartT; TripDescriptor.Builder newTripDescriptor = TripDescriptor.newBuilder(); newTripDescriptor.setTripId(trip); newTripDescriptor.setRouteId(route); newTripDescriptor.setStartTime(previousStartT); newTripDescriptor.setScheduleRelationship(ScheduleRelationship.UNSCHEDULED); tripUpdate.setTrip(newTripDescriptor); //System.out.println("second startTime = "+ tripUpdate.getTrip().getStartTime()+ " &&&& first startTime = "+ newTripUpdate.getTrip().getStartTime()); } } else preTime = timeStamp; } entity++; tripUpdateEntity.setId(Integer.toString(entity)); tripUpdateEntity.setTripUpdate(tripUpdate); tripUpdates.addEntity(tripUpdateEntity.build()); } _tripUpdatesSink.handleFullUpdate(tripUpdates); _log.info("stoIDs extracted: " + tripUpdates.getEntities().size()); // System.out.println("stoIDs extracted: " + tripUpdates.getEntityCount()); float bearing; for (int k = 0; k < vehicleArray.length(); k++) { JSONObject vehicleObj = vehicleArray.getJSONObject(k); route = vehicleObj.getString("route").substring(6); JSONArray vehicleLocsArray = vehicleObj.getJSONArray("VehicleLocation"); for (int l = 0; l < vehicleLocsArray.length(); ++l) { JSONObject child = vehicleLocsArray.getJSONObject(l); double lat = child.getDouble("vehicleLat"); double lon = child.getDouble("vehicleLong"); /** * To construct our VehiclePosition, we create a position for * the vehicle. We add the position to a VehiclePosition * builder, along with the trip and vehicle descriptors. */ tripDescriptor = TripDescriptor.newBuilder(); tripDescriptor.setRouteId(route); Position.Builder position = Position.newBuilder(); //position.setLatitude((float) lat); //position.setLongitude((float) lon); FeedEntity.Builder vehiclePositionEntity = FeedEntity.newBuilder(); //int tripID_int = child.getInt("tripId"); String vehicleId = child.getString("VehicleId"); if (!routeVehiDirMap.containsKey(route)) extractHeading(route); vehicleInfo info = tripVehicleInfoMap.get(route, vehicleId); //_log.info("vehicles' info: " + info); bearing = info.bearing; //routeVehiDirMap.get(route, vehicleId); position.setBearing(bearing); position.setLatitude(info.lat); position.setLongitude(info.longi); VehiclePosition.Builder vehiclePosition = VehiclePosition.newBuilder(); vehiclePosition.setPosition(position); vehiclePosition.setTrip(tripDescriptor); if (info.APCPercentage <= 0) vehiclePosition.setOccupancyStatus(VehiclePosition.OccupancyStatus.EMPTY); else if (info.APCPercentage >= 95) vehiclePosition.setOccupancyStatus(VehiclePosition.OccupancyStatus.FULL); else if (info.APCPercentage <= 50) vehiclePosition.setOccupancyStatus(VehiclePosition.OccupancyStatus.MANY_SEATS_AVAILABLE); else vehiclePosition.setOccupancyStatus(VehiclePosition.OccupancyStatus.FEW_SEATS_AVAILABLE); vehicleDescriptor = VehicleDescriptor.newBuilder(); vehicleDescriptor.setId(vehicleId); vehicleFeedID++; vehiclePositionEntity.setId(Integer.toString(vehicleFeedID)); vehiclePosition.setVehicle(vehicleDescriptor); vehiclePositionEntity.setVehicle(vehiclePosition); vehiclePositions.addEntity(vehiclePositionEntity.build()); } } _vehiclePositionsSink.handleFullUpdate(vehiclePositions); _log.info("vehicles' location extracted: " + vehiclePositions.getEntities().size()); //System.out.println("vehicles' location extracted: " + vehiclePositions.getEntityCount()); }
From source file:com.autentia.tnt.manager.holiday.UserHolidaysStateManager.java
public UserHolidaysState calcUserHolidaysState(User usuario, Date chargeYear) { UserHolidaysState uhs = new UserHolidaysState(); uhs.setUser(usuario);//from w w w . j a v a2 s . c om // WorkingAgreement attribute is an HB proxy not initialized, we need to get it from DB WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault(); WorkingAgreement agreement = workingAgreementDao.getById(usuario.getAgreement().getId()); // and refresh the user instance agreement attribute usuario.setAgreement(agreement); uhs.setTotalYear(agreement.getHolidays()); int acceptedHolidays = 0; if (chargeYear != null) { HolidayManager fiestasManager = HolidayManager.getDefault(); // We must take in account previous year holidays and next year holidays Calendar calMin = Calendar.getInstance(); calMin.setTime(chargeYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); Calendar calMax = Calendar.getInstance(); calMax.setTime(chargeYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); calMin.add(Calendar.YEAR, -1); calMax.add(Calendar.YEAR, 1); HolidaySearch fiestaSearch = new HolidaySearch(); fiestaSearch.setStartDate(calMin.getTime()); fiestaSearch.setEndDate(calMax.getTime()); List<Holiday> listFiestas = fiestasManager.getAllEntities(fiestaSearch, null); calMin.setTime(chargeYear); calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH)); calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH)); calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY)); calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE)); calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND)); calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND)); calMax.setTime(chargeYear); calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH)); calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH)); calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY)); calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE)); calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND)); calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND)); RequestHolidayManager holyManager = RequestHolidayManager.getDefault(); RequestHolidaySearch holSearch = new RequestHolidaySearch(); holSearch.setUserRequest(uhs.getUser()); holSearch.setState(HolidayState.ACCEPT); holSearch.setStartChargeYear(calMin.getTime()); holSearch.setEndChargeYear(calMax.getTime()); List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, null); for (RequestHoliday rH : listH) { Calendar cActual = Calendar.getInstance(); cActual.setTime(rH.getBeginDate()); while (!cActual.getTime().after(rH.getFinalDate())) { if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { boolean isFiesta = false; for (Holiday fiest : listFiestas) { Calendar cFiesta = Calendar.getInstance(); cFiesta.setTime(fiest.getDate()); if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR) && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH) && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) { isFiesta = true; } } if (!isFiesta) { acceptedHolidays++; } } cActual.add(Calendar.DAY_OF_MONTH, 1); } } uhs.setTotalAccepted(acceptedHolidays); Calendar calAuxCont = Calendar.getInstance(); calAuxCont.setTime(uhs.getUser().getStartDate()); Calendar calAux = Calendar.getInstance(); calAux.setTime(chargeYear); int yearCharge = calAux.get(Calendar.YEAR); int yearContract = calAuxCont.get(Calendar.YEAR); if (yearCharge == yearContract) { // Dividimos los das de cada usuario entre los meses del ao. double ratio = uhs.getUser().getAgreement().getHolidays() / 12.0; int monthContract = calAuxCont.get(Calendar.MONTH); int meses = (Calendar.DECEMBER - monthContract); double diasVacaciones = meses * ratio; double aux = Math.ceil(diasVacaciones); uhs.setTotalYear((int) aux); } } return uhs; }
From source file:com.sec.ose.osi.ui.frm.main.manage.JPanManageMain.java
private long calcNextAnalyzeTime(int timeCycle, int timeHour, int timeMinite) { long timeGap = 0; Calendar FixedCale = Calendar.getInstance(); FixedCale.set(Calendar.HOUR_OF_DAY, timeHour); FixedCale.set(Calendar.MINUTE, timeMinite); FixedCale.set(Calendar.SECOND, 0); FixedCale.set(Calendar.MILLISECOND, 0); log.debug("starting of fixed time : " + DateUtil.getFormatingTime("%1$tb/%1$te, %1$tI:%1$tM %1$tp", FixedCale.getTimeInMillis())); if (timeCycle > 0) { // week/*ww w. j av a2 s .c o m*/ FixedCale.set(Calendar.DAY_OF_WEEK, timeCycle); if (FixedCale.getTimeInMillis() < System.currentTimeMillis()) { FixedCale.add(Calendar.DAY_OF_MONTH, 7); } } else { // daily if (FixedCale.getTimeInMillis() < System.currentTimeMillis()) { FixedCale.add(Calendar.DAY_OF_MONTH, 1); } } timeGap = FixedCale.getTimeInMillis() - System.currentTimeMillis(); if (timeGap == 0) { timeGap = 24 * 60 * 60 * 1000; } return timeGap; }
From source file:com.discovery.darchrow.date.DateUtil.java
/** * date <span style="color:red">?()</span> <code>23:59:59.999</code> . * //w w w . ja v a 2 s . c o m * <p> * ?:,<span style="color:red">,?</span><br> * ?:,? * </p> * * <pre> * 2012-10-11 17:10:30.701 (), * return 2012-10-13 23:59:59.999 * * * getLastDateOfThisWeek(2014-12-31 05:00:00) * return 2015-01-03 23:59:59.999 * </pre> * * @param date * ?date * @return date ? <code>23:59:59.999</code> * @see #toCalendar(Date) * @see Calendar#set(int, int) * @see CalendarUtil#resetDayEnd(Calendar) * @see Calendar#getTime() * @since 1.0.1 */ public static Date getLastDateOfThisWeek(Date date) { Calendar calendar = toCalendar(date); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); CalendarUtil.resetDayEnd(calendar); return CalendarUtil.toDate(calendar); }
From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java
@Override public Inicio ayer(Inicio inicio) { Inicio ayer = new Inicio(); Integer anio = new Integer(inicio.getAnio()); String trimestre = inicio.getTrimestre(); String leccion = inicio.getLeccion(); String dia = inicio.getDia(); if (StringUtils.isBlank(dia)) { dia = obtieneDia(new GregorianCalendar(Locale.ENGLISH).get(Calendar.DAY_OF_WEEK)); }//from w ww. j ava 2 s . co m Trimestre t = trimestreService.obtiene(anio + trimestre); if (t != null) { try { Calendar cal = new GregorianCalendar(Locale.ENGLISH); cal.setTime(t.getInicia()); cal.add(Calendar.SECOND, 1); cal.set(Calendar.DAY_OF_WEEK, obtieneDia(dia)); int weeks = ((Long) nf.parse(leccion.substring(1))).intValue(); if (dia.equals("sabado")) { weeks--; } cal.add(Calendar.WEEK_OF_YEAR, weeks); cal.add(Calendar.DAY_OF_MONTH, -1); Date hoy = cal.getTime(); ayer.setHoy(hoy); t = trimestreService.obtiene(hoy); DateTime a = new DateTime(t.getInicia()); DateTime b = new DateTime(hoy); Weeks c = Weeks.weeksBetween(a, b); weeks = c.getWeeks(); weeks++; leccion = "l" + dosDigitos.format(weeks); ayer.setAnio(t.getNombre().substring(0, 4)); ayer.setTrimestre(t.getNombre().substring(4)); ayer.setLeccion(leccion); ayer.setDia(obtieneDia(cal.get(Calendar.DAY_OF_WEEK))); return ayer; } catch (ParseException e) { log.error("No pude poner la fecha de ayer", e); } } return null; }
From source file:com.hihframework.core.utils.DateUtils.java
/** * ?//from w w w . j av a 2s. c om * * @param date java.sql.Date ?? * @return Date[] java.sql.Date */ public static java.sql.Date[] getWeekDays(java.sql.Date date) { Calendar cale = Calendar.getInstance(); cale.setTime(date); cale.setFirstDayOfWeek(Calendar.SUNDAY); int days = 7; int today = cale.get(Calendar.DAY_OF_WEEK); long millis = cale.getTimeInMillis(); java.sql.Date dates[] = new java.sql.Date[days]; for (int i = 1; i <= days; i++) { long sub = (today - i) * 24 * 60 * 60 * 1000L; dates[i - 1] = new java.sql.Date(millis - sub); } cale = null; return dates; }
From source file:models.Schedule.java
public boolean isRunnable(Calendar calendar) { return isRunnable(startMinute, endMinute, MINUTE_START, MINUTE_END, calendar.get(Calendar.MINUTE)) && isRunnable(startHourOfDay, endHourOfDay, HOUR_OF_DAY_START, HOUR_OF_DAY_END, calendar.get(Calendar.HOUR_OF_DAY)) && isRunnable(startDayOfMonth, endDayOfMonth, DAY_OF_MONTH_START, DAY_OF_MONTH_END, calendar.get(Calendar.DAY_OF_MONTH)) && isRunnable(startDayOfWeek, endDayOfWeek, DAY_OF_WEEK_START, DAY_OF_WEEK_END, calendar.get(Calendar.DAY_OF_WEEK)) && isRunnable(startYear, endYear, YEAR_START, YEAR_END, calendar.get(Calendar.YEAR)); }