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.krawler.common.util.SchedulingUtilities.java
public static int nonWorkingDays(java.util.Date stdate, java.util.Date enddate, int[] NonWorkDays, String[] CmpHoliDays) throws ServiceException { Calendar c1 = Calendar.getInstance(); int NonWorkingDaysBetween = 0; Date StDate = stdate;/* w w w . j a v a2s .com*/ Date EndDate = enddate; try { c1.setTime(stdate); while ((stdate.compareTo(enddate)) < 0) { if (Arrays.binarySearch(NonWorkDays, (c1.get(Calendar.DAY_OF_WEEK) - 1)) > -1) { NonWorkingDaysBetween += 1; } c1.add(Calendar.DATE, 1); stdate = c1.getTime(); } NonWorkingDaysBetween += CountCmpHolidays(StDate, EndDate, CmpHoliDays); } catch (Exception e) { throw ServiceException.FAILURE("Exception while calculating non working days : " + e.getMessage(), e); } return NonWorkingDaysBetween; }
From source file:com.haulmont.timesheets.service.StatisticServiceBean.java
@Override public Map<Integer, Map<String, Object>> getStatisticsByProjects(Date start, Date end) { LoadContext<TimeEntry> loadContext = new LoadContext<>(TimeEntry.class) .setQuery(new LoadContext.Query( "select t from ts$TimeEntry t where t.date >= :start and t.date <= :end order by t.date") .setParameter("start", start).setParameter("end", end)) .setView(new View(TimeEntry.class) .addProperty("task", new View(Task.class).addProperty("name").addProperty("project", viewRepository.getView(Project.class, View.MINIMAL))) .addProperty("timeInMinutes").addProperty("date")); List<TimeEntry> timeEntries = dataManager.loadList(loadContext); Map<WeekAndProject, BigDecimal> statistic = new LinkedHashMap<>(); Calendar calendar = Calendar.getInstance(); for (TimeEntry timeEntry : timeEntries) { calendar.setTime(timeEntry.getDate()); int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR); WeekAndProject key = new WeekAndProject(weekOfYear, timeEntry.getTask().getProject()); BigDecimal sum = statistic.get(key); if (sum == null) { sum = BigDecimal.ZERO; }/*from w w w . j a v a 2 s .c o m*/ sum = sum.add(HoursAndMinutes.fromTimeEntry(timeEntry).toBigDecimal()); statistic.put(key, sum); } Map<Integer, Map<String, Object>> result = new LinkedHashMap<>(); for (Map.Entry<WeekAndProject, BigDecimal> entry : statistic.entrySet()) { Integer week = entry.getKey().week; Map<String, Object> projectsByWeek = result.get(week); if (projectsByWeek == null) { projectsByWeek = new HashMap<>(); calendar.set(Calendar.WEEK_OF_YEAR, week); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); projectsByWeek.put("week", DateTimeUtils.getDateFormat().format(calendar.getTime())); } projectsByWeek.put(entry.getKey().project.getName(), entry.getValue()); result.put(week, projectsByWeek); } return result; }
From source file:Holidays.java
public static java.util.Calendar ChristmasDayObserved(int nYear) { int nX;/* ww w.j a v a 2s.c o m*/ int nMonth = 11; // December java.util.Calendar cal; cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 25); nX = cal.get(Calendar.DAY_OF_WEEK); switch (nX) { case 0: {// Sunday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 26); return cal; } case 1: // Monday case 2: // Tuesday case 3: // Wednesday case 4: // Thrusday case 5: { // Friday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 25); return cal; } default: { // Saturday cal = java.util.Calendar.getInstance(); cal.set(nYear, nMonth, 24); return cal; } } }
From source file:com.mirth.connect.plugins.messagepruner.MessagePrunerService.java
private Trigger createTrigger(Properties properties) throws ParseException { Trigger trigger = null;//from w ww . ja va 2s . c o m String interval = PropertyLoader.getProperty(properties, "interval"); if (interval.equals("hourly")) trigger = TriggerUtils.makeHourlyTrigger(); else { SimpleDateFormat timeDateFormat = new SimpleDateFormat("hh:mm aa"); DateFormatter timeFormatter = new DateFormatter(timeDateFormat); String time = PropertyLoader.getProperty(properties, "time"); Date timeDate = (Date) timeFormatter.stringToValue(time); Calendar timeCalendar = Calendar.getInstance(); timeCalendar.setTime(timeDate); if (interval.equals("daily")) { trigger = TriggerUtils.makeDailyTrigger(timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE)); } else if (interval.equals("weekly")) { SimpleDateFormat dayDateFormat = new SimpleDateFormat("EEEEEEEE"); DateFormatter dayFormatter = new DateFormatter(dayDateFormat); String dayOfWeek = PropertyLoader.getProperty(properties, "dayOfWeek"); Date dayDate = (Date) dayFormatter.stringToValue(dayOfWeek); Calendar dayCalendar = Calendar.getInstance(); dayCalendar.setTime(dayDate); trigger = TriggerUtils.makeWeeklyTrigger(dayCalendar.get(Calendar.DAY_OF_WEEK), timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE)); } else if (interval.equals("monthly")) { SimpleDateFormat dayDateFormat = new SimpleDateFormat("DD"); DateFormatter dayFormatter = new DateFormatter(dayDateFormat); String dayOfMonth = PropertyLoader.getProperty(properties, "dayOfMonth"); Date dayDate = (Date) dayFormatter.stringToValue(dayOfMonth); Calendar dayCalendar = Calendar.getInstance(); dayCalendar.setTime(dayDate); trigger = TriggerUtils.makeMonthlyTrigger(dayCalendar.get(Calendar.DAY_OF_MONTH), timeCalendar.get(Calendar.HOUR_OF_DAY), timeCalendar.get(Calendar.MINUTE)); } } trigger.setStartTime(new Date()); trigger.setName("prunerTrigger"); trigger.setJobName("prunerJob"); return trigger; }
From source file:com.espertech.esper.regression.pattern.TestCronParameter.java
public void testOperator() throws Exception { // Observer for last Sunday of month, 0 = Sunday int lastDayOfWeek = getLastDayOfWeekInMonth(0, 2007); calendar.set(2007, getCurrentMonth(2007), lastDayOfWeek, 8, 00, 00); printCurrentTime(calendar);/*w w w. j a v a 2 s . co m*/ baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, *, 0 last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of current month calendar.set(2007, getCurrentMonth(2007), getLastDayOfMonth(2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, last, *, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of Auguts 2007 // For Java: January=0, February=1, March=2, April=3, May=4, June=5, // July=6, August=7, September=8, November=9, October=10, December=11 // For Esper: January=1, February=2, March=3, April=4, May=5, June=6, // July=7, August=8, September=9, November=10, October=11, December=12 calendar.set(2007, Calendar.AUGUST, 31, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, last, 8, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of February 2007 calendar.set(2007, Calendar.FEBRUARY, 28, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, last, 2, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last day of week (Saturday) Calendar calendar = Calendar.getInstance(); Date date = new Date(); calendar.setTime(date); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, *, last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last Friday of June calendar.set(2007, Calendar.JUNE, 29, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, 6, 5 last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last weekday of the current month calendar.set(2007, getCurrentMonth(2007), getLastWeekDayOfMonth(null, 2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, lastweekday, *, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last weekday of September 2007, it's Friday September 28th calendar.set(2007, Calendar.SEPTEMBER, 28, 10, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, lastweekday, 9, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last weekday of February, it's Wednesday February 28th calendar.set(2007, Calendar.FEBRUARY, 28, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, lastweekday, 2, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for nearest weekday for current month on the 10th calendar.set(2007, getCurrentMonth(2007), getLastWeekDayOfMonth(10, 2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, 10 weekday, *, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for nearest weekday of September 1st (Saturday), it's Monday September 3rd (no "jump" over month) calendar.set(2007, Calendar.SEPTEMBER, 3, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, 1 weekday, 9, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for nearest weekday of September 30th (Sunday), it's Friday September 28th (no "jump" over month) calendar.set(2007, Calendar.SEPTEMBER, 28, 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, 30 weekday, 9, *, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); // Observer for last Friday of current month, // 0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4= Thursday, 5=Friday, 6=Saturday calendar.set(2007, getCurrentMonth(2007), getLastDayOfWeekInMonth(5, 2007), 8, 00, 00); printCurrentTime(calendar); baseTime = calendar.getTimeInMillis(); testData = getEventSet(baseTime, 1000 * 60 * 10); expressionText = "timer:at(*, *, *, *, 5 last, *)"; testCase = new EventExpressionCase(expressionText); testCase.add("A1"); runTestEvent(); }
From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataFormEntryOverviewController.java
@RequestMapping("/module/facilitydata/formEntryOverview.form") public void formEntryOverview(ModelMap map, @RequestParam(required = true) FacilityDataForm form, @RequestParam(required = false) Integer yearIncrement, @RequestParam(required = false) Integer monthIncrement) throws Exception { FacilityDataService service = Context.getService(FacilityDataService.class); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1);/*from w ww.ja v a2s.com*/ if (yearIncrement != null) { cal.add(Calendar.YEAR, yearIncrement); } if (monthIncrement != null) { cal.add(Calendar.DATE, monthIncrement * 21); } if (form.getFrequency() == Frequency.MONTHLY) { cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); } Date endDate = cal.getTime(); if (form.getFrequency() == Frequency.MONTHLY) { // For monthly reports, display last year cal.set(Calendar.DATE, 1); cal.add(Calendar.YEAR, -1); } else if (form.getFrequency() == Frequency.DAILY) { // For daily reports, display last 3 weeks cal.add(Calendar.DATE, -21); } else { throw new RuntimeException("Unable to handle a report with frequency: " + form.getFrequency()); } Date startDate = cal.getTime(); Map<Integer, Map<String, Integer>> questionsAnswered = service.getNumberOfQuestionsAnswered(form, startDate, endDate); DateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd"); DateFormat monthFormat = new SimpleDateFormat("MMM"); List<Integer> daysOfWeekSupported = FacilityDataConstants.getDailyReportDaysOfWeek(); Map<Integer, Integer> yearCols = new LinkedHashMap<Integer, Integer>(); // Year -> Number of columns Map<String, Integer> monthCols = new LinkedHashMap<String, Integer>(); // Month -> Number of columns Map<String, Date> dayCols = new LinkedHashMap<String, Date>(); Map<Integer, Map<String, Integer>> dayData = new HashMap<Integer, Map<String, Integer>>(); // LocationId -> Day -> Number of questions Map<Object, String> displayKeys = new HashMap<Object, String>(); // Map key -> Display format Set<String> datesSupported = new HashSet<String>(); // Dates support entry while (cal.getTime().before(endDate)) { String dateStr = ymdFormat.format(cal.getTime()); Integer year = cal.get(Calendar.YEAR); String month = monthFormat.format(cal.getTime()); Integer day = cal.get(Calendar.DAY_OF_MONTH); yearCols.put(year, yearCols.get(year) == null ? 1 : yearCols.get(year) + 1); monthCols.put(year + month, monthCols.get(year + month) == null ? 1 : monthCols.get(year + month) + 1); dayCols.put(dateStr, cal.getTime()); if (form.getFrequency() == Frequency.MONTHLY || daysOfWeekSupported.contains(cal.get(Calendar.DAY_OF_WEEK))) { datesSupported.add(dateStr); } for (Integer locationId : questionsAnswered.keySet()) { Map<String, Integer> questionsAnsweredAtLocation = questionsAnswered.get(locationId); Integer numAnswered = questionsAnsweredAtLocation == null ? null : questionsAnsweredAtLocation.get(dateStr); Map<String, Integer> locationData = dayData.get(locationId); if (locationData == null) { locationData = new HashMap<String, Integer>(); dayData.put(locationId, locationData); } locationData.put(dateStr, numAnswered == null ? 0 : numAnswered); } displayKeys.put(year, year.toString()); displayKeys.put(year + month, month); displayKeys.put(dateStr, day.toString()); cal.add(form.getFrequency().getCalendarField(), form.getFrequency().getCalendarIncrement()); } Map<FacilityDataFormSchema, Integer> numQuestionsBySchema = new HashMap<FacilityDataFormSchema, Integer>(); for (FacilityDataFormSchema schema : form.getSchemas()) { numQuestionsBySchema.put(schema, schema.getTotalNumberOfQuestions()); } map.addAttribute("today", new Date()); map.addAttribute("form", form); map.addAttribute("yearIncrement", yearIncrement); map.addAttribute("monthIncrement", monthIncrement); map.addAttribute("yearCols", yearCols); map.addAttribute("monthCols", monthCols); map.addAttribute("dayCols", dayCols); map.addAttribute("dayData", dayData); map.addAttribute("displayKeys", displayKeys); map.addAttribute("numQuestionsBySchema", numQuestionsBySchema); map.addAttribute("questionsAnswered", questionsAnswered); map.addAttribute("locations", FacilityDataConstants.getSupportedFacilities()); map.addAttribute("datesSupported", datesSupported); }
From source file:de.tor.tribes.ui.components.DatePicker.java
public void buildCalendar() { jLabelMonth.setText(monthAndYear.format(selectedDate)); Calendar temp = new GregorianCalendar(); temp.setTime(selectedDate);/*from ww w. j a va 2 s. com*/ int maxDaysInMonth = temp.getActualMaximum(Calendar.DAY_OF_MONTH); int firstdayInMonth = temp.getActualMinimum(Calendar.DAY_OF_MONTH); temp.set(Calendar.DAY_OF_MONTH, firstdayInMonth); int dayOfWeek = mapDayOfWeek(temp.get(Calendar.DAY_OF_WEEK)); int currentField = 0; //ensure that at least one day of prev month is shown int preDaysToAdd = ((dayOfWeek + 5) % 7) + 1; temp.add(Calendar.MONTH, -1); temp.set(Calendar.DAY_OF_MONTH, temp.getActualMaximum(Calendar.DAY_OF_MONTH) - preDaysToAdd + 1); for (; currentField < preDaysToAdd; currentField++) { //days belong to last month CrossedLabel current = daysInMonth[currentField / 7][currentField % 7]; current.setText("" + temp.get(Calendar.DAY_OF_MONTH)); current.setForeground(LIGHT_GRAY); datesInMonth[currentField / 7][currentField % 7] = temp.getTime(); temp.add(Calendar.DAY_OF_MONTH, 1); } //normal days of month for (int i = firstdayInMonth; i <= maxDaysInMonth; i++, currentField++) { CrossedLabel current = daysInMonth[currentField / 7][currentField % 7]; current.setText("" + temp.get(Calendar.DAY_OF_MONTH)); current.setForeground(BLACK); datesInMonth[currentField / 7][currentField % 7] = temp.getTime(); temp.add(Calendar.DAY_OF_MONTH, 1); } //post days of month for (; currentField < WEEKS_TO_SHOW * 7; currentField++) { CrossedLabel current = daysInMonth[currentField / 7][currentField % 7]; current.setText("" + temp.get(Calendar.DAY_OF_MONTH)); current.setForeground(LIGHT_GRAY); datesInMonth[currentField / 7][currentField % 7] = temp.getTime(); temp.add(Calendar.DAY_OF_MONTH, 1); } for (int i = 0; i < WEEKS_TO_SHOW * 7; i++) { if (selectedDate.equals(datesInMonth[i / 7][i % 7])) { daysInMonth[i / 7][i % 7].cross(); } else { daysInMonth[i / 7][i % 7].uncross(); } } }
From source file:br.com.transport.report.ManagerReportBean.java
/** * Retorna lista com os dias da semana/*w ww. ja v a2 s . c o m*/ * @return {@link List}< {@link Calendar} > */ private List<Calendar> createDayOfTheWeek() { Calendar firstDay = GregorianCalendar.getInstance(); firstDay.setFirstDayOfWeek(Calendar.SUNDAY); firstDay.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); firstDay.set(Calendar.HOUR_OF_DAY, 0); firstDay.set(Calendar.MINUTE, 0); firstDay.set(Calendar.SECOND, 0); List<Calendar> daysOfTheWeek = new LinkedList<Calendar>(); for (int count = 0; count < 7; count++) { Calendar temp = (Calendar) firstDay.clone(); temp.roll(Calendar.DAY_OF_WEEK, count); temp.setTime(temp.getTime()); daysOfTheWeek.add(temp); } return daysOfTheWeek; }
From source file:com.etime.ETimeUtils.java
/** * Return a List of Punches for the current day. The list is empty if there are no punches for today. * * @param page the raw html of the user's timecard page * @return A list of Punches for the current day. *///from w w w. ja va 2 s . c om protected static List<Punch> getTodaysPunches(String page) { String curRow; String date; List<Punch> punchesList = new LinkedList<Punch>(); Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); String dayOfWeek = daysOfWeek[calendar.get(Calendar.DAY_OF_WEEK) - 1]; if (day < 10) { date = dayOfWeek + " " + Integer.toString(month) + "/0" + Integer.toString(day); } else { date = dayOfWeek + " " + Integer.toString(month) + "/" + Integer.toString(day); } try { Pattern todaysRowsPattern = Pattern.compile("(?i)(>" + date + ")(.*?)(</tr>)", Pattern.MULTILINE | Pattern.DOTALL); Matcher todaysRowsMatcher = todaysRowsPattern.matcher(page); while (todaysRowsMatcher.find()) { curRow = todaysRowsMatcher.group(2); addPunchesFromRowToList(curRow, punchesList); } } catch (Exception e) { Log.w(TAG, e.toString()); } return punchesList; }
From source file:com.zigbee.framework.common.util.Utils.java
/** * ??// w w w . ja va 2 s. c om * @Date : 2011-6-27 * @return */ public static String getLastSundayBeforeThisWeek() { Calendar c = Calendar.getInstance(); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK) - 1; if (dayOfWeek == 0) { dayOfWeek = 7; } c.add(Calendar.DATE, -dayOfWeek); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(c.getTime()); }