List of usage examples for java.util Calendar SUNDAY
int SUNDAY
To view the source code for java.util Calendar SUNDAY.
Click Source Link
From source file:org.osframework.contract.date.fincal.holiday.producer.SingleYearProducer.java
private void addWeekends(FinancialCalendar calendar, List<Holiday> holidays) { c.clear();/* w w w . ja v a2 s .com*/ c.set(year, Calendar.JANUARY, 1); while (c.get(Calendar.YEAR) == year) { if (Calendar.SATURDAY == c.get(Calendar.DAY_OF_WEEK) || Calendar.SUNDAY == c.get(Calendar.DAY_OF_WEEK)) { holidays.add(new Holiday(calendar, c.getTime(), WEEKEND_HOLIDAY_DEFINITION)); } c.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:stepReport.model.PeriodoModel.java
private String[] calcPeriodoMes(String Mes) { Calendar c = Calendar.getInstance(); String ano = Mes.substring(6, 10); String mes = Mes.substring(3, 5); mes = Integer.toString(Integer.parseInt(mes) - 1); c.set(Integer.parseInt(ano), Integer.parseInt(mes), 1); int day = c.get(Calendar.DAY_OF_WEEK); while (day != Calendar.SUNDAY) { c.add(Calendar.DAY_OF_WEEK, 1); day = c.get(Calendar.DAY_OF_WEEK); }/*from w w w . j a va 2 s . c om*/ SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd"); String dataIni = fmt.format(c.getTime()); int maxDay = c.getActualMaximum(Calendar.DAY_OF_MONTH); c = Calendar.getInstance(); c.set(Integer.parseInt(ano), Integer.parseInt(mes), maxDay); day = c.get(Calendar.DAY_OF_MONTH); while (day != Calendar.SUNDAY) { c.add(Calendar.DAY_OF_WEEK, 1); day = c.get(Calendar.DAY_OF_WEEK); } String dataFim = fmt.format(c.getTime()); String[] v = { dataIni, dataFim }; return v; }
From source file:com.itd.dbmrgdao.TestTime_newscanner.java
private Boolean updateScanFileRoundUp2(BufferedReader br) { try {//from w w w .ja v a 2 s . co m String strLine; SimpleDateFormat curFormater = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); ScanDataDate scanDataDateItem = null; Map<String, ScanDataDate> mapScanDatas = new HashMap<String, ScanDataDate>(); String scode = "1985"; // ? ?? String sunday2014 = "2557-01-05"; //default value for check correct setting year Date dateObj = curFormater.parse(sunday2014); Calendar calendar = Calendar.getInstance(); calendar.setTime(dateObj); if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) { // system not correct return false; } for (strLine = br.readLine(); strLine != null; strLine = br.readLine()) { String sysid = "", scdate = null, p1Start = null, p2End = null; Boolean isSunday = false; String parts[] = new String[7]; // read data from scan machine by line parts[1] = strLine.substring(3, 11); // date parts[5] = strLine.substring(11, 15); // time parts[5] = new StringBuffer(parts[5]).insert(parts[5].length() - 2, ":").toString(); parts[0] = strLine.substring(18, 27); // systemid // update read data to standard data sysid = parts[0]; scdate = new StringBuffer(parts[1]).insert(parts[1].length() - 2, "-").toString(); scdate = new StringBuffer(scdate).insert(scdate.length() - 5, "-").toString(); // check if sunday must convert to 543 first String temp_scdate = (Integer.toString(Integer.parseInt(scdate.substring(0, 4)) + 543)) .concat(scdate.substring(4, 10)); dateObj = curFormater.parse(temp_scdate); calendar = Calendar.getInstance(); calendar.setTime(dateObj); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { isSunday = true; } // check time from scan machine for in or out ScanRule scanRule = scanDao.findScanRuleBySysId(sysid); //if used in record if (mapScanDatas.containsKey(sysid)) { scanDataDateItem = mapScanDatas.get(sysid); mapScanDatas.remove(sysid); p1Start = scanDataDateItem.getP1start(); p2End = scanDataDateItem.getP2end(); } else { // never used in record scanDataDateItem = null; p1Start = scanRule.getP1start(); p2End = scanRule.getP2end(); } parts[6] = FindInOut(parts[5], scanRule.getP1break_st()); if (parts[6].equals("01")) { p1Start = CompareTime(p1Start, parts[5], "01"); } else { p2End = CompareTime(p2End, parts[5], "04"); } // ?? ? ? table scan rule code if (p2End == null || p2End.isEmpty()) { //if not punch out Monthly or Daily will automatic p2End startdart time p2End = scanRule.getP2end(); } else { p2End = CompareTime(p2End, scanRule.getP2end(), "04"); if (scanRule.getCalcot().equals("Y")) { //check if 10 min roundup // >= 50 will 60, < 50 and >= 20 will 30 , < 20 will be 00 p2End = MinRoundUp(p2End); } } // ? if (isSunday) { p2End = scanRule.getP2end(); } scanDataDateItem = new ScanDataDate(sysid, scdate, scode, p1Start, p2End); mapScanDatas.put(sysid, scanDataDateItem); System.out.println("Sysid : " + sysid + ", In : " + scanDataDateItem.getP1start() + ", Out : " + scanDataDateItem.getP2end()); } // create SQL and update data in table UpdateScanData(mapScanDatas); br.close(); return true; } catch (IOException | ParseException e) { JOptionPane.showMessageDialog(null, e); } return false; }
From source file:com.github.notizklotz.derbunddownloader.download.AutomaticIssueDownloadAlarmManager.java
private Calendar calculateNextAlarm(int hourOfDay, int minute) { final Calendar nextAlarm = Calendar.getInstance(); nextAlarm.clear();//from w ww. ja v a2s. c om final Calendar now = Calendar.getInstance(); nextAlarm.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), hourOfDay, minute); //Make sure trigger is in the future if (now.after(nextAlarm)) { nextAlarm.add(Calendar.DAY_OF_MONTH, 1); } //Do not schedule Sundays as the newspaper is not issued on Sundays if ((nextAlarm.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) { nextAlarm.add(Calendar.DAY_OF_MONTH, 1); } return nextAlarm; }
From source file:de.ribeiro.android.gso.activities.PlanActivity.java
/** * @author ribeiro// www . j a va 2s .c om * ffnet ein Datumsplugin und prft, ob dieses TimeTable verfgbar ist, wenn ja, springt er dorthin */ private void gotoDate() { ctxt.handler.post(new Runnable() { @Override public void run() { _logger.Info("Goto Date called"); if (ctxt.mIsRunning && ctxt.pager != null && ctxt.pager.size() > 1) { Calendar cal = ctxt.pager.getDateOfCurrentPage(); if (cal != null) { DatePickerDialog picker = new DatePickerDialog(PlanActivity.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { _logger.Info("Set Date " + dayOfMonth + "." + monthOfYear + "." + year); // das Ausgewhlte Datum einstellen Calendar newDate = new GregorianCalendar(); newDate.set(year, monthOfYear, dayOfMonth); // prfen, ob es sich dabei um wochenend tage // handelt: switch (newDate.get(Calendar.DAY_OF_WEEK)) { case Calendar.SATURDAY: newDate.setTimeInMillis( newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2)); break; case Calendar.SUNDAY: newDate.setTimeInMillis( newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 1)); break; } int page = ctxt.pager.getPage(newDate, -1); if (page != -1) { // gefunden ctxt.pager.setPage(page); } else { _logger.Info("Selected date is unavailable"); Toast.makeText(PlanActivity.this, "Dieses Datum ist nicht verfgbar!", Toast.LENGTH_SHORT).show(); } } }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); picker.show(); } else _logger.Info("Cal Picker canceled, because Pager is empty"); } } }); }
From source file:org.osframework.contract.date.fincal.holiday.producer.SingleFinancialCalendarProducer.java
private void addWeekends(int year, List<Holiday> holidays) { c.clear();/*from w ww .j ava2 s . c om*/ c.set(year, Calendar.JANUARY, 1); while (c.get(Calendar.YEAR) == year) { if (Calendar.SATURDAY == c.get(Calendar.DAY_OF_WEEK) || Calendar.SUNDAY == c.get(Calendar.DAY_OF_WEEK)) { holidays.add(new Holiday(calendar, c.getTime(), WEEKEND_HOLIDAY_DEFINITION)); } c.add(Calendar.DAY_OF_MONTH, 1); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.exams.RoomSearchDA.java
public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DynaValidatorForm roomSearchForm = (DynaValidatorForm) form; // date//from w w w .j ava 2 s . c o m Calendar searchDate = Calendar.getInstance(); Integer day = new Integer((String) roomSearchForm.get("day")); Integer month = new Integer((String) roomSearchForm.get("month")); Integer year = new Integer((String) roomSearchForm.get("year")); request.setAttribute("day", day.toString()); request.setAttribute("month", month.toString()); request.setAttribute("year", year.toString()); searchDate.set(Calendar.YEAR, year.intValue()); searchDate.set(Calendar.MONTH, month.intValue() - 1); searchDate.set(Calendar.DAY_OF_MONTH, day.intValue()); if (searchDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { ActionError actionError = new ActionError("error.sunday"); ActionErrors actionErrors = new ActionErrors(); actionErrors.add("error.sunday", actionError); saveErrors(request, actionErrors); return prepare(mapping, form, request, response); } // exam start time Calendar searchStartTime = Calendar.getInstance(); Integer startHour = new Integer((String) roomSearchForm.get("beginningHour")); Integer startMinute = new Integer((String) roomSearchForm.get("beginningMinute")); request.setAttribute("beginningHour", startHour.toString()); request.setAttribute("beginningMinute", startMinute.toString()); searchStartTime.set(Calendar.HOUR_OF_DAY, startHour.intValue()); searchStartTime.set(Calendar.MINUTE, startMinute.intValue()); searchStartTime.set(Calendar.SECOND, 0); // exam end time Calendar searchEndTime = Calendar.getInstance(); Integer endHour = new Integer((String) roomSearchForm.get("endHour")); Integer endMinute = new Integer((String) roomSearchForm.get("endMinute")); request.setAttribute("endHour", endHour.toString()); request.setAttribute("endMinute", endMinute.toString()); searchEndTime.set(Calendar.HOUR_OF_DAY, endHour.intValue()); searchEndTime.set(Calendar.MINUTE, endMinute.intValue()); searchEndTime.set(Calendar.SECOND, 0); if (searchStartTime.after(searchEndTime)) { ActionError actionError = new ActionError("error.timeSwitched"); ActionErrors actionErrors = new ActionErrors(); actionErrors.add("error.timeSwitched", actionError); saveErrors(request, actionErrors); return prepare(mapping, form, request, response); } int dayOfWeekInt = searchDate.get(Calendar.DAY_OF_WEEK); DiaSemana dayOfWeek = new DiaSemana(dayOfWeekInt); List<InfoRoom> availableInfoRoom = null; availableInfoRoom = SpaceUtils.allocatableSpace(YearMonthDay.fromCalendarFields(searchDate), YearMonthDay.fromCalendarFields(searchDate), HourMinuteSecond.fromCalendarFields(searchStartTime), HourMinuteSecond.fromCalendarFields(searchEndTime), dayOfWeek, null, null, false); String sdate = roomSearchForm.get("day") + "/" + roomSearchForm.get("month") + "/" + roomSearchForm.get("year"); String startTime = roomSearchForm.get("beginningHour") + ":" + roomSearchForm.get("beginningMinute"); String endTime = roomSearchForm.get("endHour") + ":" + roomSearchForm.get("endMinute"); request.setAttribute(PresentationConstants.DATE, sdate); request.setAttribute(PresentationConstants.START_TIME, startTime); request.setAttribute(PresentationConstants.END_TIME, endTime); Integer exam = null; Integer normal = null; List<InfoRoom> newAvailableInfoRoom = new ArrayList<InfoRoom>(); if (availableInfoRoom != null && !availableInfoRoom.isEmpty()) { try { exam = new Integer((String) roomSearchForm.get("exam")); } catch (NumberFormatException ex) { // the user didn't speciefy a exam minimum capacity } try { normal = new Integer((String) roomSearchForm.get("normal")); } catch (NumberFormatException ex) { // the user didn't speciefy a normal minimum capacity } if (normal != null || exam != null) { Iterator<InfoRoom> iter = availableInfoRoom.iterator(); while (iter.hasNext()) { InfoRoom elem = iter.next(); if (!((normal != null && elem.getCapacidadeNormal().intValue() < normal.intValue()) || (exam != null && elem.getCapacidadeExame().intValue() < exam.intValue()))) { newAvailableInfoRoom.add(elem); } } } else { newAvailableInfoRoom = availableInfoRoom; } } if (newAvailableInfoRoom != null && !newAvailableInfoRoom.isEmpty()) { Collections.sort(newAvailableInfoRoom, new BeanComparator("nome")); String[] availableRoomId = new String[newAvailableInfoRoom.size()]; Iterator<InfoRoom> iter = newAvailableInfoRoom.iterator(); int i = 0; while (iter.hasNext()) { InfoRoom elem = iter.next(); availableRoomId[i] = elem.getExternalId().toString(); } request.setAttribute(PresentationConstants.AVAILABLE_ROOMS_ID, availableRoomId); } request.setAttribute(PresentationConstants.AVAILABLE_ROOMS, newAvailableInfoRoom); return mapping.findForward("showRooms"); }
From source file:org.silverpeas.calendar.CalendarViewContext.java
private void setReferenceDay(final Date date, int offset) { // Reference date Calendar cal = DateUtil.convert(date, locale); final Date referenceDate; if (!withWeekend && (viewType.equals(CalendarViewType.WEEKLY) || viewType.equals(CalendarViewType.DAILY))) { switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.SATURDAY: if (Calendar.SATURDAY == DateUtil.getFirstDayOfWeek(locale)) { referenceDate = DateUtils.addDays(date, (offset >= 0 ? 2 : -1)); } else { referenceDate = DateUtils.addDays(date, (offset > 0 ? 2 : -1)); }/*from w w w . j a v a 2 s. com*/ break; case Calendar.SUNDAY: if (Calendar.SUNDAY == DateUtil.getFirstDayOfWeek(locale)) { referenceDate = DateUtils.addDays(date, (offset >= 0 ? 1 : -2)); } else { referenceDate = DateUtils.addDays(date, (offset > 0 ? 1 : -2)); } break; default: referenceDate = date; } } else { referenceDate = date; } this.referenceDay = new CalendarDay(referenceDate, locale); // Period referencePeriod = CalendarPeriod.from(Period.from(referenceDate, viewType.getPeriodeType(), locale), locale); }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * Generate the histogram buckets based on the time frame requested and the interval. This will * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0. * @param rval// w ww .j av a 2 s . co m * @param from * @param to * @param interval */ public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval, DateTime from, DateTime to, HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) { Map<K, T> index = new HashMap<>(); Calendar fromCal = from.toGregorianCalendar(); Calendar toCal = to.toGregorianCalendar(); switch (interval) { case day: fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case hour: fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case minute: fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case month: fromCal.set(Calendar.DAY_OF_MONTH, 1); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case week: fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; default: break; } while (fromCal.before(toCal)) { String label = formatDateWithMillis(fromCal); T point; try { point = dataType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } point.setLabel(label); rval.addDataPoint(point); if (keyType == String.class) { index.put((K) label, point); } else { index.put((K) new Long(fromCal.getTimeInMillis()), point); } switch (interval) { case day: fromCal.add(Calendar.DAY_OF_YEAR, 1); break; case hour: fromCal.add(Calendar.HOUR_OF_DAY, 1); break; case minute: fromCal.add(Calendar.MINUTE, 1); break; case month: fromCal.add(Calendar.MONTH, 1); break; case week: fromCal.add(Calendar.WEEK_OF_YEAR, 1); break; default: break; } } return index; }
From source file:org.kuali.student.r2.core.scheduling.util.SchedulingServiceUtil.java
public static List<Integer> weekdaysString2WeekdaysList(String weekdaysString) { List<Integer> result = new ArrayList<Integer>(); if (StringUtils.isNotBlank(weekdaysString)) { checkStringForDayCode(SchedulingServiceConstants.MONDAY_TIMESLOT_DAY_CODE, Calendar.MONDAY, result, weekdaysString);//www . j ava 2 s . com checkStringForDayCode(SchedulingServiceConstants.TUESDAY_TIMESLOT_DAY_CODE, Calendar.TUESDAY, result, weekdaysString); checkStringForDayCode(SchedulingServiceConstants.WEDNESDAY_TIMESLOT_DAY_CODE, Calendar.WEDNESDAY, result, weekdaysString); checkStringForDayCode(SchedulingServiceConstants.THURSDAY_TIMESLOT_DAY_CODE, Calendar.THURSDAY, result, weekdaysString); checkStringForDayCode(SchedulingServiceConstants.FRIDAY_TIMESLOT_DAY_CODE, Calendar.FRIDAY, result, weekdaysString); checkStringForDayCode(SchedulingServiceConstants.SATURDAY_TIMESLOT_DAY_CODE, Calendar.SATURDAY, result, weekdaysString); checkStringForDayCode(SchedulingServiceConstants.SUNDAY_TIMESLOT_DAY_CODE, Calendar.SUNDAY, result, weekdaysString); } return result; }