List of usage examples for java.util Calendar WEEK_OF_MONTH
int WEEK_OF_MONTH
To view the source code for java.util Calendar WEEK_OF_MONTH.
Click Source Link
get
and set
indicating the week number within the current month. From source file:org.exoplatform.services.jcr.ext.classify.impl.DateTimeClassifyPlugin.java
/** * Gets the date time structured./*from w ww .j av a2 s . c o m*/ * * @param templDateTime the templ date time * @param calendar the calendar * * @return the date time structured */ private String getDateTimeStructured(String templDateTime, Calendar calendar) { int year = calendar.get(Calendar.YEAR), month = calendar.get(Calendar.MONTH) + 1, woy = calendar.get(Calendar.WEEK_OF_YEAR), wom = calendar.get(Calendar.WEEK_OF_MONTH), dom = calendar.get(Calendar.DAY_OF_MONTH), dow = calendar.get(Calendar.DAY_OF_WEEK), startYear = startDateTime.get(Calendar.YEAR), startMonth = startDateTime.get(Calendar.MONTH); switch (incrementType) { case 'Y': int n = (year - startYear) / (increment + 1); year = n * (increment + 1) + startYear; break; case 'M': if (year != startYear) startMonth = 1; int m = (month - startMonth) / (increment + 1); month = m * (increment + 1) + startMonth; break; default: break; } templDateTime = templDateTime.replace("YYYY", Integer.toString(year)).replace("MM", Integer.toString(month)) .replace("WW", Integer.toString(woy)).replace("ww", Integer.toString(wom)) .replace("DD", Integer.toString(dom)).replace("dd", Integer.toString(dow)); String expr = templDateTime.substring(templDateTime.indexOf("{") + 1, templDateTime.indexOf("}")); templDateTime = templDateTime.replace(expr, operateExpression(expr)).replace("#", "").replace("{", "") .replace("}", ""); return templDateTime; }
From source file:com.glaf.core.web.springmvc.WorkCalendarController.java
/** * /*from w ww . java 2s . c om*/ * * @param request * @param modelMap * @return */ @RequestMapping("/showCalendar") public ModelAndView showCalendar(HttpServletRequest request, ModelMap modelMap) { Calendar cal = Calendar.getInstance(); int month = RequestUtils.getIntParameter(request, "month", cal.get(Calendar.MONTH)); int year = RequestUtils.getIntParameter(request, "year", cal.get(Calendar.YEAR)); cal.set(Calendar.MONTH, month); // cal.set(Calendar.YEAR, year); // cal.setFirstDayOfWeek(Calendar.SUNDAY); cal.set(Calendar.DAY_OF_MONTH, 1); logger.info("month:" + month); int firstIndex = cal.get(Calendar.DAY_OF_WEEK) - 1; // logger.info("firstIndex:" + firstIndex); int maxIndex = cal.getActualMaximum(Calendar.DAY_OF_MONTH);// logger.info("maxIndex:" + maxIndex); int weeks = Calendar.WEEK_OF_MONTH;// cal.set(Calendar.DATE, 1);// 1? if (cal.get(Calendar.DAY_OF_WEEK) == 7) weeks += 1; logger.info("day of week:" + cal.get(Calendar.DAY_OF_WEEK)); logger.info("weeks:" + weeks); String days[] = new String[42]; for (int i = 0; i < 42; i++) { days[i] = ""; } for (int i = 0; i < maxIndex; i++) { days[firstIndex + i] = String.valueOf(i + 1); } List<Integer> list = workCalendarService.getWorkDateList(year, month + 1); if (list == null) { list = new java.util.ArrayList<Integer>(); } request.setAttribute("list", list); request.setAttribute("year", String.valueOf(year)); request.setAttribute("month", String.valueOf(month)); request.setAttribute("weeks", String.valueOf(weeks)); request.setAttribute("days", days); String x_view = ViewProperties.getString("calendar.showCalendar"); if (StringUtils.isNotEmpty(x_view)) { return new ModelAndView(x_view, modelMap); } return new ModelAndView("/modules/sys/calendar/calendar", modelMap); }
From source file:org.eclipse.wb.internal.swing.model.property.editor.models.spinner.SpinnerModelPropertyEditor.java
/** * @return the the name of step from {@link Calendar} fields. *//*from w w w. j a v a 2s .co m*/ private static String getDateStep(int calendarField) { switch (calendarField) { case Calendar.ERA: return "ERA"; case Calendar.YEAR: return "YEAR"; case Calendar.MONTH: return "MONTH"; case Calendar.WEEK_OF_YEAR: return "WEEK_OF_YEAR"; case Calendar.WEEK_OF_MONTH: return "WEEK_OF_MONTH"; case Calendar.DAY_OF_MONTH: return "DAY_OF_MONTH"; case Calendar.DAY_OF_YEAR: return "DAY_OF_YEAR"; case Calendar.DAY_OF_WEEK: return "DAY_OF_WEEK"; case Calendar.DAY_OF_WEEK_IN_MONTH: return "DAY_OF_WEEK_IN_MONTH"; case Calendar.AM_PM: return "AM_PM"; case Calendar.HOUR: return "HOUR"; case Calendar.HOUR_OF_DAY: return "HOUR_OF_DAY"; case Calendar.MINUTE: return "MINUTE"; case Calendar.SECOND: return "SECOND"; case Calendar.MILLISECOND: return "MILLISECOND"; default: return null; } }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSourceTestCase.java
public void testBadTimeResolution() { Calendar c = Calendar.getInstance(); Map<String, Object> params = new HashMap<String, Object>(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 5);/*from w w w . j ava 2 s. c o m*/ List<TimePoint> series = new LinkedList<TimePoint>(); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.MINUTE, 12); series.add(new TimePoint(c.getTime(), 8, params)); Map<String, Object> seriesParams = new HashMap<String, Object>(); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.HOURLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } series.clear(); for (int i = 1; i < 5; i += 1) { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.DAY_OF_WEEK, i); series.add(new TimePoint(c.getTime(), i, params)); } c.set(Calendar.DAY_OF_WEEK, 2); c.set(Calendar.HOUR_OF_DAY, 3); series.add(new TimePoint(c.getTime(), 2, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.HOURLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through okay } catch (GraphException e) { fail(); } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.DAY_OF_WEEK, 3); series.add(new TimePoint(c.getTime(), 12, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a daily resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for weekly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); series.add(new TimePoint(c.getTime(), 5, params)); c.set(Calendar.WEEK_OF_MONTH, 3); series.add(new TimePoint(c.getTime(), 8, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a weekly resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.MONTHLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for monthly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); c.set(Calendar.MONTH, 2); series.add(new TimePoint(c.getTime(), 8, params)); c.set(Calendar.MONTH, 3); series.add(new TimePoint(c.getTime(), 12, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.MONTHLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a monthly resolution } catch (GraphException e) { fail(); } seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.YEARLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); fail(); } catch (GraphException e) { // expected failure for yearly } series.clear(); c.set(Calendar.DAY_OF_WEEK, 1); c.set(Calendar.WEEK_OF_MONTH, 2); c.set(Calendar.MONTH, 2); series.add(new TimePoint(c.getTime(), 8, params)); c.add(Calendar.YEAR, 1); series.add(new TimePoint(c.getTime(), 18, params)); seriesParams.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.YEARLY); try { new JFreeChartTimeSeriesGraphSource(Arrays.asList(new DefaultTimeSeries(series, seriesParams)), params); // this should go through on a yearly resolution } catch (GraphException e) { fail(); } }
From source file:com.weekcalendar.sample.Sample.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sample);/*from ww w. j a va2 s. c om*/ mDateSelectedTv = (TextView) findViewById(R.id.txt_date); mWeekCalendarFragment = (WeekCalendarFragment) getSupportFragmentManager() .findFragmentByTag(WeekCalendarFragment.class.getSimpleName()); if (mWeekCalendarFragment == null) { mWeekCalendarFragment = new WeekCalendarFragment(); Bundle args = new Bundle(); /* Must add this attribute if using ARGUMENT_NOW_BACKGROUND or ARGUMENT_SELECTED_DATE_BACKGROUND*/ args.putString(WeekCalendarFragment.ARGUMENT_PACKAGE_NAME, getApplicationContext().getPackageName()); /* IMPORTANT: Customization for week calender fragment*/ //------------------------------------------------------------------------------------------------// //sets background drawable to the selected dates - null to disable args.putString(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_BACKGROUND, "bg_select"); // args.putString(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_BACKGROUND, null);// disable //Sets background color to calender args.putInt(WeekCalendarFragment.ARGUMENT_CALENDER_BACKGROUND_COLOR, ContextCompat.getColor(this, R.color.md_deep_purple_500)); // Sets text color for the selected date // args.putInt(WeekCalendarFragment.ARGUMENT_SELECTED_DATE_HIGHLIGHT_COLOR // , ContextCompat.getColor(this, R.color.md_pink_200)); // Adds N weeks from the current week (53 or 52 week is one year) args.putInt(WeekCalendarFragment.ARGUMENT_WEEK_COUNT, 1000); // Cancels date picker args.putBoolean(WeekCalendarFragment.ARGUMENT_DISPLAY_DATE_PICKER, false); // Sets background resource drawable to nowView // args.putString(WeekCalendarFragment.ARGUMENT_NOW_BACKGROUND,"bg_now"); // Sets text color to the current date // args.putInt(WeekCalendarFragment.ARGUMENT_CURRENT_DATE_TEXT_COLOR // , ContextCompat.getColor(this, R.color.md_green_500)); // Sets color to the primary views (Month name and dates) // args.putInt(WeekCalendarFragment.ARGUMENT_PRIMARY_TEXT_COLOR // , ContextCompat.getColor(this,R.color.md_yellow_500)); // Sets text size of dates // args.putInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_SIZE, 18); // // Sets typeface style of date texts // args.putInt(WeekCalendarFragment.ARGUMENT_DAY_TEXT_STYLE, Typeface.BOLD_ITALIC); // // Sets color to the secondary views (now view and week names) /* args.putInt(WeekCalendarFragment.ARGUMENT_SECONDARY_TEXT_COLOR , ContextCompat.getColor(this,R.color.md_green_500));*/ // Sets typeface size of secondary text views (now view and week names) // args.putInt(WeekCalendarFragment.ARGUMENT_SECONDARY_TEXT_SIZE, 18); // Sets typeface style of secondary text views (now view and week names) // args.putInt(WeekCalendarFragment.ARGUMENT_SECONDARY_TEXT_STYLE, Typeface.ITALIC); // Picks between three or one date header letters ex. "Sun" or "S" // two options: // 1. WeekCalendarOptions.DAY_HEADER_LENGTH_THREE_LETTERS // 2. WeekCalendarOptions.DAY_HEADER_LENGTH_ONE_LETTER args.putString(WeekCalendarFragment.ARGUMENT_DAY_HEADER_LENGTH, WeekCalendarOptions.DAY_HEADER_LENGTH_THREE_LETTERS); // Days that have events ArrayList<Calendar> eventDays = new ArrayList<>(); eventDays.add(Calendar.getInstance()); eventDays.add(Calendar.getInstance()); eventDays.add(Calendar.getInstance()); eventDays.get(1).add(Calendar.DAY_OF_MONTH, 1); eventDays.get(2).add(Calendar.WEEK_OF_MONTH, 1); args.putSerializable(WeekCalendarFragment.ARGUMENT_EVENT_DAYS, eventDays); // Sets the color of event dots // 5 options: // 1. WeekCalendarOptions.EVENT_COLOR_YELLOW, 2. WeekCalendarOptions.EVENT_COLOR_BLUE // 3. WeekCalendarOptions.EVENT_COLOR_GREEN, 4. WeekCalendarOptions.EVENT_COLOR_RED // 5. WeekCalendarOptions.EVENT_COLOR_WHITE args.putString(WeekCalendarFragment.ARGUMENT_EVENT_COLOR, WeekCalendarOptions.EVENT_COLOR_YELLOW); //------------------------------------------------------------------------------------------------// mWeekCalendarFragment.setArguments(args); // Attach to the activity FragmentTransaction t = getSupportFragmentManager().beginTransaction(); t.replace(R.id.container, mWeekCalendarFragment, WeekCalendarFragment.class.getSimpleName()); t.commit(); } CalenderListener listener = new CalenderListener() { @Override public void onSelectPicker() { //User can use any type of pickers here the below picker is only Just a example DatePickerDialog .newInstance(Sample.this, Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) .show(getFragmentManager(), "datePicker"); } @Override public void onSelectDate(LocalDateTime mSelectedDate) { //callback when a date is selcted mDateSelectedTv.setText("" + mSelectedDate.getDayOfMonth() + "-" + mSelectedDate.getMonthOfYear() + "-" + mSelectedDate.getYear()); } }; //setting the listener mWeekCalendarFragment.setCalenderListener(listener); mWeekCalendarFragment.setPreSelectedDate(Calendar.getInstance()); }
From source file:org.callimachusproject.sql.SqlTupleResult.java
private Value value(int col) throws SQLException { int type = md.getColumnType(col); String str = rs.getString(col); if (str == null) return null; switch (type) { case java.sql.Types.NULL: return null; case java.sql.Types.DATALINK: return vf.createURI(str); case java.sql.Types.BINARY: case java.sql.Types.VARBINARY: case java.sql.Types.BIT: case java.sql.Types.BLOB: case java.sql.Types.LONGVARBINARY: case java.sql.Types.JAVA_OBJECT: return vf.createLiteral(Hex.encodeHexString(rs.getBytes(col)), XMLSchema.HEXBINARY); case java.sql.Types.DECIMAL: case java.sql.Types.NUMERIC: return vf.createLiteral(str, XMLSchema.DECIMAL); case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: case java.sql.Types.INTEGER: case java.sql.Types.BIGINT: return vf.createLiteral(str, XMLSchema.INTEGER); case java.sql.Types.DOUBLE: case java.sql.Types.FLOAT: case java.sql.Types.REAL: return vf.createLiteral(str, XMLSchema.DOUBLE); case java.sql.Types.BOOLEAN: return vf.createLiteral(rs.getBoolean(col)); case java.sql.Types.DATE: GregorianCalendar date = new GregorianCalendar(); date.setTime(rs.getDate(col));//from w ww . j a va 2s. co m date.clear(Calendar.AM_PM); date.clear(Calendar.HOUR); date.clear(Calendar.HOUR_OF_DAY); date.clear(Calendar.MINUTE); date.clear(Calendar.SECOND); date.clear(Calendar.MILLISECOND); return vf.createLiteral(df.newXMLGregorianCalendar(date)); case java.sql.Types.TIME: GregorianCalendar time = new GregorianCalendar(); time.setTime(rs.getTime(col)); time.clear(Calendar.ERA); time.clear(Calendar.YEAR); time.clear(Calendar.MONTH); time.clear(Calendar.WEEK_OF_YEAR); time.clear(Calendar.WEEK_OF_MONTH); time.clear(Calendar.DATE); time.clear(Calendar.DAY_OF_MONTH); time.clear(Calendar.DAY_OF_YEAR); time.clear(Calendar.DAY_OF_WEEK); time.clear(Calendar.DAY_OF_WEEK_IN_MONTH); return vf.createLiteral(df.newXMLGregorianCalendar(time)); case java.sql.Types.TIMESTAMP: return vf.createLiteral(rs.getTimestamp(col)); case java.sql.Types.SQLXML: return vf.createLiteral(str, RDF.XMLLITERAL); case java.sql.Types.ARRAY: case java.sql.Types.CHAR: case java.sql.Types.CLOB: case java.sql.Types.DISTINCT: case java.sql.Types.LONGNVARCHAR: case java.sql.Types.NCHAR: case java.sql.Types.NCLOB: case java.sql.Types.NVARCHAR: case java.sql.Types.OTHER: case java.sql.Types.REF: case java.sql.Types.ROWID: case java.sql.Types.STRUCT: case java.sql.Types.VARCHAR: default: return vf.createLiteral(str); } }
From source file:org.apache.kylin.rest.service.JobService.java
private long getTimeStartInMillis(Calendar calendar, JobTimeFilterEnum timeFilter) { Message msg = MsgPicker.getMsg();/*from www.ja va2s . c o m*/ switch (timeFilter) { case LAST_ONE_DAY: calendar.add(Calendar.DAY_OF_MONTH, -1); return calendar.getTimeInMillis(); case LAST_ONE_WEEK: calendar.add(Calendar.WEEK_OF_MONTH, -1); return calendar.getTimeInMillis(); case LAST_ONE_MONTH: calendar.add(Calendar.MONTH, -1); return calendar.getTimeInMillis(); case LAST_ONE_YEAR: calendar.add(Calendar.YEAR, -1); return calendar.getTimeInMillis(); case ALL: return 0; default: throw new BadRequestException(String.format(msg.getILLEGAL_TIME_FILTER(), timeFilter)); } }
From source file:com.stratelia.webactiv.almanach.control.AlmanachSessionController.java
/** * Moves the window in time to the next calendar view according to the current view mode. *//*from w ww . j a v a2s. co m*/ public void nextView() { switch (viewMode) { case MONTHLY: currentDay.add(Calendar.MONTH, 1); break; case WEEKLY: currentDay.add(Calendar.WEEK_OF_MONTH, 1); break; } }
From source file:org.sakaiproject.util.CalendarUtil.java
/** * Set the calendar to the next week, and return this. * @return the next week. */ public void setNextWeek() { m_calendar.set(Calendar.WEEK_OF_MONTH, getWeekOfMonth() + 1); }
From source file:com.stratelia.webactiv.almanach.control.AlmanachSessionController.java
/** * Moves the window in time to the previous calendar view according to the current view mode. *///from w ww . j a v a 2 s. com public void previousView() { switch (viewMode) { case MONTHLY: currentDay.add(Calendar.MONTH, -1); break; case WEEKLY: currentDay.add(Calendar.WEEK_OF_MONTH, -1); break; } }