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.surevine.alfresco.repo.action.delete.DeleteActionJob.java
/** * Separated into a separate method to allow for optimisation etc. * @return//from ww w . j a v a 2 s .c o m */ protected String assembleLuceneQuery() { final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); // Attempt to delete items that have previously failed to delete if the // day of the week is a saturday and it's between midnight and 1am. if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && calendar.get(Calendar.HOUR_OF_DAY) == 0) { if (_logger.isDebugEnabled()) { _logger.debug("Not filtering items that have failed to delete."); } return _itemsToDeleteQuery; } else { if (_logger.isDebugEnabled()) { _logger.debug("Filtering items that have failed to delete."); } return _itemsToDeleteFilterFailedQuery; } }
From source file:TimePeriod.java
/** * Setzt den bis-Wert auf einen der Standard-Typen * /*from w w w .j a va 2 s. c om*/ * @param neuertyp */ public void setToTyp(int neuertyp) { this.to_typ = neuertyp; if (from_typ != to_typ) typ = -1; else typ = neuertyp; switch (neuertyp) { case TODAY: to = new GregorianCalendar(); set2359(to); break; case YESTERDAY: to = new GregorianCalendar(); set2359(to); to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY); break; case THIS_WEEK: to = new GregorianCalendar(); int day_of_week = to.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week == 1) { day_offset_von = -6; } else { day_offset_von = 2 - day_of_week; } // bis ist logischerweise 6-Tage nach von int day_offset_bis = day_offset_von + 6; set2359(to); to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis); break; case LAST_WEEK: // wie diese woche, nur 7 tage weiter zurck to = new GregorianCalendar(); int day_of_week2 = to.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von2; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week2 == 1) { day_offset_von2 = -13; } else { day_offset_von2 = -5 - day_of_week2; } // bis ist logischerweise 6-Tage nach von int day_offset_bis2 = day_offset_von2 + 6; set2359(to); to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis2); break; case THIS_MONTH: GregorianCalendar temp = new GregorianCalendar(); setMidnight(temp); temp.set(Calendar.DAY_OF_MONTH, 1); to = new GregorianCalendar(); set2359(to); // wann der letzte tag im monat ist ist unklar, also solange weiter // gehen, // bis der neue monat anfngt, dann einen tag zurck while (to.get(Calendar.MONTH) == temp.get(Calendar.MONTH)) to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY); // Jetzt wieder einen tag zurck to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY); break; case LAST_MONTH: GregorianCalendar temp2 = new GregorianCalendar(); setMidnight(temp2); temp2.set(Calendar.DAY_OF_MONTH, 1); // der erste tag des letzten Monats ist vielleicht nicht mehr in // diesem Jahr, also // rckwrts laufen, bis wieder ein erster Tag gefunden wird temp2.setTimeInMillis(temp2.getTimeInMillis() - ONE_DAY); to = new GregorianCalendar(); to.setTimeInMillis(temp2.getTimeInMillis()); set2359(to); break; case THIS_JEAR: to = new GregorianCalendar(); set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); break; case LAST_JEAR: to = new GregorianCalendar(); int jahr = to.get(Calendar.YEAR); jahr--; set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); to.set(Calendar.YEAR, jahr); break; case EVER: to = new GregorianCalendar(); int jahr2 = to.get(Calendar.YEAR); set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); to.set(Calendar.YEAR, jahr2); break; } // Von darf nicht nach bis liegen, ist bis schon initialisiert, so muss // es angepasst werden if (from != null) if (to.before(from)) { from.setTimeInMillis(to.getTimeInMillis()); setMidnight(from); from_typ = to_typ; } }
From source file:egovframework.oe1.cms.com.web.EgovOe1CalRestdeManageController.java
/** * ? ?//from w w w . j av a2 s . co m * @param restde * @param model * @return "/cmm/sym/cal/EgovNormalDayCalendar" * @throws Exception */ @RequestMapping(value = "/com/EgovNormalDayCalendar.do") public String selectNormalDayCalendar(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()); int iDay = Integer.parseInt(restde.getDay()); 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, iDay); 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)); restde.setYear(Integer.toString(cal.get(cal.YEAR))); restde.setMonth(Integer.toString(cal.get(cal.MONTH) + 1)); restde.setDay(Integer.toString(cal.get(cal.DAY_OF_MONTH))); restde.setWeek(cal.get(cal.DAY_OF_WEEK)); restde.setLastDayMonth(cal.getActualMaximum(Calendar.DATE)); List CalInfoList = restdeManageService.selectNormalDayCal(restde); List NormalWeekRestdeList = restdeManageService.selectNormalDayRestde(restde); model.addAttribute("resultList", CalInfoList); model.addAttribute("RestdeList", NormalWeekRestdeList); return "/cms/com/EgovNormalDayCalendar"; }
From source file:com.glaf.core.util.DateUtils.java
/** * // www.j a va 2 s. c o m * * @param date * @return */ public static Calendar getNextMonday(Calendar date) { Calendar result = date; do { result = (Calendar) result.clone(); result.add(Calendar.DATE, 1); } while (result.get(Calendar.DAY_OF_WEEK) != 2); return result; }
From source file:com.project.framework.util.DateUtils.java
/** * ??(?)// ww w . ja v a 2s .c o m * * @param date ? * @return Date ?? */ public static Date getMonthLastTrad(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(getMonthLastDay(date)); while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7) { calendar.roll(Calendar.DATE, false); } return calendar.getTime(); }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
/** * Day of year.//ww w.j av a2 s .c om * * @param year * the year * @param month * the month * @param dayOfWeek * the day of week * @param weekInMonth * the week in month * @return the day of the year */ private int dayOfYear(int year, int month, int dayOfWeek, int weekInMonth) { Calendar holiday = now(); holiday.set(Calendar.YEAR, year); holiday.set(Calendar.MONTH, month); holiday.set(Calendar.DAY_OF_WEEK, dayOfWeek); holiday.set(Calendar.DAY_OF_WEEK_IN_MONTH, weekInMonth); return holiday.get(Calendar.DAY_OF_YEAR); }
From source file:net.granoeste.commons.util.DateUtils.java
/** * ???/*w w w . j a v a2s.co m*/ * * @param cal * @param amount ex) last week : -1. the current week : 0. the next week : 1 */ public static void shiftDateOnMondayOfTheWeek(final Calendar cal, final int amount) { cal.add(Calendar.WEEK_OF_YEAR, amount); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { cal.add(Calendar.DATE, -6); } else { cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 2); } }
From source file:net.rrm.ehour.ui.timesheet.panel.TimesheetRowList.java
private void addInputCells(ListItem<TimesheetRow> item, final TimesheetRow row) { Calendar currentDate = (Calendar) row.getFirstDayOfWeekDate().clone(); ProjectAssignment assignment = row.getProjectAssignment(); final DateRange range = new DateRange(assignment.getDateStart(), assignment.getDateEnd()); final List<Calendar> dates = Lists.newArrayList(); for (int i = 1; i <= 7; i++, currentDate.add(Calendar.DAY_OF_YEAR, 1)) { dates.add((Calendar) currentDate.clone()); }// w w w . j av a2 s . co m item.add(new ListView<Calendar>("days", dates) { @Override protected void populateItem(ListItem<Calendar> item) { Calendar currentDate = item.getModelObject(); int index = currentDate.get(Calendar.DAY_OF_WEEK) - 1; TimesheetCell timesheetCell = row.getTimesheetCells()[index]; DayStatus dayStatus = determineDayStatus(timesheetCell, currentDate, range); Component day; switch (dayStatus) { case HIDDEN: default: day = createEmptyTimesheetEntry(DAY_ID); item.add(new WebMarkupContainer(DAY_OPTIONS_ID)); break; case OPEN: day = createInputTimesheetEntry(DAY_ID, row, index); item.add(renderOptions(DAY_OPTIONS_ID, timesheetCell, dayStatus)); break; case LOCKED: day = createLockedTimesheetEntry(DAY_ID, row, index); item.add(renderOptions(DAY_OPTIONS_ID, timesheetCell, dayStatus)); item.add(AttributeModifier.append("class", "locked")); break; } String cssClass = "weekday"; if (dayStatus == DayStatus.LOCKED) { cssClass += " lockedCell"; } else if (item.getIndex() == 0) { cssClass = "sunday"; } else if (item.getIndex() == 6) { cssClass = "saturday"; } day.add(AttributeModifier.replace("class", cssClass)); item.add(day); } }); }
From source file:edu.jhuapl.openessence.web.util.Filters.java
private Date muckDate(Date date, int prepull, String resolution, int calWeekStartDay) { GregorianCalendar x = new GregorianCalendar(); x.setTime(date);/*from w ww . j ava 2 s .c o m*/ if (resolution != null && resolution.equals("weekly")) { x.add(Calendar.DATE, (-7 * prepull)); // make sure week starts on week start day defined // in message.properties or datasource groovy file while (x.get(Calendar.DAY_OF_WEEK) != calWeekStartDay) { x.add(Calendar.DATE, -1); } } else if (resolution != null && resolution.equals("monthly")) { x.set(Calendar.DAY_OF_MONTH, 1); } else if (resolution != null && resolution.equals("daily")) { x.add(Calendar.DATE, -prepull); } return x.getTime(); }
From source file:com.stratelia.webactiv.util.DateUtilTest.java
@Test public void testAddDays() { Calendar calend = Calendar.getInstance(); calend.set(Calendar.DATE, 27); calend.set(Calendar.MONTH, Calendar.JUNE); calend.set(Calendar.YEAR, 2012); calend.setTimeZone(TimeZone.getTimeZone("GMT+01")); assertThat(calend.get(Calendar.DAY_OF_WEEK), is(Calendar.WEDNESDAY)); DateUtil.addDaysExceptWeekEnds(calend, 2); assertThat(calend.get(Calendar.DAY_OF_WEEK), is(Calendar.FRIDAY)); assertThat(calend.get(Calendar.DATE), is(29)); assertThat(calend.get(Calendar.MONTH), is(Calendar.JUNE)); assertThat(calend.get(Calendar.YEAR), is(2012)); calend = Calendar.getInstance(); calend.set(Calendar.DATE, 27); calend.set(Calendar.MONTH, Calendar.JUNE); calend.set(Calendar.YEAR, 2012); calend.setTimeZone(TimeZone.getTimeZone("GMT+01")); assertThat(calend.get(Calendar.DAY_OF_WEEK), is(Calendar.WEDNESDAY)); DateUtil.addDaysExceptWeekEnds(calend, 4); assertThat(calend.get(Calendar.DAY_OF_WEEK), is(Calendar.TUESDAY)); assertThat(calend.get(Calendar.DATE), is(3)); assertThat(calend.get(Calendar.MONTH), is(Calendar.JULY)); assertThat(calend.get(Calendar.YEAR), is(2012)); }