List of usage examples for java.util Calendar MONDAY
int MONDAY
To view the source code for java.util Calendar MONDAY.
Click Source Link
From source file:com.hurence.logisland.utils.DateUtils.java
/** * Check if the date parameter is within a given range of hours * * @return true or false//from ww w. j a v a2 s . c o m */ public static boolean isWithinHourRange(Date date, int startHour, int stopHour) { if (stopHour < startHour) { throw new IllegalArgumentException("start hour shall be before stop hour"); } if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(date); int currentHour = calendar.get(Calendar.HOUR_OF_DAY); return currentHour >= startHour && currentHour <= stopHour; } else { return false; } }
From source file:nu.nethome.home.items.web.GraphServlet.java
/** * This is the main enterence point of the class. This is called when a http request is * routed to this servlet./* ww w .j a va 2 s .c o m*/ */ public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { ServletOutputStream p = res.getOutputStream(); Date startTime = null; Date stopTime = null; // Analyse arguments String fileName = req.getParameter("file"); if (fileName != null) fileName = getFullFileName(fromURL(fileName)); String startTimeString = req.getParameter("start"); String stopTimeString = req.getParameter("stop"); try { if (startTimeString != null) { startTime = m_Format.parse(startTimeString); } if (stopTimeString != null) { stopTime = m_Format.parse(stopTimeString); } } catch (ParseException e1) { e1.printStackTrace(); } String look = req.getParameter("look"); if (look == null) look = ""; TimeSeries timeSeries = new TimeSeries("Data", Minute.class); // Calculate time window Calendar cal = Calendar.getInstance(); Date currentTime = cal.getTime(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); Date startOfDay = cal.getTime(); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date startOfWeek = cal.getTime(); cal.set(Calendar.DAY_OF_MONTH, 1); Date startOfMonth = cal.getTime(); cal.set(Calendar.MONTH, Calendar.JANUARY); Date startOfYear = cal.getTime(); // if (startTime == null) startTime = startOfWeek; if (stopTime == null) stopTime = currentTime; if (startTime == null) startTime = new Date(stopTime.getTime() - 1000L * 60L * 60L * 24L * 2L); try { // Open the data file File logFile = new File(fileName); Scanner fileScanner = new Scanner(logFile); Long startTimeMs = startTime.getTime(); Long month = 1000L * 60L * 60L * 24L * 30L; boolean doOptimize = true; boolean justOptimized = false; try { while (fileScanner.hasNext()) { try { // Get next log entry String line = fileScanner.nextLine(); if (line.length() > 21) { // Adapt the time format String minuteTime = line.substring(0, 16).replace('.', '-'); // Parse the time stamp Minute min = Minute.parseMinute(minuteTime); // Ok, this is an ugly optimization. If the current time position in the file // is more than a month (30 days) ahead of the start of the time window, we // quick read two weeks worth of data, assuming that there is 4 samples per hour. // This may lead to scanning past start of window if there are holes in the data // series. if (doOptimize && ((startTimeMs - min.getFirstMillisecond()) > month)) { for (int i = 0; (i < (24 * 4 * 14)) && fileScanner.hasNext(); i++) { fileScanner.nextLine(); } justOptimized = true; continue; } // Detect if we have scanned past the window start position just after an optimization scan. // If this is the case it may be because of the optimization. In that case we have to switch // optimization off and start over. if ((min.getFirstMillisecond() > startTimeMs) && doOptimize && justOptimized) { logFile = new File(fileName); fileScanner = new Scanner(logFile); doOptimize = false; continue; } justOptimized = false; // Check if value is within time window if ((min.getFirstMillisecond() > startTimeMs) && (min.getFirstMillisecond() < stopTime.getTime())) { // Parse the value double value = Double.parseDouble((line.substring(20)).replace(',', '.')); // Add the entry timeSeries.add(min, value); doOptimize = false; } } } catch (SeriesException se) { // Bad entry, for example due to duplicates at daylight saving time switch } catch (NumberFormatException nfe) { // Bad number format in a line, try to continue } } } catch (Exception e) { System.out.println(e.toString()); } finally { fileScanner.close(); } } catch (FileNotFoundException f) { System.out.println(f.toString()); } // Create a collection for plotting TimeSeriesCollection data = new TimeSeriesCollection(); data.addSeries(timeSeries); JFreeChart chart; int xSize = 750; int ySize = 450; // Customize colors and look of the Graph. if (look.equals("mobtemp")) { // Look for the mobile GUI chart = ChartFactory.createTimeSeriesChart(null, null, null, data, false, false, false); XYPlot plot = chart.getXYPlot(); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); xSize = 175; ySize = 180; } else { // Create a Chart with time range as heading SimpleDateFormat localFormat = new SimpleDateFormat(); String heading = localFormat.format(startTime) + " - " + localFormat.format(stopTime); chart = ChartFactory.createTimeSeriesChart(heading, null, null, data, false, false, false); Paint background = new Color(0x9D8140); chart.setBackgroundPaint(background); TextTitle title = chart.getTitle(); // fix title Font titleFont = title.getFont(); titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0); title.setFont(titleFont); title.setPaint(Color.darkGray); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(background); plot.setDomainGridlinePaint(Color.darkGray); ValueAxis timeAxis = plot.getDomainAxis(); timeAxis.setAxisLineVisible(false); ValueAxis valueAxis = plot.getRangeAxis(0); valueAxis.setAxisLineVisible(false); plot.setRangeGridlinePaint(Color.darkGray); XYItemRenderer renderer = plot.getRenderer(0); renderer.setSeriesPaint(0, Color.darkGray); xSize = 750; ySize = 450; } try { res.setContentType("image/png"); res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); res.setStatus(HttpServletResponse.SC_OK); ChartUtilities.writeChartAsPNG(p, chart, xSize, ySize); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } p.flush(); p.close(); return; }
From source file:org.structr.common.RecurringDateHelper.java
private static int getDayOfWeek(final String shortWeekday) { if (shortWeekday != null && !shortWeekday.equals("")) try {/* ww w .j ava 2 s . c om*/ ShortWeekday wd = ShortWeekday.valueOf(shortWeekday); switch (wd) { case Mo: return Calendar.MONDAY; case Di: return Calendar.TUESDAY; case Mi: return Calendar.WEDNESDAY; case Do: return Calendar.THURSDAY; case Fr: return Calendar.FRIDAY; case Sa: return Calendar.SATURDAY; case So: return Calendar.SUNDAY; } } catch (Throwable t) { logger.log(Level.WARNING, "Unable to parse day of week for string {0}", shortWeekday); } return 0; }
From source file:in.suraj.timetableswipe.TYFragment.java
private void init() { rgroup = (RadioGroup) rootView.findViewById(R.id.rbgrp); rbMon = (RadioButton) rootView.findViewById(R.id.rbMon); rbTue = (RadioButton) rootView.findViewById(R.id.rbTue); rbWed = (RadioButton) rootView.findViewById(R.id.rbWed); rbThur = (RadioButton) rootView.findViewById(R.id.rbThur); rbFri = (RadioButton) rootView.findViewById(R.id.rbFri); tvLect1Name = (TextView) rootView.findViewById(R.id.tvLect1Name); tvLect1Prof = (TextView) rootView.findViewById(R.id.tvLect1Prof); tvLect2Name = (TextView) rootView.findViewById(R.id.tvLect2Name); tvLect2Prof = (TextView) rootView.findViewById(R.id.tvLect2Prof); tvLect3Name = (TextView) rootView.findViewById(R.id.tvLect3Name); tvLect3Prof = (TextView) rootView.findViewById(R.id.tvLect3Prof); tvLect4Name = (TextView) rootView.findViewById(R.id.tvLect4Name); tvLect4Prof = (TextView) rootView.findViewById(R.id.tvLect4Prof); tvLect5Name = (TextView) rootView.findViewById(R.id.tvLect5Name); tvLect5Prof = (TextView) rootView.findViewById(R.id.tvLect5Prof); Calendar c = Calendar.getInstance(); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); if (Calendar.MONDAY == dayOfWeek) { setUpMonday();/*from ww w. jav a2 s . c o m*/ } else if (Calendar.TUESDAY == dayOfWeek) { setUpTuesday(); } else if (Calendar.WEDNESDAY == dayOfWeek) { setUpWednesday(); } else if (Calendar.THURSDAY == dayOfWeek) { setUpThursday(); } else if (Calendar.FRIDAY == dayOfWeek) { setUpFriday(); } else if (Calendar.SATURDAY == dayOfWeek) { } else if (Calendar.SUNDAY == dayOfWeek) { } }
From source file:in.suraj.timetableswipe.SYFragment.java
private void init() { rgroup = (RadioGroup) rootView.findViewById(R.id.rbgrp); rbMon = (RadioButton) rootView.findViewById(R.id.rbMon); rbTue = (RadioButton) rootView.findViewById(R.id.rbTue); rbWed = (RadioButton) rootView.findViewById(R.id.rbWed); rbThur = (RadioButton) rootView.findViewById(R.id.rbThur); rbFri = (RadioButton) rootView.findViewById(R.id.rbFri); tvLect1Name = (TextView) rootView.findViewById(R.id.tvLect1Name); tvLect1Prof = (TextView) rootView.findViewById(R.id.tvLect1Prof); tvLect2Name = (TextView) rootView.findViewById(R.id.tvLect2Name); tvLect2Prof = (TextView) rootView.findViewById(R.id.tvLect2Prof); tvLect3Name = (TextView) rootView.findViewById(R.id.tvLect3Name); tvLect3Prof = (TextView) rootView.findViewById(R.id.tvLect3Prof); tvLect4Name = (TextView) rootView.findViewById(R.id.tvLect4Name); tvLect4Prof = (TextView) rootView.findViewById(R.id.tvLect4Prof); tvLect5Name = (TextView) rootView.findViewById(R.id.tvLect5Name); tvLect5Prof = (TextView) rootView.findViewById(R.id.tvLect5Prof); Calendar c = Calendar.getInstance(); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); if (Calendar.MONDAY == dayOfWeek) { setUpMonday();// w ww. j a v a 2 s . c om } else if (Calendar.TUESDAY == dayOfWeek) { setUpTuesday(); } else if (Calendar.WEDNESDAY == dayOfWeek) { setUpWednesday(); } else if (Calendar.THURSDAY == dayOfWeek) { setUpThursday(); } else if (Calendar.FRIDAY == dayOfWeek) { setUpFriday(); } else if (Calendar.SATURDAY == dayOfWeek) { } else if (Calendar.SUNDAY == dayOfWeek) { } }
From source file:com.binary_machinery.avalonschedule.view.schedule.SchedulePagerAdapter.java
private Calendar getWeekEnd(int position) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(m_minDate);/*from ww w .j a v a 2 s. c o m*/ calendar.add(Calendar.WEEK_OF_MONTH, position); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); calendar.set(Calendar.HOUR, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar; }
From source file:com.netflix.simianarmy.basic.BasicCalendar.java
/** * Load holidays.// w w w .j av a2 s . c om * * @param year * the year */ protected void loadHolidays(int year) { holidays.clear(); // these aren't all strictly holidays, but days when engineers will likely // not be in the office to respond to rampaging monkeys // new years, or closest work day holidays.add(workDayInYear(year, Calendar.JANUARY, 1)); // 3rd monday == MLK Day holidays.add(dayOfYear(year, Calendar.JANUARY, Calendar.MONDAY, 3)); // 3rd monday == Presidents Day holidays.add(dayOfYear(year, Calendar.FEBRUARY, Calendar.MONDAY, 3)); // last monday == Memorial Day holidays.add(dayOfYear(year, Calendar.MAY, Calendar.MONDAY, -1)); // 4th of July, or closest work day holidays.add(workDayInYear(year, Calendar.JULY, 4)); // first monday == Labor Day holidays.add(dayOfYear(year, Calendar.SEPTEMBER, Calendar.MONDAY, 1)); // second monday == Columbus Day holidays.add(dayOfYear(year, Calendar.OCTOBER, Calendar.MONDAY, 2)); // veterans day, Nov 11th, or closest work day holidays.add(workDayInYear(year, Calendar.NOVEMBER, 11)); // 4th thursday == Thanksgiving holidays.add(dayOfYear(year, Calendar.NOVEMBER, Calendar.THURSDAY, 4)); // 4th friday == "black friday", monkey goes shopping! holidays.add(dayOfYear(year, Calendar.NOVEMBER, Calendar.FRIDAY, 4)); // christmas eve holidays.add(dayOfYear(year, Calendar.DECEMBER, 24)); // christmas day holidays.add(dayOfYear(year, Calendar.DECEMBER, 25)); // day after christmas holidays.add(dayOfYear(year, Calendar.DECEMBER, 26)); // new years eve holidays.add(dayOfYear(year, Calendar.DECEMBER, 31)); // mark the holiday set with the year, so on Jan 1 it will automatically // recalculate the holidays for next year holidays.add(year); }
From source file:org.openvpms.web.echo.date.RelativeDateParser.java
/** * Parses a date relative to the specified date. * * @param source the relative date string * @param date the date// w w w. j a v a2 s . co m * @return the relative date, or <code>null</code> if the source is invalid */ public Date parse(String source, Date date) { if (StringUtils.isEmpty(source)) { return null; } Matcher matcher = pattern.matcher(source.toLowerCase()); Calendar calendar; calendar = new GregorianCalendar(); calendar.setTime(date); int start = 0; boolean neg = false; boolean first = true; while (start < source.length() && matcher.find(start)) { if (start != matcher.start()) { return null; } String valueGroup = matcher.group(1); int value = Integer.parseInt(valueGroup); if (first) { if (value < 0) { neg = true; } first = false; } else if (value >= 0 && valueGroup.charAt(0) != '+' && neg) { // if there is a leading sign, and the current value has no explicit +, it propagates to all // other patterns where no sign is specified value = -value; } String field = matcher.group(2); String se = matcher.group(3); // get any s=start or e=end if (field.equals("d")) { calendar.add(Calendar.DAY_OF_MONTH, value); // se ignored if day } else if (field.equals("m")) { calendar.add(Calendar.MONTH, value); if (se.equals("s")) { calendar.set(Calendar.DAY_OF_MONTH, 1); // set 1st of month } else if (se.equals("e")) { calendar.set(Calendar.DAY_OF_MONTH, 1); // set 1st of month calendar.add(Calendar.MONTH, 1); // go to next month calendar.add(Calendar.DAY_OF_MONTH, -1); // back one to to get end of month } } else if (field.equals("w")) { calendar.add(Calendar.WEEK_OF_YEAR, value); if (se.equals("s")) { calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); //set Monday } else if (se.equals("e")) { calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); //set Friday } } else if (field.equals("q")) { // quarter calendar.add(Calendar.MONTH, 3 * value); // move by 3 month blocks if (se.equals("s")) { calendar.set(Calendar.DAY_OF_MONTH, 1); // set 1st of month int k = calendar.get(Calendar.MONTH); // get month (0 = Jan) k = (k / 3) * 3; // get month number at start of quarter (0,3,6,9) calendar.set(Calendar.MONTH, k); // set that month } else if (se.equals("e")) { calendar.set(Calendar.DAY_OF_MONTH, 1); // set 1st of month int k = calendar.get(Calendar.MONTH); // get month (0 = Jan) k = (k / 3) * 3; // get month number at start of quarter (0,3,6,9) calendar.set(Calendar.MONTH, k); // set that month calendar.add(Calendar.MONTH, 3); // go to next quarter calendar.add(Calendar.DAY_OF_MONTH, -1); // back one day to to get end of quarter } } else { calendar.add(Calendar.YEAR, value); if (se.equals("s")) { calendar.set(Calendar.DAY_OF_MONTH, 1); // set 1st of month calendar.set(Calendar.MONTH, Calendar.JANUARY); // set January } else if (se.equals("e")) { calendar.set(Calendar.DAY_OF_MONTH, 1); // set 1st of month calendar.set(Calendar.MONTH, Calendar.JANUARY); // set January calendar.add(Calendar.YEAR, 1); // go to next year calendar.add(Calendar.DAY_OF_MONTH, -1); // back one to to get 31 Dec } } start = matcher.end(); } return (start == source.length()) ? calendar.getTime() : null; }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Every monday from June 1 2008 to July 1 2008. * //from w ww . j av a 2 s . c om * @throws Exception */ @Test public void testCreateBlocksExample1() throws Exception { SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("10:30 AM", "1:00 PM", "M", dateFormat.parse("20080601"), dateFormat.parse("20080701")); // there are 5 mondays in between June 1 2008 and July 1 2008 assertEquals(5, blocks.size()); for (AvailableBlock block : blocks) { Calendar cal = Calendar.getInstance(); cal.setTime(block.getStartTime()); assertEquals(10, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(30, cal.get(Calendar.MINUTE)); cal.setTime(block.getEndTime()); assertEquals(13, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(0, cal.get(Calendar.MINUTE)); assertEquals(Calendar.MONDAY, cal.get(Calendar.DAY_OF_WEEK)); assertEquals(1, block.getVisitorLimit()); } blocks = AvailableBlockBuilder.createBlocks("10:30 AM", "1:00 PM", "M", dateFormat.parse("20080601"), dateFormat.parse("20080701"), 5); // there are 5 mondays in between June 1 2008 and July 1 2008 assertEquals(5, blocks.size()); for (AvailableBlock block : blocks) { assertEquals(150, block.getDurationInMinutes()); Calendar cal = Calendar.getInstance(); cal.setTime(block.getStartTime()); assertEquals(10, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(30, cal.get(Calendar.MINUTE)); cal.setTime(block.getEndTime()); assertEquals(13, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(0, cal.get(Calendar.MINUTE)); assertEquals(Calendar.MONDAY, cal.get(Calendar.DAY_OF_WEEK)); assertEquals(5, block.getVisitorLimit()); } }
From source file:com.siblinks.ws.service.impl.VideoSubscriptionsServiceImpl.java
/** * {@inheritDoc}/*from w w w .j a va 2 s . c o m*/ */ @Override @RequestMapping(value = "/getListVideoSubscription", method = RequestMethod.GET) public ResponseEntity<Response> getListVideoSubscription(@RequestParam("userId") final String userId, @RequestParam("subjectId") final String subjectId) { SimpleResponse response = null; try { String method = "getListVideoSubscription()"; logger.debug(method + " start"); String entityName = null; List<Object> readObject = null; String currentDate = ""; String firstDayOfCurrentWeek = ""; Object[] queryParams = null; Map<String, List<Object>> mapListVideo = new HashMap<String, List<Object>>(); try { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); Date firstDayOfTheWeek = cal.getTime(); currentDate = DateUtil.date2YYYYMMDD000000(new Date()); firstDayOfCurrentWeek = DateUtil.date2YYYYMMDD000000(firstDayOfTheWeek); if ("-2".equals(subjectId)) { entityName = SibConstants.SqlMapper.SQL_SIB_GET_ALL_VIDEO_SUBSCRIPTION; queryParams = new Object[] { userId, currentDate, userId, firstDayOfCurrentWeek, currentDate, userId, firstDayOfCurrentWeek }; readObject = dao.readObjects(entityName, queryParams); } else { // Get child category by subjectId List<Map<String, Object>> readObjectNoCondition = dao .readObjectNoCondition(SibConstants.SqlMapper.SQL_GET_ALL_CATEGORY_TOPIC); MapSqlParameterSource params = new MapSqlParameterSource(); String allChildCategory = CommonUtil.getAllChildCategory(subjectId, readObjectNoCondition); if (!StringUtil.isNull(allChildCategory)) { List<Integer> listChildCategory = new ArrayList<Integer>(); String[] arrChildCategory = allChildCategory.split(","); for (String string : arrChildCategory) { listChildCategory.add(Integer.parseInt(string)); } params.addValue("subjectID", listChildCategory); } params.addValue("userID", userId); params.addValue("currentDate", currentDate); params.addValue("firstDayOfCurrentWeek", firstDayOfCurrentWeek); entityName = SibConstants.SqlMapper.SQL_SIB_GET_ALL_VIDEO_SUBSCRIPTION_BY_CATEGORY; readObject = dao.readObjectNamedParameter(entityName, params); } if (readObject == null) { readObject = new ArrayList<Object>(); } JSONArray jsonAraay = new JSONArray(readObject); for (int i = 0; i < jsonAraay.length(); i++) { JSONObject jsonObj = jsonAraay.getJSONObject(i); ObjectMapper mapper = new ObjectMapper(); Object obj = mapper.readValue(jsonObj.toString(), Object.class); addMapVideo(mapListVideo, jsonObj.get("flag").toString(), obj); } } catch (ParseException | IOException e) { logger.error(method + " - error : " + e.getMessage()); } response = new SimpleResponse("true", mapListVideo); } catch (Exception e) { e.printStackTrace(); response = new SimpleResponse(SibConstants.FAILURE, "video", "getListVideoSubscription", e.getMessage()); } return new ResponseEntity<Response>(response, HttpStatus.OK); }