List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:org.exoplatform.addon.pulse.service.ws.RestActivitiesStatistic.java
private ChartData buildStatisticByFilter(String maxColumn, String filter, Date fromDate) throws Exception { int totalDataCoulumn = 5; try {//from w w w . j a v a 2s .c o m totalDataCoulumn = Integer.parseInt(maxColumn); } catch (Exception e) { //do nothing } if (filter.equalsIgnoreCase(FILTER_BY_DAY)) { Calendar calendar = Calendar.getInstance(); calendar.setTime(fromDate); calendar.add(Calendar.DATE, totalDataCoulumn - 1); Date toDate = calendar.getTime(); List<ActivityStatisticBean> list = service.getListActivityStatisticByDate(fromDate, toDate); TreeMap<Date, ActivityStatisticBean> dateData = new TreeMap<Date, ActivityStatisticBean>(); //init empty-data for (int i = 0; i < totalDataCoulumn; i++) { calendar.clear(); calendar.setTime(fromDate); calendar.add(Calendar.DATE, i); Date nextDate = parseDate(partString(calendar.getTime(), "dd/MM/yyyy"), "dd/MM/yyyy"); dateData.put(nextDate, null); } List<String> listTitle = new ArrayList<String>(); List<Long> newUsersData = new ArrayList<Long>(); List<Long> loginCountData = new ArrayList<Long>(); List<Long> forumActiveUsersData = new ArrayList<Long>(); List<Long> newForumPostsData = new ArrayList<Long>(); List<Long> userConnectionData = new ArrayList<Long>(); List<Long> socialPostData = new ArrayList<Long>(); List<Long> emailNotificationData = new ArrayList<Long>(); ChartData chartData = new ChartData(); for (ActivityStatisticBean bean : list) { dateData.put(parseDate(partString(bean.getCreatedDate(), "dd/MM/yyyy"), "dd/MM/yyyy"), bean); } for (Date key : dateData.keySet()) { ActivityStatisticBean bean = dateData.get(key); if (bean != null) { listTitle.add(partString(bean.getCreatedDate(), "dd-MM-yyyy")); newUsersData.add(bean.getNewUserToday()); loginCountData.add(bean.getLoginCountToday()); forumActiveUsersData.add(bean.getForumActiveUserToday()); newForumPostsData.add(bean.getForumPostToday()); userConnectionData.add(bean.getUserConnectionCountToday()); socialPostData.add(bean.getSocialPostCountToday()); emailNotificationData.add(bean.getEmailNotificationCountToday()); } else { listTitle.add(partString(key, "dd-MM-yyyy")); newUsersData.add(0L); loginCountData.add(0L); forumActiveUsersData.add(0L); newForumPostsData.add(0L); userConnectionData.add(0L); socialPostData.add(0L); emailNotificationData.add(0L); } } chartData.setListTitle(listTitle); chartData.setNewUsersData(newUsersData); chartData.setLoginCountData(loginCountData); chartData.setForumActiveUsersData(forumActiveUsersData); chartData.setNewForumPostsData(newForumPostsData); chartData.setUserConnectionData(userConnectionData); chartData.setSocialPostData(socialPostData); chartData.setEmailNotificationData(emailNotificationData); return chartData; } if (filter.equalsIgnoreCase(FILTER_BY_WEEK)) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(fromDate); calendar.add(Calendar.WEEK_OF_YEAR, totalDataCoulumn - 1); Date nextFewWeek = calendar.getTime(); List<ActivityStatisticBean> list = service.getListActivityStatisticByDate(fromDate, nextFewWeek); List<String> listTitle = new ArrayList<String>(); List<Long> newUsersData = new ArrayList<Long>(); List<Long> loginCountData = new ArrayList<Long>(); List<Long> forumActiveUsersData = new ArrayList<Long>(); List<Long> newForumPostsData = new ArrayList<Long>(); List<Long> userConnectionData = new ArrayList<Long>(); List<Long> socialPostData = new ArrayList<Long>(); List<Long> emailNotificationData = new ArrayList<Long>(); ChartData chartData = new ChartData(); TreeMap<String, List<ActivityStatisticBean>> weekData = new TreeMap<String, List<ActivityStatisticBean>>(); //init empty-data for (int i = 0; i < totalDataCoulumn; i++) { calendar.clear(); calendar.setTime(fromDate); calendar.add(Calendar.WEEK_OF_YEAR, i); int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); int monthIndex = calendar.get(Calendar.MONTH); if (monthIndex == Calendar.DECEMBER && weekIndex == 1) weekIndex = 53; int year = calendar.get(Calendar.YEAR); //goto begin of week calendar.clear(); calendar.set(Calendar.WEEK_OF_YEAR, weekIndex); calendar.set(Calendar.YEAR, year); //goto end of week calendar.add(Calendar.DATE, 6); String week = ""; if (calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.WEEK_OF_YEAR) == 1) { week = 53 + "-" + calendar.get(Calendar.YEAR); } else { week = calendar.get(Calendar.WEEK_OF_YEAR) + "-" + calendar.get(Calendar.YEAR); } week = week.length() < 7 ? calendar.get(Calendar.YEAR) + "-" + "0" + week : calendar.get(Calendar.YEAR) + "-" + week; weekData.put(week, new ArrayList<ActivityStatisticBean>()); } for (ActivityStatisticBean bean : list) { calendar.clear(); calendar.setTime(bean.getCreatedDate()); int weekIndex = calendar.get(Calendar.WEEK_OF_YEAR); int monthIndex = calendar.get(Calendar.MONTH); if (monthIndex == Calendar.DECEMBER && weekIndex == 1) weekIndex = 53; int year = calendar.get(Calendar.YEAR); //goto begin of week calendar.clear(); calendar.set(Calendar.WEEK_OF_YEAR, weekIndex); calendar.set(Calendar.YEAR, year); //goto end of week calendar.add(Calendar.DATE, 6); String week = ""; if (calendar.get(Calendar.MONTH) == Calendar.DECEMBER && calendar.get(Calendar.WEEK_OF_YEAR) == 1) { week = 53 + "-" + calendar.get(Calendar.YEAR); } else { week = calendar.get(Calendar.WEEK_OF_YEAR) + "-" + calendar.get(Calendar.YEAR); } week = week.length() < 7 ? calendar.get(Calendar.YEAR) + "-" + "0" + week : calendar.get(Calendar.YEAR) + "-" + week; if (weekData.containsKey(week)) { List<ActivityStatisticBean> listValueOfNode = weekData.get(week); listValueOfNode.add(bean); } else { List<ActivityStatisticBean> listValueOfNode = new ArrayList<ActivityStatisticBean>(); listValueOfNode.add(bean); weekData.put(week, listValueOfNode); } } for (String key : weekData.keySet()) { List<ActivityStatisticBean> listValueOfNode = weekData.get(key); Long weekNewUsersValue = 0L; Long weekLoginCountValue = 0L; Long weekForumActiveUsersValue = 0L; Long weekNewForumPostsValue = 0L; Long weekUserConnectionValue = 0L; Long weekSocialPostsValue = 0L; Long weekEmailNotificationValue = 0L; for (ActivityStatisticBean obj : listValueOfNode) { weekNewUsersValue = weekNewUsersValue + obj.getNewUserToday(); weekLoginCountValue = weekLoginCountValue + obj.getLoginCountToday(); weekForumActiveUsersValue = weekForumActiveUsersValue + obj.getForumActiveUserToday(); weekNewForumPostsValue = weekNewForumPostsValue + obj.getForumPostToday(); weekUserConnectionValue = weekUserConnectionValue + obj.getUserConnectionCountToday(); weekSocialPostsValue = weekSocialPostsValue + obj.getSocialPostCountToday(); weekEmailNotificationValue = weekEmailNotificationValue + obj.getEmailNotificationCountToday(); } String weekTitle = "W" + key.substring(5, key.length()); listTitle.add(weekTitle); newUsersData.add(weekNewUsersValue); loginCountData.add(weekLoginCountValue); forumActiveUsersData.add( weekForumActiveUsersValue > 0 ? (Long) (weekForumActiveUsersValue / listValueOfNode.size()) : 0L); newForumPostsData.add(weekNewForumPostsValue); userConnectionData.add(weekUserConnectionValue); socialPostData.add(weekSocialPostsValue); emailNotificationData.add(weekEmailNotificationValue); } chartData.setListTitle(listTitle); chartData.setNewUsersData(newUsersData); chartData.setLoginCountData(loginCountData); chartData.setForumActiveUsersData(forumActiveUsersData); chartData.setNewForumPostsData(newForumPostsData); chartData.setUserConnectionData(userConnectionData); chartData.setSocialPostData(socialPostData); chartData.setEmailNotificationData(emailNotificationData); return chartData; } if (filter.equalsIgnoreCase(FILTER_BY_MONTH)) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(fromDate); calendar.add(Calendar.MONTH, totalDataCoulumn - 1); Date nextFewMonth = calendar.getTime(); List<ActivityStatisticBean> list = service.getListActivityStatisticByDate(fromDate, nextFewMonth); List<String> listTitle = new ArrayList<String>(); List<Long> newUsersData = new ArrayList<Long>(); List<Long> loginCountData = new ArrayList<Long>(); List<Long> forumActiveUsersData = new ArrayList<Long>(); List<Long> newForumPostsData = new ArrayList<Long>(); List<Long> userConnectionData = new ArrayList<Long>(); List<Long> socialPostData = new ArrayList<Long>(); List<Long> emailNotificationData = new ArrayList<Long>(); ChartData chartData = new ChartData(); TreeMap<String, List<ActivityStatisticBean>> monthData = new TreeMap<String, List<ActivityStatisticBean>>(); //init empty-data for (int i = 0; i < totalDataCoulumn; i++) { calendar.clear(); calendar.setTime(fromDate); calendar.add(Calendar.MONTH, i); String month = calendar.get(Calendar.YEAR) + "-" + partString(calendar.getTime(), "MM") + "-" + partString(calendar.getTime(), "MMM") + "-" + calendar.get(Calendar.YEAR); //get name of Month monthData.put(month, new ArrayList<ActivityStatisticBean>()); } for (ActivityStatisticBean bean : list) { calendar.clear(); calendar.setTime(bean.getCreatedDate()); String month = calendar.get(Calendar.YEAR) + "-" + partString(calendar.getTime(), "MM") + "-" + partString(calendar.getTime(), "MMM") + "-" + calendar.get(Calendar.YEAR); //get name of Month if (monthData.containsKey(month)) { List<ActivityStatisticBean> listValueOfNode = monthData.get(month); listValueOfNode.add(bean); } else { List<ActivityStatisticBean> listValueOfNode = new ArrayList<ActivityStatisticBean>(); listValueOfNode.add(bean); monthData.put(month, listValueOfNode); } } for (String key : monthData.keySet()) { List<ActivityStatisticBean> listValueOfNode = monthData.get(key); Long monthNewUsersValue = 0L; Long monthLoginCountValue = 0L; Long monthForumActiveUsersValue = 0L; Long monthNewForumPostsValue = 0L; Long monthUserConnectionValue = 0L; Long monthSocialPostsValue = 0L; Long monthEmailNotificationValue = 0L; for (ActivityStatisticBean obj : listValueOfNode) { monthNewUsersValue = monthNewUsersValue + obj.getNewUserToday(); monthLoginCountValue = monthLoginCountValue + obj.getLoginCountToday(); monthForumActiveUsersValue = monthForumActiveUsersValue + obj.getForumActiveUserToday(); monthNewForumPostsValue = monthNewForumPostsValue + obj.getForumPostToday(); monthUserConnectionValue = monthUserConnectionValue + obj.getUserConnectionCountToday(); monthSocialPostsValue = monthSocialPostsValue + obj.getSocialPostCountToday(); monthEmailNotificationValue = +monthEmailNotificationValue + obj.getEmailNotificationCountToday(); } listTitle.add(key.substring(8, key.length())); newUsersData.add(monthNewUsersValue); loginCountData.add(monthLoginCountValue); forumActiveUsersData.add(monthForumActiveUsersValue > 0 ? (Long) (monthForumActiveUsersValue / listValueOfNode.size()) : 0L); newForumPostsData.add(monthNewForumPostsValue); userConnectionData.add(monthUserConnectionValue); socialPostData.add(monthSocialPostsValue); emailNotificationData.add(monthEmailNotificationValue); } chartData.setListTitle(listTitle); chartData.setNewUsersData(newUsersData); chartData.setLoginCountData(loginCountData); chartData.setForumActiveUsersData(forumActiveUsersData); chartData.setNewForumPostsData(newForumPostsData); chartData.setUserConnectionData(userConnectionData); chartData.setSocialPostData(socialPostData); chartData.setEmailNotificationData(emailNotificationData); return chartData; } return null; }
From source file:org.olat.commons.calendar.ui.components.WeeklyCalendarComponentRenderer.java
private void renderWeekGrid(final int year, final int weekOfYear, final boolean enableAddEvent, final StringOutput sb, final URLBuilder ubu, final Locale locale) { final Calendar cal = CalendarUtils.getStartOfWeekCalendar(year, weekOfYear, locale); int dayToday = -1; final Calendar calNow = CalendarUtils.createCalendarInstance(locale); if ((calNow.get(Calendar.WEEK_OF_YEAR) == weekOfYear) && (calNow.get(Calendar.YEAR) == year)) { // if we are within current week, adjust dayToday dayToday = calNow.get(Calendar.DAY_OF_WEEK); }/*from w w w . j av a 2s. co m*/ // render day grid sb.append("\n<div class=\"o_cal_wv_time o_cal_wv_row0\">"); for (int i = 0; i < 23; i++) { sb.append("<div class=\"o_cal_wv_legend_hour\"><div>"); sb.append(i); sb.append(":00</div></div>"); } sb.append("<div class=\"o_cal_wv_legend_hour o_cal_wv_lasthour\"><div>23:00</div></div></div>"); // render daily grid // reposition calendar to start of week for (int i = 1; i <= 7; i++) { final int dayOfWeekIter = cal.get(Calendar.DAY_OF_WEEK); sb.append("\n<div class=\"o_cal_wv_day o_cal_wv_row"); sb.append(i); if (dayOfWeekIter == dayToday) { // current day sb.append(" o_cal_wv_today"); } else if (dayOfWeekIter == Calendar.SATURDAY || dayOfWeekIter == Calendar.SUNDAY) { // holiday sb.append(" o_cal_wv_holiday"); } sb.append("\">"); for (int j = 0; j < 23; j++) { // set calendar add link to corresponding hour cal.set(Calendar.HOUR_OF_DAY, j); // build the add event uri final StringOutput uri = new StringOutput(); ubu.buildJavaScriptBgCommand(uri, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM }, new String[] { WeeklyCalendarComponent.CMD_ADD, dmyDateFormat.format(cal.getTime()) }, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL, true); sb.append("<div class=\"o_cal_wv_hour\""); if (enableAddEvent) { sb.append(" onclick=\""); sb.append(uri); } sb.append("\"></div>"); sb.append("<div class=\"o_cal_wv_half_hour\""); if (enableAddEvent) { sb.append(" onclick=\""); sb.append(uri); } sb.append("\"></div>"); } // set calendar add link to last hour (23) cal.set(Calendar.HOUR_OF_DAY, 23); final StringOutput uri = new StringOutput(); ubu.buildJavaScriptBgCommand(uri, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM }, new String[] { WeeklyCalendarComponent.CMD_ADD, dmyDateFormat.format(cal.getTime()) }, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL, true); sb.append("<div class=\"o_cal_wv_hour\""); if (enableAddEvent) { sb.append(" onclick=\""); sb.append(uri); } sb.append("\"></div>"); sb.append("<div class=\"o_cal_wv_half_hour o_cal_wv_lasthour\""); if (enableAddEvent) { sb.append(" onclick=\""); sb.append(uri); } sb.append("\"></div></div>"); cal.add(Calendar.DAY_OF_YEAR, 1); } }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
private static GregorianCalendar getDate() { GregorianCalendar date = new GregorianCalendar(HeliniumStudentApp.LOCALE); date.clear();//from w w w .j a v a 2s . c o m date.set(Calendar.YEAR, new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.YEAR)); //FIXME BAD date.set(Calendar.WEEK_OF_YEAR, scheduleFocus); date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return date; }
From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java
/** * Created a regular time period// w ww.ja va 2 s . co m * @param period * @param year * @param timeInterval * @return */ public static Date createDate(int period, int year, int timeInterval) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setLenient(true); calendar.set(Calendar.YEAR, year); switch (timeInterval) { case TIME_INTERVAL.DAY: calendar.set(Calendar.DAY_OF_YEAR, period); break; case TIME_INTERVAL.WEEK: calendar.set(Calendar.WEEK_OF_YEAR, period); break; default: calendar.set(Calendar.MONTH, period); } return calendar.getTime(); }
From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java
public static Object week(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { try {//www. j ava 2 s.co m if (ArgList.length == 1) { if (isNull(ArgList[0])) { return new Double(Double.NaN); } else if (isUndefined(ArgList[0])) { return undefinedValue; } java.util.Date dArg1 = (java.util.Date) ArgList[0]; Calendar cal = Calendar.getInstance(); cal.setTime(dArg1); return new Double(cal.get(Calendar.WEEK_OF_YEAR)); } else { throw new RuntimeException("The function call week requires 1 argument."); } } catch (Exception e) { throw new RuntimeException(e.toString()); } }
From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java
public static Object week(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { try {/*from w ww . java2 s. c o m*/ if (ArgList.length == 1) { if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return undefinedValue; java.util.Date dArg1 = (java.util.Date) ArgList[0]; Calendar cal = Calendar.getInstance(); cal.setTime(dArg1); return new Double(cal.get(Calendar.WEEK_OF_YEAR)); } else { throw new RuntimeException("The function call week requires 1 argument."); } } catch (Exception e) { throw new RuntimeException(e.toString()); } }
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
/** * This version is for HOURLY/DAILY frequencies: it does NOT check the ordinal at all, * it only verifies that the day-of-the-week matches * * @param cal/* w w w .j a v a 2 s.com*/ * @return */ private boolean checkDayList(GregorianCalendar cal) { assert (mFreq != Frequency.MONTHLY && mFreq != Frequency.YEARLY && mFreq != Frequency.WEEKLY); if (mByDayList.size() > 0) { for (ZWeekDayNum listCur : mByDayList) { int curDayOfWeek = cal.get(Calendar.DAY_OF_WEEK); if (listCur.mDay.getCalendarDay() == curDayOfWeek) return true; // since the DayOfWeek list is in week-order, if we hit a HIGHER one, // then we know out current one isn't in the list, and therefore // we should go to this one we just found in the list if (listCur.mDay.getCalendarDay() > curDayOfWeek) { cal.set(Calendar.DAY_OF_WEEK, listCur.mDay.getCalendarDay()); return false; } } // we've not found a match AND we've not found a // higher value in our list -- so wrap cal.set(Calendar.DAY_OF_WEEK, mByDayList.get(0).mDay.getCalendarDay()); cal.add(Calendar.WEEK_OF_YEAR, 1); return false; } return true; }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object week(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { try {//from ww w. j a v a2 s. c o m if (ArgList.length == 1) { if (isNull(ArgList[0])) return new Double(Double.NaN); else if (isUndefined(ArgList[0])) return Context.getUndefinedValue(); java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); Calendar cal = Calendar.getInstance(); cal.setTime(dArg1); return new Double(cal.get(Calendar.WEEK_OF_YEAR)); } else { throw Context.reportRuntimeError("The function call week requires 1 argument."); } } catch (Exception e) { throw Context.reportRuntimeError(e.toString()); } }
From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object week(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { try {//from w w w. ja v a 2 s . co m if (ArgList.length == 1) { if (isNull(ArgList[0])) { return new Double(Double.NaN); } else if (isUndefined(ArgList[0])) { return Context.getUndefinedValue(); } java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); Calendar cal = Calendar.getInstance(); cal.setTime(dArg1); return new Double(cal.get(Calendar.WEEK_OF_YEAR)); } else { throw Context.reportRuntimeError("The function call week requires 1 argument."); } } catch (Exception e) { throw Context.reportRuntimeError(e.toString()); } }
From source file:cn.mljia.common.notify.utils.DateUtils.java
public static boolean isSameWeekWithToday(Date date) { if (date == null) { return false; }//from w ww . j ava2 s . c o m // 0.Date?Calendar Calendar todayCal = Calendar.getInstance(); Calendar dateCal = Calendar.getInstance(); todayCal.setTime(new Date()); dateCal.setTime(date); int subYear = todayCal.get(Calendar.YEAR) - dateCal.get(Calendar.YEAR); // subYear==0,? if (subYear == 0) { if (todayCal.get(Calendar.WEEK_OF_YEAR) == dateCal.get(Calendar.WEEK_OF_YEAR)) return true; } else if (subYear == 1 && dateCal.get(Calendar.MONTH) == 11 && todayCal.get(Calendar.MONTH) == 0) { if (todayCal.get(Calendar.WEEK_OF_YEAR) == dateCal.get(Calendar.WEEK_OF_YEAR)) return true; } else if (subYear == -1 && todayCal.get(Calendar.MONTH) == 11 && dateCal.get(Calendar.MONTH) == 0) { if (todayCal.get(Calendar.WEEK_OF_YEAR) == dateCal.get(Calendar.WEEK_OF_YEAR)) return true; } return false; }