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.project.framework.util.DateUtils.java
/** * ??(?)/* w ww .jav a2s . c o m*/ * * @param date ? * @return Date ?? */ public static Date getMonthFirstTrad(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(getMonthFistDay(date)); while (calendar.get(Calendar.DAY_OF_WEEK) == 1 || calendar.get(Calendar.DAY_OF_WEEK) == 7) { calendar.roll(Calendar.DATE, true); } return calendar.getTime(); }
From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeDate.java
@Override public byte[] encodeInt(Object data) throws EBusTypeException { IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD); IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD); IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR); Calendar calendar = null;/*from w w w . ja v a2 s . c o m*/ byte[] result = new byte[this.getTypeLength()]; if (data instanceof EBusDateTime) { calendar = ((EBusDateTime) data).getCalendar(); } else if (data instanceof Calendar) { calendar = (Calendar) data; } // set date to midnight calendar = (Calendar) calendar.clone(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); if (calendar != null) { if (StringUtils.equals(variant, DEFAULT)) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(dayOfWeek)[0], bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, SHORT)) { result = new byte[] { bcdType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], bcdType.encode(calendar.get(Calendar.MONTH) + 1)[0], bcdType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, HEX)) { int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(dayOfWeek)[0], charType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, HEX_SHORT)) { result = new byte[] { charType.encode(calendar.get(Calendar.DAY_OF_MONTH))[0], charType.encode(calendar.get(Calendar.MONTH) + 1)[0], charType.encode(calendar.get(Calendar.YEAR) % 100)[0] }; } else if (StringUtils.equals(variant, DAYS)) { long millis = calendar.getTimeInMillis(); calendar.clear(); calendar.set(1900, 0, 1, 0, 0); long millis1900 = calendar.getTimeInMillis(); BigDecimal days = new BigDecimal(millis - millis1900); days = days.divide(BigDecimal.valueOf(86400000), 0, RoundingMode.HALF_UP); result = wordType.encode(days); } } return result; }
From source file:CalIcon.java
/** paintIcon: draw the calendar page. */ public void paintIcon(Component c, Graphics g, int x, int y) { // Allow clock to get painted (voodoo magic) if (showTime) super.paint(g); // Outline it. g.setColor(Color.black);/*from w w w . j a va 2 s . com*/ g.draw3DRect(x, y, d.width - 2, d.height - 2, true); // Show the date: First, a white page with a drop shadow. g.setColor(Color.gray); g.fillRect(x + RBX + 3, y + RBY + 3, RBW, RBH); g.setColor(Color.white); g.fillRect(x + RBX, y + RBY, RBW, RBH); // g.setColor(getForeground()); g.setColor(Color.black); String s = days[myCal.get(Calendar.DAY_OF_WEEK) - 1]; g.setFont(dayNameFont); int w = dayNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 10); s = Integer.toString(myCal.get(Calendar.DAY_OF_MONTH)); g.setFont(dayNumbFont); w = dayNumbFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 25); s = mons[myCal.get(Calendar.MONTH)]; g.setFont(monNameFont); w = monNameFM.stringWidth(s); g.drawString(s, x + RBX + ((RBW - w) / 2), y + RBY + 35); }
From source file:com.lk.ofo.util.DateUtil.java
/** * ?/*from ww w .ja v a 2 s . c o m*/ * * @param date * @return */ public static Integer getWeekdayNumber(Date date) { try { Calendar cal = Calendar.getInstance(); cal.setTime(date); Integer w = cal.get(Calendar.DAY_OF_WEEK) - 1; if (w < 0) { w = 0; } return w; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:br.com.transport.report.ManagerReportBean.java
/** * Retorna o ultimo dia da semana// w w w . jav a 2s.co m * @return */ private Calendar getLastCalendar() { Calendar end = GregorianCalendar.getInstance(); end.setFirstDayOfWeek(Calendar.SUNDAY); end.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); end.set(Calendar.HOUR_OF_DAY, 23); end.set(Calendar.MINUTE, 59); end.set(Calendar.SECOND, 59); end.setTime(end.getTime()); return end; }
From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java
private void writeDays(FacesContext facesContext, ResponseWriter writer, HtmlOcupationCalendar inputComponent, Calendar timeKeeper, int currentDay, int weekStartsAtDayIndex, int weekDayOfFirstDayOfMonth, int lastDayInMonth, String[] weekdays) throws IOException { if (log.isDebugEnabled()) { log.debug("writeDays - currentDay=\"" + currentDay + "\", weekDayOfFirstDayOfMonth=\"" + weekDayOfFirstDayOfMonth + "\", lastDayInMonth=\"" + lastDayInMonth + "\", weekdays=\"" + Arrays.toString(weekdays) + "\"."); }/*from ww w. j av a2s. c om*/ OcupationModel ocupation = inputComponent.getOcupation(); Calendar cal; int space = (weekStartsAtDayIndex < weekDayOfFirstDayOfMonth) ? (weekDayOfFirstDayOfMonth - weekStartsAtDayIndex) : (weekdays.length - weekStartsAtDayIndex + weekDayOfFirstDayOfMonth); if (space == weekdays.length) space = 0; int extraDays = 0; try { extraDays = Integer.valueOf(inputComponent.getExtraDays()).intValue(); } catch (NumberFormatException e) { // nothing to do } for (int i = 0 - extraDays; i < lastDayInMonth + extraDays; i++) { cal = copyCalendar(facesContext, timeKeeper); cal.set(Calendar.DAY_OF_MONTH, i + 1); int dayofweek = cal.get(Calendar.DAY_OF_WEEK); String cellStyle = inputComponent.getDayCellClass(); StringBuilder description = new StringBuilder(); // checking for vacations days Collection<OcupationEntry> entries = ocupation.getOcupationEntries(cal.getTime()); if (i < 0 || i >= lastDayInMonth) { cellStyle = inputComponent.getExtraDaysCellClass(); } if (entries != null && entries.size() > 0) { int performedHours = 0; int aEntryIsVacations = 0; for (OcupationEntry entry : entries) { performedHours += entry.getDuration(); if (entry.isVacances()) { aEntryIsVacations = 1; } else if (entry.isHoliday()) { aEntryIsVacations = 2; } description.append("[" + entry.getDescription() + "]"); } if (aEntryIsVacations == 1) { cellStyle = inputComponent.getVacancesCellClass(); } else if (aEntryIsVacations == 2) { cellStyle = inputComponent.getWeekEndCellClass(); } else { if (performedHours >= Integer.valueOf(inputComponent.getWorkingDayHours()).intValue()) { cellStyle = inputComponent.getFullWorkCellClass(); } else { cellStyle = inputComponent.getPartialWorkCellClass(); } } } else { description = null; } // week-end days if (dayofweek == 1 || dayofweek == 7) { description = new StringBuilder("Fin de semana"); cellStyle = inputComponent.getWeekEndCellClass(); } writeCell(facesContext, writer, inputComponent, String.valueOf(cal.get(Calendar.DAY_OF_MONTH)), null, cellStyle, description == null ? null : description.toString()); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Set the view to WEEK.//ww w. ja v a 2 s .c om */ private void setWeekView() { actualStart = (GregorianCalendar) actualDay.clone(); actualStart.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); actualStart.set(Calendar.HOUR_OF_DAY, 0); actualStart.set(Calendar.MINUTE, 0); actualEnd = (GregorianCalendar) actualDay.clone(); actualEnd.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); actualEnd.set(Calendar.HOUR_OF_DAY, 23); actualEnd.set(Calendar.MINUTE, 59); actualStart.add(Calendar.HOUR_OF_DAY, -1); actualEnd.add(Calendar.HOUR_OF_DAY, 1); actualView = WEEK; GregorianCalendar helper = (GregorianCalendar) actualEnd.clone(); helper.add(Calendar.DATE, -1); makeChart(LocalizedStrings.getGeneralStrings().calendarWeekAbbreviation() + " " + new SimpleDateFormat("ww yyyy").format(helper.getTime())); }
From source file:com.clustercontrol.calendar.composite.CalendarWeekComposite.java
/** * ?<BR>//from ww w. j ava2 s .co m * * @since 4.1.0 */ public void update(String managerName, String calendarId, int year, int month, int day) { if (calendarId == null) { return; } // ??? createPanel(); int period = 7; //?? Calendar now = Calendar.getInstance(TimezoneUtil.getTimeZone()); now.set(year, month - 1, day); int dayOfWeek = now.get(Calendar.DAY_OF_WEEK); m_panel.repaint(); // Sometimes labels disappear in RAP. Repaint to make sure labels show it //?(???) scheduleBars = createScheduleBars(m_panel, dayOfWeek); //??? for (ScheduleBar bar : scheduleBars) { bar.getInitBar().setBackgroundColor(ColorConstantsWrapper.red()); } try { for (int i = 0; i < period; i++) { //????? CalendarEndpointWrapper wrapper = CalendarEndpointWrapper.getWrapper(managerName); List<CalendarDetailInfo> detailList = wrapper.getCalendarWeek(calendarId, year, month, day); m_log.trace("detailList.size=" + detailList.size() + ", " + year + "/" + month + "/" + day); //???????? ArrayList<CalendarDetailInfo> detailListOrder = new ArrayList<CalendarDetailInfo>(); while (detailList.size() > 0) { int size = detailList.size(); detailListOrder.add(detailList.get(size - 1)); detailList.remove(size - 1); } for (CalendarDetailInfo detail : detailListOrder) { addScheduleBar(m_panel, dayOfWeek, detail.getTimeFrom(), detail.getTimeTo(), detail.isOperateFlg()); } // m_labelMatrix[i].setText(String.format("%02d/%02d/%02d", year, month, day) + " ( " + DayOfWeekConstant.typeToString(dayOfWeek) + " )"); //?? if (day + 1 > now.getActualMaximum(Calendar.DAY_OF_MONTH)) { //?? if (month == 12) { year++; month = 1; } else { month++; } day = 1; } else { day++; } //??? now.set(year, month - 1, day); dayOfWeek = now.get(Calendar.DAY_OF_WEEK); } } catch (InvalidRole_Exception e) { // ??? MessageDialog.openInformation(null, Messages.getString("message"), Messages.getString("message.accesscontrol.16")); } catch (CalendarNotFound_Exception e) { // ???????? m_log.info("update(), " + HinemosMessage.replace(e.getMessage())); } catch (Exception e) { // ? m_log.warn("update(), " + HinemosMessage.replace(e.getMessage()), e); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.hinemos.failure.unexpected") + ", " + HinemosMessage.replace(e.getMessage())); } //? if (calendarId.length() > 0) { m_labelId.setText(Messages.getString("calendar.id") + " : " + calendarId); } else { m_labelId.setText(Messages.getString("calendar.id") + " : "); } }
From source file:org.callistasoftware.netcare.core.job.SystemAlarmJob.java
@Scheduled(fixedRate = 3600000) public void alarmJob() { log.info("======== ALARM JOB STARTED ========="); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -(HealthPlanServiceImpl.SCHEMA_HISTORY_DAYS)); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); cal.add(Calendar.DATE, -1);/* w ww. ja v a 2 s.com*/ ApiUtil.dayEnd(cal); /* * Create alarm for health plans that is about to expire */ plans(cal.getTime()); /* * Create alarm for activities that is about to expire */ activities(cal.getTime()); log.info("======== ALARM JOB COMPLETED ========="); }
From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java
private static String dayToICalRRulePart(int hintYear, int hintMonth, Day day) { DayType type = day.getType();/*from w ww . jav a 2s. c o m*/ int weeknum = day.getWeeknum(); Weekday wkday = day.getWeekday(); int date = day.getDate(); // Turn ON rules into WEEKNUM rules using the wkday of the monthday in hintYear/hintMonth. if (DayType.ON.equals(type)) { Calendar hintDay = new GregorianCalendar(TimeZone.getTimeZone("UTC")); hintDay.set(hintYear, hintMonth - 1, date, 0, 0, 0); hintDay.set(Calendar.MILLISECOND, 0); int calWkday = hintDay.get(Calendar.DAY_OF_WEEK); wkday = Weekday.lookUp(calWkday); assert (wkday != null); weeknum = (date - 1) / 7 + 1; // Did they mean "last week" rather than "week 4"? if (hintDay.getActualMaximum(Calendar.DAY_OF_MONTH) - date < 7) weeknum = -1; type = DayType.WEEKNUM; } String icalWkday = weekdayToICalWkday(wkday); // Turn [ON_OR_]BEFORE/AFTER rules into WEEKNUM rules using the wkday of the monthday in hintYear/hintMonth. // Simplify: < to <=, > to >=. if (DayType.BEFORE.equals(type)) { type = DayType.ON_OR_BEFORE; --date; } else if (DayType.AFTER.equals(type)) { type = DayType.ON_OR_AFTER; ++date; } if (DayType.ON_OR_BEFORE.equals(type) || DayType.ON_OR_AFTER.equals(type)) { Calendar hintDay = new GregorianCalendar(TimeZone.getTimeZone("UTC")); hintDay.set(hintYear, hintMonth - 1, date, 0, 0, 0); hintDay.set(Calendar.MILLISECOND, 0); int numDaysInMonth = hintDay.getActualMaximum(Calendar.DAY_OF_MONTH); int calWkday = hintDay.get(Calendar.DAY_OF_WEEK); int wkdayInt = Weekday.toInt(wkday); int newDate; if (DayType.ON_OR_BEFORE.equals(type)) { // search backward if (calWkday > wkdayInt) // e.g calWkday=Wed(4), wkdayInt=Sun(1) => back 3 newDate = date - (calWkday - wkdayInt); else // eg. calWkday=Wed(4), wkdayInt=Fri(6) => back 5 = back 7-2 newDate = date - (7 + (calWkday - wkdayInt)); } else { // search forward if (calWkday > wkdayInt) // e.g calWkday=Wed(4), wkdayInt=Sun(1) => forward 4 = forward 7 - 3 newDate = date + (7 + (wkdayInt - calWkday)); else // eg. calWkday=Wed(4), wkdayInt=Fri(6) => forward 2 newDate = date + (wkdayInt - calWkday); } if (newDate >= 1 && newDate <= numDaysInMonth) { weeknum = (newDate - 1) / 7 + 1; // Did they mean "last week" rather than "week 4"? if (numDaysInMonth - newDate < 7) weeknum = -1; type = DayType.WEEKNUM; } } // If we couldn't convert BYMONTHDAY rule to BYDAY rule for any reason, we have no choice but // to use the ugly BYMONTHDAY rule that lists 7 dates. // week 1: 1-7 // week 2: 8-14 // week 3: 15 - 21 // week 4: 22 - 28 // week 5: 29 - 31 if (DayType.ON_OR_BEFORE.equals(type)) { if (date % 7 == 0) { // days 7, 14, 21 and 28 only weeknum = (date - 1) / 7 + 1; type = DayType.WEEKNUM; } else { // Can't be done in WEEKNUM style. We need to use a more verbose iCalendar recurrence // syntax. Let's use the example of "Sun<=25". This means the last Sunday of the month // on or before the 25th. We can express this in iCalendar with 2 conditions ANDed together: // 1) BYDAY=SU (all Sundays in the month) // 2) BYMONTHDAY=19,20,21,22,23,24,25 (7 days ending on the given date) StringBuilder sb = new StringBuilder("BYDAY="); sb.append(icalWkday).append(";BYMONTHDAY="); int minDate = Math.max(date - 6, 1); sb.append(minDate); for (int i = minDate + 1; i <= date; ++i) { sb.append(",").append(i); } return sb.toString(); } } else if (DayType.ON_OR_AFTER.equals(type)) { if (date % 7 == 1) { // days 1, 8, 15, 22, and 29 only weeknum = date / 7 + 1; type = DayType.WEEKNUM; } else { // Similar to ON_OR_BEFORE case above. Combine BYDAY and BYMONTHDAY rules. // Example: "Sat>=13" means the first Sunday on or after the 9th. // 1) BYDAY=SA (all Saturdays in the month) // 2) BYMONTHDAY=13,14,15,16,17,18,19 (7 days starting on the given date) StringBuilder sb = new StringBuilder("BYDAY="); sb.append(icalWkday).append(";BYMONTHDAY="); sb.append(date); int maxDate = Math.min(date + 6, 31); for (int i = date + 1; i <= maxDate; ++i) { sb.append(",").append(i); } return sb.toString(); } } assert (DayType.WEEKNUM.equals(type)); if (weeknum > 4) weeknum = -1; return String.format("BYDAY=%d%s", weeknum, icalWkday); }