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:com.haulmont.timesheets.entity.WeeklyReportEntry.java
public void addTimeEntry(TimeEntry timeEntry) { int dayNumber = DateUtils.toCalendar(timeEntry.getDate()).get(Calendar.DAY_OF_WEEK); DayOfWeek day = DayOfWeek.fromCalendarDay(dayNumber); List<TimeEntry> timeEntries = getDayOfWeekTimeEntries(day); if (timeEntries == null) { List<TimeEntry> list = new ArrayList<>(); list.add(timeEntry);/*from w w w. j ava 2s.c om*/ changeDayOfWeekTimeEntries(day, list); } else { timeEntries.add(timeEntry); } }
From source file:onl.netfishers.netshot.work.Task.java
/** * Gets the next execution date./*from w ww. jav a 2 s . co m*/ * * @return the next execution date */ @Transient @XmlElement public Date getNextExecutionDate() { Calendar reference = Calendar.getInstance(); reference.setTime(this.scheduleReference); Calendar target = Calendar.getInstance(); Calendar inOneMinute = Calendar.getInstance(); inOneMinute.add(Calendar.MINUTE, 1); switch (this.scheduleType) { case AT: return this.scheduleReference; case DAILY: target.set(Calendar.HOUR_OF_DAY, reference.get(Calendar.HOUR_OF_DAY)); target.set(Calendar.MINUTE, reference.get(Calendar.MINUTE)); target.set(Calendar.SECOND, reference.get(Calendar.SECOND)); target.set(Calendar.MILLISECOND, 0); if (target.before(inOneMinute)) { target.add(Calendar.DAY_OF_MONTH, 1); } return target.getTime(); case WEEKLY: target.set(Calendar.HOUR_OF_DAY, reference.get(Calendar.HOUR_OF_DAY)); target.set(Calendar.MINUTE, reference.get(Calendar.MINUTE)); target.set(Calendar.SECOND, reference.get(Calendar.SECOND)); target.set(Calendar.MILLISECOND, 0); target.set(Calendar.DAY_OF_WEEK, reference.get(Calendar.DAY_OF_WEEK)); if (target.before(inOneMinute)) { target.add(Calendar.WEEK_OF_YEAR, 1); } return target.getTime(); case MONTHLY: target.set(Calendar.HOUR_OF_DAY, reference.get(Calendar.HOUR_OF_DAY)); target.set(Calendar.MINUTE, reference.get(Calendar.MINUTE)); target.set(Calendar.SECOND, reference.get(Calendar.SECOND)); target.set(Calendar.MILLISECOND, 0); target.set(Calendar.DAY_OF_MONTH, reference.get(Calendar.DAY_OF_MONTH)); if (target.before(inOneMinute)) { target.add(Calendar.MONTH, 1); } return target.getTime(); case ASAP: default: return null; } }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSourceTestCase.java
private JFreeChartTimeSeriesGraphSource getComplexGraph() throws GraphException { Calendar base = Calendar.getInstance(); base.set(Calendar.WEEK_OF_YEAR, 6); Random r = new Random(); List<TimePoint> ps1 = new LinkedList<TimePoint>(); List<TimePoint> ps2 = new LinkedList<TimePoint>(); List<TimePoint> ps3 = new LinkedList<TimePoint>(); for (int count = 0; count < 4; count += 1) { base.set(Calendar.DAY_OF_WEEK, 2); addPoint(base.getTime(), ps2, r); // now generate five points for ps1 and p23, the daily sets addPoint(base.getTime(), ps1, r); addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=0", null); for (int i = 1; i < 5; i += 1) { base.add(Calendar.DAY_OF_WEEK, 1); addPoint(base.getTime(), ps1, r); addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=" + i, null); }//from ww w . j a va2 s . c o m base.set(Calendar.DAY_OF_WEEK, 1); base.add(Calendar.WEEK_OF_YEAR, 1); } List<DefaultTimeSeries> series = new LinkedList<DefaultTimeSeries>(); Map<String, Object> s1Md = new HashMap<String, Object>(); s1Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); s1Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-5, -5, 10, 10)); s1Md.put(GraphSource.SERIES_TITLE, "Frederick County Counts"); series.add(new DefaultTimeSeries(ps1, s1Md)); Map<String, Object> s2Md = new HashMap<String, Object>(); s2Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); s2Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-7, -7, 14, 14)); s2Md.put(GraphSource.SERIES_TITLE, "NCR Counts"); series.add(new DefaultTimeSeries(ps2, s2Md)); Map<String, Object> s3Md = new HashMap<String, Object>(); s3Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); s3Md.put(GraphSource.SERIES_SHAPE, new Rectangle2D.Float(-3, -3, 6, 6)); s3Md.put(GraphSource.SERIES_TITLE, "Carroll County Counts"); series.add(new DefaultTimeSeries(ps3, s3Md)); Map<String, Object> params = new HashMap<String, Object>(); params.put(GraphSource.BACKGROUND_COLOR, Color.BLUE); params.put(GraphSource.GRAPH_TITLE, "Counts"); params.put(GraphSource.GRAPH_X_LABEL, "Time"); params.put(GraphSource.GRAPH_Y_LABEL, "Total Counts"); return new JFreeChartTimeSeriesGraphSource(series, params); }
From source file:com.example.android.expandingcells.ExpandingCells.java
public void getRaghukalam() { // Raahu Kaalam for today Calendar c = Calendar.getInstance(); Integer dayOfWeek = c.get(Calendar.DAY_OF_WEEK); Log.d("DEBUG", "Today is" + dayOfWeek.toString()); Raghukalam = "Raahu Kaalam: " + CommonLib.raahuKaalam(dayOfWeek); Raghu_Image = "drawable://" + R.drawable.mb_raghukalam; //todoAdapter.add("Raahu Kaalam: " + CommonLib.raahuKaalam(dayOfWeek)); //itemList.add(new Bytes(Raghu_Image,"Raghu Kalam", Raghukalam)); NewsList.get(2).setNews(Raghu_Image, "Raghukalam", Raghukalam); }
From source file:de.ribeiro.android.gso.core.UntisProvider.java
private static ICalEvent GetSchulstunde(WeekData wd, int day, int hour) { for (ICalEvent event : wd.events) { if (event.DTSTART.get(Calendar.DAY_OF_WEEK) == day) { if (GetSchulstundeOfEvent(event) == hour) return event; }/* ww w . j av a2 s .c o m*/ } return null; }
From source file:com.feilong.core.date.DateUtil.java
/** * date <span style="color:red"> ()</span> <code>00:00:00.000</code> . * // ww w . ja va 2s . co m * <pre class="code"> * DateUtil.getFirstDateOfThisWeek(2012-10-11 17:10:30.701) =2012-10-07 00:00:00.000 * DateUtil.getFirstDateOfThisWeek(2014-01-01 05:00:00) =2013-12-29 00:00:00.000 // * </pre> * * <h3>?:</h3> * <blockquote> * <ol> * <li>,<span style="color:red">,?</span></li> * <li>,?</li> * </ol> * </blockquote> * * @param date * ? * @return <code>date</code> null, {@link NullPointerException} * @see #toCalendar(Date) * @see Calendar#set(int, int) * @see CalendarUtil#resetDayBegin(Calendar) * @see Calendar#getTime() */ public static Date getFirstDateOfThisWeek(Date date) { Calendar calendar = toCalendar(date); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); return CalendarUtil.toDate(CalendarUtil.resetDayBegin(calendar)); }
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java
/** * @param infoExam/*from ww w. j av a 2 s.c o m*/ * @return */ private boolean atValidHour(InfoExam infoExam) { int curricularYear = infoExam.getInfoExecutionCourse().getCurricularYear().intValue(); int beginning = infoExam.getBeginning().get(Calendar.HOUR_OF_DAY); int weekDay = infoExam.getDay().get(Calendar.DAY_OF_WEEK); return ((curricularYear == 1 || curricularYear == 2) && (beginning == 9)) || (curricularYear == 3 && beginning == 17) || (curricularYear == 4 && (((weekDay == Calendar.TUESDAY || weekDay == Calendar.THURSDAY) && beginning == 17) || (weekDay == Calendar.SATURDAY && beginning == 9))) || (curricularYear == 5 && beginning == 13); }
From source file:edu.harvard.iq.dvn.core.harvest.HarvesterServiceBean.java
private void createHarvestTimer(HarvestingDataverse dataverse) { if (dataverse.isScheduled()) { long intervalDuration = 0; Calendar initExpiration = Calendar.getInstance(); initExpiration.set(Calendar.MINUTE, 0); initExpiration.set(Calendar.SECOND, 0); if (dataverse.getSchedulePeriod().equals(dataverse.SCHEDULE_PERIOD_DAILY)) { intervalDuration = 1000 * 60 * 60 * 24; initExpiration.set(Calendar.HOUR_OF_DAY, dataverse.getScheduleHourOfDay()); } else if (dataverse.getSchedulePeriod().equals(dataverse.SCHEDULE_PERIOD_WEEKLY)) { intervalDuration = 1000 * 60 * 60 * 24 * 7; initExpiration.set(Calendar.HOUR_OF_DAY, dataverse.getScheduleHourOfDay()); initExpiration.set(Calendar.DAY_OF_WEEK, dataverse.getScheduleDayOfWeek()); } else {/*from w ww. j a v a2 s.c o m*/ logger.log(Level.WARNING, "Could not set timer for dataverse id, " + dataverse.getId() + ", unknown schedule period: " + dataverse.getSchedulePeriod()); return; } Date initExpirationDate = initExpiration.getTime(); Date currTime = new Date(); if (initExpirationDate.before(currTime)) { initExpirationDate.setTime(initExpiration.getTimeInMillis() + intervalDuration); } logger.log(Level.INFO, "Setting timer for dataverse " + dataverse.getVdc().getName() + ", initial expiration: " + initExpirationDate); // timerService.createTimer(initExpirationDate, intervalDuration, new HarvestTimerInfo(dataverse.getId(), dataverse.getVdc().getName(), dataverse.getSchedulePeriod(), dataverse.getScheduleHourOfDay(), dataverse.getScheduleDayOfWeek())); dvnTimerService.createTimer(initExpirationDate, intervalDuration, new HarvestTimerInfo(dataverse.getId(), dataverse.getVdc().getName(), dataverse.getSchedulePeriod(), dataverse.getScheduleHourOfDay(), dataverse.getScheduleDayOfWeek())); } }
From source file:CalendarUtilsTest.java
/** * Tests the calendar iterator for week ranges *///from w w w . j a v a 2 s. c o m public void testWeekIterator() throws Exception { Calendar now = Calendar.getInstance(); Calendar today = CalendarUtils.trunc(now, Calendar.DATE); Calendar sunday = CalendarUtils.trunc(now, Calendar.DATE); sunday.add(Calendar.DATE, 1 - sunday.get(Calendar.DAY_OF_WEEK)); Calendar monday = CalendarUtils.trunc(now, Calendar.DATE); if (monday.get(Calendar.DATE) == 1) { //This is sunday... roll back 6 days monday.add(Calendar.DATE, -6); } else { monday.add(Calendar.DATE, 2 - monday.get(Calendar.DAY_OF_WEEK)); } Calendar centered = CalendarUtils.trunc(now, Calendar.DATE); centered.add(Calendar.DATE, -3); Iterator it = CalendarUtils.getCalendarIterator(now, CalendarUtils.RANGE_WEEK_SUNDAY); assertWeekIterator(it, sunday); it = CalendarUtils.getCalendarIterator(now, CalendarUtils.RANGE_WEEK_MONDAY); assertWeekIterator(it, monday); it = CalendarUtils.getCalendarIterator(now, CalendarUtils.RANGE_WEEK_RELATIVE); assertWeekIterator(it, today); it = CalendarUtils.getCalendarIterator(now, CalendarUtils.RANGE_WEEK_CENTER); assertWeekIterator(it, centered); }
From source file:egovframework.oe1.cms.com.web.EgovOe1CalRestdeManageController.java
/** * ? //from w w w.java 2 s.co m * @param restde * @param model * @return "/cmm/sym/cal/EgovNormalWeekCalendar" * @throws Exception */ @RequestMapping(value = "/com/EgovNormalWeekCalendar.do") public String selectNormalWeekCalendar(EgovOe1Restde restde, ModelMap model) throws Exception { Calendar cal = Calendar.getInstance(); if (restde.getYear() == null || restde.getYear().equals("")) { restde.setYear(Integer.toString(cal.get(Calendar.YEAR))); } if (restde.getMonth() == null || restde.getMonth().equals("")) { restde.setMonth(Integer.toString(cal.get(Calendar.MONTH) + 1)); } if (restde.getDay() == null || restde.getDay().equals("")) { restde.setDay(Integer.toString(cal.get(Calendar.DATE))); } int iYear = Integer.parseInt(restde.getYear()); int iMonth = Integer.parseInt(restde.getMonth()); if (iMonth < 1) { iYear--; iMonth = 12; } if (iMonth > 12) { iYear++; iMonth = 1; } if (iYear < 1) { iYear = 1; iMonth = 1; } if (iYear > 9999) { iYear = 9999; iMonth = 12; } restde.setYear(Integer.toString(iYear)); restde.setMonth(Integer.toString(iMonth)); cal.set(iYear, iMonth - 1, 1); restde.setStartWeekMonth(cal.get(Calendar.DAY_OF_WEEK)); cal.set(iYear, iMonth - 1, Integer.parseInt(restde.getDay())); restde.setLastDayMonth(cal.getActualMaximum(Calendar.DAY_OF_MONTH)); int iStartWeek = restde.getStartWeekMonth(); int iLastDate = restde.getLastDayMonth(); int iDayWeek = cal.get(Calendar.DAY_OF_WEEK); int iMaxWeeks = (int) Math.floor(iLastDate / 7); iMaxWeeks = iMaxWeeks + (int) Math.ceil(((iLastDate - iMaxWeeks * 7) + iStartWeek - 1) / 7.0); restde.setMaxWeeks(iMaxWeeks); if (iMaxWeeks < restde.getWeeks()) { restde.setWeeks(iMaxWeeks); } EgovOe1Restde vo = new EgovOe1Restde(); Calendar weekCal = Calendar.getInstance(); weekCal.setTime(cal.getTime()); if (restde.getWeeks() != 0) { weekCal.set(weekCal.DATE, (restde.getWeeks() - 1) * 7 + 1); if (restde.getWeeks() > 1) { iDayWeek = weekCal.get(weekCal.DAY_OF_WEEK); weekCal.add(weekCal.DATE, (-1) * (iDayWeek - 1)); } restde.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH) + 1)); } iDayWeek = weekCal.get(weekCal.DAY_OF_WEEK); // ?? weekCal.add(weekCal.DATE, (-1) * (iDayWeek - 1)); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_1 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_1 = restdeManageService.selectNormalDayRestde(vo); // ? weekCal.add(weekCal.DATE, 1); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_2 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_2 = restdeManageService.selectNormalDayRestde(vo); // ? weekCal.add(weekCal.DATE, 1); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_3 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_3 = restdeManageService.selectNormalDayRestde(vo); // ? weekCal.add(weekCal.DATE, 1); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_4 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_4 = restdeManageService.selectNormalDayRestde(vo); // ? weekCal.add(weekCal.DATE, 1); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_5 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_5 = restdeManageService.selectNormalDayRestde(vo); // ? weekCal.add(weekCal.DATE, 1); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_6 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_6 = restdeManageService.selectNormalDayRestde(vo); // ? weekCal.add(weekCal.DATE, 1); vo.setYear(Integer.toString(weekCal.get(weekCal.YEAR))); vo.setMonth(Integer.toString(weekCal.get(weekCal.MONTH) + 1)); vo.setDay(Integer.toString(weekCal.get(weekCal.DAY_OF_MONTH))); vo.setWeek(weekCal.get(weekCal.DAY_OF_WEEK)); List CalInfoList_7 = restdeManageService.selectNormalDayCal(vo); List NormalWeekRestdeList_7 = restdeManageService.selectNormalDayRestde(vo); model.addAttribute("resultList_1", CalInfoList_1); model.addAttribute("resultList_2", CalInfoList_2); model.addAttribute("resultList_3", CalInfoList_3); model.addAttribute("resultList_4", CalInfoList_4); model.addAttribute("resultList_5", CalInfoList_5); model.addAttribute("resultList_6", CalInfoList_6); model.addAttribute("resultList_7", CalInfoList_7); model.addAttribute("RestdeList_1", NormalWeekRestdeList_1); model.addAttribute("RestdeList_2", NormalWeekRestdeList_2); model.addAttribute("RestdeList_3", NormalWeekRestdeList_3); model.addAttribute("RestdeList_4", NormalWeekRestdeList_4); model.addAttribute("RestdeList_5", NormalWeekRestdeList_5); model.addAttribute("RestdeList_6", NormalWeekRestdeList_6); model.addAttribute("RestdeList_7", NormalWeekRestdeList_7); List CalInfoList = restdeManageService.selectNormalDayCal(restde); model.addAttribute("resultList", CalInfoList); return "/cms/com/EgovNormalWeekCalendar"; }