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:org.openmrs.module.facilitydata.web.controller.FacilityDataCompletionAnalysisFormController.java
@RequestMapping("/module/facilitydata/completionAnalysis.form") public void viewForm(ModelMap map, HttpServletRequest request, @ModelAttribute("query") FacilityDataQuery query) { FacilityDataService fds = Context.getService(FacilityDataService.class); if (query.getSchema() != null) { Date validFrom = query.getSchema().getValidFrom(); if (query.getFromDate() != null && validFrom != null && query.getFromDate().before(validFrom)) { query.setFromDate(validFrom); }// w w w. ja v a 2 s . co m if (query.getFromDate() == null) { Date minEntryDate = fds.getMinEnteredStartDateForSchema(query.getSchema()); if (minEntryDate == null) { minEntryDate = new Date(); } query.setFromDate(minEntryDate); } Date validTo = query.getSchema().getValidTo(); if (query.getToDate() != null && validTo != null && query.getToDate().after(validTo)) { query.setToDate(validTo); } if (query.getToDate() == null) { query.setToDate(new Date()); } Calendar cal = Calendar.getInstance(); Frequency frequency = query.getSchema().getForm().getFrequency(); if (frequency == Frequency.MONTHLY) { cal.setTime(query.getFromDate()); if (cal.get(Calendar.DATE) > 1) { cal.set(Calendar.DATE, 1); query.setFromDate(cal.getTime()); } cal.setTime(query.getToDate()); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); query.setToDate(cal.getTime()); } int numExpected = 0; List<Integer> daysOfWeek = FacilityDataConstants.getDailyReportDaysOfWeek(); Map<FacilityDataFormQuestion, Integer> numValuesByQuestion = new LinkedHashMap<FacilityDataFormQuestion, Integer>(); Map<FacilityDataFormQuestion, Double> numericTotals = new HashMap<FacilityDataFormQuestion, Double>(); Map<FacilityDataFormQuestion, Map<FacilityDataCodedOption, Integer>> codedTotals = new HashMap<FacilityDataFormQuestion, Map<FacilityDataCodedOption, Integer>>(); cal.setTime(query.getFromDate()); while (cal.getTime().compareTo(query.getToDate()) <= 0) { if (frequency != Frequency.DAILY || daysOfWeek.contains(cal.get(Calendar.DAY_OF_WEEK))) { numExpected++; } cal.add(frequency.getCalendarField(), frequency.getCalendarIncrement()); } List<FacilityDataValue> values = fds.evaluateFacilityDataQuery(query); Map<FacilityDataFormQuestion, Map<Location, FacilityDataValue>> latestValuesForQuestion = new HashMap<FacilityDataFormQuestion, Map<Location, FacilityDataValue>>(); for (FacilityDataValue v : values) { Integer numValues = numValuesByQuestion.get(v.getQuestion()); numValuesByQuestion.put(v.getQuestion(), numValues == null ? 1 : numValues + 1); FacilityDataQuestionType type = v.getQuestion().getQuestion().getQuestionType(); if (type instanceof CodedFacilityDataQuestionType) { Map<FacilityDataCodedOption, Integer> m = codedTotals.get(v.getQuestion()); if (m == null) { m = new HashMap<FacilityDataCodedOption, Integer>(); codedTotals.put(v.getQuestion(), m); } Integer num = m.get(v.getValueCoded()); num = num == null ? 1 : num + 1; m.put(v.getValueCoded(), num); } else { PeriodApplicability pa = v.getQuestion().getQuestion().getPeriodApplicability(); if (pa == PeriodApplicability.DURING_PERIOD) { Double num = numericTotals.get(v.getQuestion()); if (num == null) { num = new Double(0); } num += v.getValueNumeric(); numericTotals.put(v.getQuestion(), num); } else { Map<Location, FacilityDataValue> valueForQuestion = latestValuesForQuestion .get(v.getQuestion()); if (valueForQuestion == null) { valueForQuestion = new HashMap<Location, FacilityDataValue>(); latestValuesForQuestion.put(v.getQuestion(), valueForQuestion); } FacilityDataValue valueForLocation = valueForQuestion.get(v.getFacility()); if (valueForLocation == null || valueForLocation.getToDate().before(v.getToDate())) { valueForQuestion.put(v.getFacility(), v); } } } } if (!latestValuesForQuestion.isEmpty()) { for (FacilityDataFormSection section : query.getSchema().getSections()) { for (FacilityDataFormQuestion question : section.getQuestions()) { Double d = new Double(0); Map<Location, FacilityDataValue> m = latestValuesForQuestion.get(question); if (m != null) { for (FacilityDataValue v : m.values()) { if (v != null) { d += v.getValueNumeric(); } } numericTotals.put(question, d); } } } } if (query.getFacility() == null) { numExpected = numExpected * getLocations().size(); } else { Set<Location> allFacilities = FacilityDataUtil.getAllLocationsInHierarchy(query.getFacility()); List<Location> supportedFacilities = FacilityDataConstants.getSupportedFacilities(); allFacilities.retainAll(supportedFacilities); numExpected = numExpected * allFacilities.size(); } map.addAttribute("numExpected", numExpected); map.addAttribute("numValuesByQuestion", numValuesByQuestion); map.addAttribute("numericTotals", numericTotals); map.addAttribute("codedTotals", codedTotals); } }
From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java
@Test public void testDoActivateSuccess() throws Exception { properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, Calendar.SUNDAY); Calendar actual = Calendar.getInstance(); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); actual.set(Calendar.HOUR_OF_DAY, 1); actual.set(Calendar.MINUTE, 29); filter.doActivate(componentContext); filter.adjustExpires(actual);/*from www .ja va 2 s . co m*/ assertEquals(Calendar.SUNDAY, actual.get(Calendar.DAY_OF_WEEK)); // Abstract class will pass expires, this checks we aren't messing with the time. assertEquals(1, actual.get(Calendar.HOUR_OF_DAY)); assertEquals(29, actual.get(Calendar.MINUTE)); }
From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java
/** * // w ww . ja va2s. c om * @param date * @return array of two date elements, first is the first day of week, and * the second is the end week date */ public static Date[] getBounceDateofWeek(Date date) { Calendar calendar = new GregorianCalendar(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(date); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date begin = calendar.getTime(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date end = calendar.getTime(); return new Date[] { begin, end }; }
From source file:dk.cafeanalog.AnalogDownloader.java
public List<DayOfOpenings> getDaysOfOpenings() throws JSONException, ParseException, IOException { ArrayList<Opening> openings = getOpenings(); Collections.sort(openings, new Comparator<Opening>() { @Override//from w ww .ja va 2s.c o m public int compare(Opening lhs, Opening rhs) { return lhs.getOpen().compareTo(rhs.getOpen()); } }); ArrayList<DayOfOpenings> result = new ArrayList<>(); Calendar calendar = Calendar.getInstance(); for (Opening opening : openings) { calendar.setTime(opening.getOpen()); int dayOfMonth = calendar.get(Calendar.DATE); DayOfOpenings day; boolean retrieved = false; if (!result.isEmpty()) { day = result.get(result.size() - 1); if (day.getDayOfMonth() != dayOfMonth) { day = new DayOfOpenings(dayOfMonth, calendar.get(Calendar.DAY_OF_WEEK)); } else { retrieved = true; } } else { day = new DayOfOpenings(dayOfMonth, calendar.get(Calendar.DAY_OF_WEEK)); } int openHour = calendar.get(Calendar.HOUR_OF_DAY); switch (openHour) { case 9: day.setMorning(); break; case 11: day.setNoon(); break; case 14: day.setAfternoon(); break; default: Log.d("OpeningsTranslation", "Wrong hour: " + openHour); } calendar.setTime(opening.getClose()); int closeHour = calendar.get(Calendar.HOUR_OF_DAY); if (openHour == 9 && closeHour == 14) { day.setNoon(); } else if (openHour == 9 && closeHour == 17) { day.setNoon(); day.setAfternoon(); } else if (openHour == 11 && closeHour == 17) { day.setAfternoon(); } if (!retrieved) result.add(day); } return result; }
From source file:ch.ethz.dcg.jukefox.model.player.playlog.PlayLog.java
License:asdf
public void writeToPlayLog(final Date time, final PlaylistSong<BaseArtist, BaseAlbum> song, final boolean skip, final int playbackPosition) { int day_of_week = 0, hour_of_day = 0; long utcTime = time.getTime(); Calendar cal = Calendar.getInstance(); // in minutes int timeZoneOffset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000; // in hours// ww w . ja v a 2s .co m timeZoneOffset /= 60; Calendar logcalendar = Calendar.getInstance(); logcalendar.setTimeInMillis(time.getTime()); day_of_week = logcalendar.get(Calendar.DAY_OF_WEEK); hour_of_day = logcalendar.get(Calendar.HOUR_OF_DAY); Log.v(TAG, "day of week: " + day_of_week); Log.v(TAG, "hour of day: " + hour_of_day); Log.v(TAG, "utcTime: " + utcTime); AbstractContextResult contextData = contextProvider.getMeanContextValues(30 * 1000); try { // Write playlog entry dbDataPortal.writePlayLogEntry(playerModelId, song, utcTime, timeZoneOffset, day_of_week, hour_of_day, skip, playerController.getPlayMode().getPlayModeType().value(), contextData, playbackPosition); // Write a rating entry as well double fractionPlayed = playbackPosition / (double) song.getDuration(); ratingHelper.addRatingFromPlayLog(song, time, fractionPlayed); } catch (DataWriteException e) { Log.w(TAG, e); } }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on date start and resource * @param start/* w w w.j ava 2 s . com*/ * @param resource * @return CategoryDataset */ protected CategoryDataset createDataset(Timestamp start, MResource resource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); Timestamp date = start; String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID()); int days = 1; long hours = t.getTimeSlotHours(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Long Hours = new Long(hours); int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", resource.getS_Resource_ID()); MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID); if (!uom.isHour()) { return dataset; } long summary = 0; while (days < 32) { String day = new String(new Integer(date.getDate()).toString()); long HoursLoad = getLoad(resource, date).longValue(); Long Hours = new Long(hours); switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: days++; if (t.isOnSunday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.MONDAY: days++; if (t.isOnMonday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.TUESDAY: days++; if (t.isOnTuesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.WEDNESDAY: days++; if (t.isOnWednesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.THURSDAY: days++; if (t.isOnThursday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.FRIDAY: days++; if (t.isOnFriday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.SATURDAY: days++; if (t.isOnSaturday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } } } return dataset; }
From source file:net.diogobohm.timed.impl.ui.overviewwindow.OverviewWindowController.java
private Date getNextSaturday(Date start) { Calendar calendar = Calendar.getInstance(); calendar.setTime(start);//from w w w . ja v a 2 s. com while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { calendar.setTime(DateUtils.addDays(calendar.getTime(), 1)); } return calendar.getTime(); }
From source file:com.eryansky.common.utils.SysUtils.java
public static String getNowDateStr() { String result = dateFormat(getNowDate(), CHS_DATEFORMAT); Calendar c = Calendar.getInstance(); for (int i = 0; i < 8; i++) { c.add(Calendar.DAY_OF_MONTH, 1); @SuppressWarnings("unused") int e = c.get(Calendar.DAY_OF_WEEK); }//from w w w.ja v a 2 s .c o m result += " "; switch (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: return result + ""; case Calendar.MONDAY: return result + ""; case Calendar.TUESDAY: return result + ""; case Calendar.WEDNESDAY: return result + ""; case Calendar.THURSDAY: return result + ""; case Calendar.FRIDAY: return result + ""; case Calendar.SATURDAY: return result + ""; default: return result; } }
From source file:com.project.framework.util.DateUtils.java
/** * ??(?)// w w w . j av a2 s . c o m * * @param date ? * @return Date ?? */ public static Date getAfterTrad(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); do { calendar.roll(Calendar.DATE, true); } while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7); return calendar.getTime(); }
From source file:JobScheduler.java
public void executeAtNextDOW(Runnable job, Date when, int DOW) { Calendar target = Calendar.getInstance(); target.setTime(when);/*from w ww.j a v a 2s.co m*/ while (target.get(Calendar.DAY_OF_WEEK) != DOW) target.add(Calendar.DATE, 1); executeAt(job, target.getTime()); }