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:com.bt.heliniumstudentapp.ScheduleFragment.java
private int checkDatabase() { Boolean updated = false;// www . j av a2 s.co m final GregorianCalendar currentDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); final GregorianCalendar storedDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); final String scheduleStart = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_start_0", null); if (scheduleStart == null) { return HeliniumStudentApp.DB_OK; } else { try { storedDate.setTime(HeliniumStudentApp.df_date().parse(scheduleStart)); } catch (ParseException ignored) { return HeliniumStudentApp.DB_ERROR; } } for (int weekDays = 0; weekDays < 7; weekDays++) { if (currentDate.get(Calendar.YEAR) == storedDate.get(Calendar.YEAR) && currentDate.get(Calendar.MONTH) == storedDate.get(Calendar.MONTH) && currentDate.get(Calendar.DAY_OF_MONTH) == storedDate.get(Calendar.DAY_OF_MONTH)) { updated = true; break; } storedDate.add(Calendar.DAY_OF_YEAR, 1); } if (updated) { return HeliniumStudentApp.DB_OK; } else { scheduleFocus = currentDate.get(Calendar.WEEK_OF_YEAR); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1", null) == null) { if (MainActivity.isOnline()) { MainActivity.setStatusBar(mainContext); PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putString("schedule_0", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putString("schedule_1", null) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_start_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_start_1", null).apply(); ScheduleFragment.getSchedule(HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_SHORT_IN); return HeliniumStudentApp.DB_REFRESHING; //TODO Handle by caller to avoid workarounds } else { Toast.makeText(mainContext, mainContext.getString(R.string.error_database) + ". " + mainContext.getString(R.string.error_conn_no) + ".", Toast.LENGTH_SHORT).show(); mainContext.finish(); return HeliniumStudentApp.DB_ERROR; //TODO Throw error / in finally } } else try { currentDate.setTime(HeliniumStudentApp.df_date().parse(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("schedule_start_0", "1"))); if (currentDate.get(Calendar.WEEK_OF_YEAR) - currentDate.get(Calendar.WEEK_OF_YEAR) == 1) { PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_0", PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null)) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("pref_schedule_version_0", PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("pref_schedule_version_1", null)) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("pref_schedule_version_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_start_0", PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_start_1", null)) .apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_start_1", null).apply(); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); return HeliniumStudentApp.DB_OK; } else { if (MainActivity.isOnline()) { MainActivity.setStatusBar(mainContext); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_1", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_start_0", null).apply(); PreferenceManager.getDefaultSharedPreferences(mainContext).edit() .putString("schedule_start_1", null).apply(); ScheduleFragment.getSchedule(HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_SHORT_IN); return HeliniumStudentApp.DB_REFRESHING; //TODO Handle by caller to avoid workarounds } else { Toast.makeText(mainContext, mainContext.getString(R.string.error_database) + ". " + mainContext.getString(R.string.error_conn_no) + ".", Toast.LENGTH_SHORT).show(); mainContext.finish(); return HeliniumStudentApp.DB_ERROR; //TODO Throw error / in finally } } } catch (ParseException ignored) { } return HeliniumStudentApp.DB_ERROR; //TODO Throw error / in finally } }
From source file:com.bt.heliniumstudentapp.MainActivity.java
@SuppressWarnings("deprecation") protected static void setUI(final int view, final int action) { if (action == HeliniumStudentApp.ACTION_SHORT_IN || (action == HeliniumStudentApp.ACTION_INIT_IN && view == HeliniumStudentApp.VIEW_GRADES)) { containerFL.setVisibility(View.GONE); drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); drawerDLtoggle.setToolbarNavigationClickListener(null); drawerDLtoggle.syncState();//w w w. j av a 2s. com weekTV.setText(""); yearTV.setText(""); prevIV.setAlpha(130); historyIV.setAlpha(130); nextIV.setAlpha(130); containerFL.setAlpha(0); statusLL.setAlpha(1); } else if (action == HeliniumStudentApp.ACTION_SHORT_OUT || (action == HeliniumStudentApp.ACTION_INIT_OUT && view == HeliniumStudentApp.VIEW_GRADES)) { containerFL.setVisibility(View.VISIBLE); drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); drawerDLtoggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawerDL.openDrawer(drawerNV); } }); drawerDLtoggle.syncState(); historyIV.setAlpha(255); switch (GradesFragment.termFocus) { case 1: prevIV.setAlpha(130); nextIV.setAlpha(255); break; case 4: prevIV.setAlpha(255); nextIV.setAlpha(130); break; default: prevIV.setAlpha(255); nextIV.setAlpha(255); break; } final int shortAnimationDuration = mainContext.getResources() .getInteger(android.R.integer.config_shortAnimTime); statusLL.animate().alpha(0).setDuration(shortAnimationDuration).setListener(null); containerFL.animate().alpha(1).setDuration(shortAnimationDuration).setListener(null); } else if (action == HeliniumStudentApp.ACTION_INIT_IN) { toolbarTB.setVisibility(View.GONE); containerFL.setVisibility(View.GONE); containerLL.setVisibility(View.GONE); drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); toolbarTB.setAlpha(0); containerFL.setAlpha(0); containerLL.setAlpha(0); statusLL.setAlpha(1); } else if (action == HeliniumStudentApp.ACTION_INIT_OUT) { toolbarTB.setVisibility(View.VISIBLE); containerFL.setVisibility(View.VISIBLE); containerLL.setVisibility(View.VISIBLE); drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); setStatusBar(mainContext); final int shortAnimationDuration = mainContext.getResources() .getInteger(android.R.integer.config_shortAnimTime); final int longAnimationDuration = mainContext.getResources() .getInteger(android.R.integer.config_longAnimTime); toolbarTB.animate().alpha(1).setDuration(longAnimationDuration).setListener(null); containerLL.animate().alpha(1).setDuration(longAnimationDuration) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); statusLL.animate().alpha(0).setDuration(shortAnimationDuration).setListener(null); containerFL.animate().alpha(1).setDuration(shortAnimationDuration).setListener(null); } }); } else { switch (view) { case HeliniumStudentApp.VIEW_SCHEDULE: switch (action) { case HeliniumStudentApp.ACTION_ONLINE: case HeliniumStudentApp.ACTION_ONLINE_1: prevIV.setAlpha(255); historyIV.setAlpha(255); nextIV.setAlpha(255); break; case HeliniumStudentApp.ACTION_OFFLINE: case HeliniumStudentApp.ACTION_OFFLINE_1: if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1", null) == null) { prevIV.setAlpha(130); historyIV.setAlpha(130); nextIV.setAlpha(130); } else { if (ScheduleFragment.scheduleFocus == new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR) + 1) { prevIV.setAlpha(255); historyIV.setAlpha(255); nextIV.setAlpha(130); } else { prevIV.setAlpha(130); historyIV.setAlpha(130); nextIV.setAlpha(255); } } break; case HeliniumStudentApp.ACTION_REFRESH_IN: drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); drawerDLtoggle.setToolbarNavigationClickListener(null); drawerDLtoggle.syncState(); prevIV.setAlpha(130); historyIV.setAlpha(130); nextIV.setAlpha(130); ((SwipeRefreshLayout) ScheduleFragment.scheduleLayout).setRefreshing(true); break; case HeliniumStudentApp.ACTION_REFRESH_OUT: drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); drawerDLtoggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawerDL.openDrawer(drawerNV); } }); drawerDLtoggle.syncState(); prevIV.setAlpha(255); historyIV.setAlpha(255); nextIV.setAlpha(255); ((SwipeRefreshLayout) ScheduleFragment.scheduleLayout).setRefreshing(false); break; /*case HeliniumStudentApp.ERR_UNDEFINED: case HeliniumStudentApp.ERR_OK: //FIXME HANDLE!!! break;*/ } break; case HeliniumStudentApp.VIEW_GRADES: switch (action) { case HeliniumStudentApp.ACTION_ONLINE: case HeliniumStudentApp.ACTION_ONLINE_1: historyIV.setAlpha(255); switch (GradesFragment.termFocus) { case 1: prevIV.setAlpha(130); nextIV.setAlpha(255); break; case 4: prevIV.setAlpha(255); nextIV.setAlpha(130); break; default: prevIV.setAlpha(255); nextIV.setAlpha(255); break; } break; case HeliniumStudentApp.ACTION_OFFLINE: case HeliniumStudentApp.ACTION_OFFLINE_1: final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); prevIV.setAlpha(130); historyIV.setAlpha(130); nextIV.setAlpha(130); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null) { if (GradesFragment.yearFocus == 0 && GradesFragment.termFocus > databaseFocus) prevIV.setAlpha(255); if (GradesFragment.yearFocus != 0 || GradesFragment.termFocus != databaseFocus) historyIV.setAlpha(255); if (GradesFragment.yearFocus == 0 && GradesFragment.termFocus < databaseFocus) nextIV.setAlpha(255); } break; case HeliniumStudentApp.ACTION_REFRESH_IN: drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); drawerDLtoggle.setToolbarNavigationClickListener(null); drawerDLtoggle.syncState(); prevIV.setAlpha(130); historyIV.setAlpha(130); nextIV.setAlpha(130); ((SwipeRefreshLayout) GradesFragment.gradesLayout).setRefreshing(true); break; case HeliniumStudentApp.ACTION_REFRESH_OUT: drawerDL.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); drawerDLtoggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { drawerDL.openDrawer(drawerNV); } }); drawerDLtoggle.syncState(); historyIV.setAlpha(255); switch (GradesFragment.termFocus) { case 1: prevIV.setAlpha(130); nextIV.setAlpha(255); break; case 4: prevIV.setAlpha(255); nextIV.setAlpha(130); break; default: prevIV.setAlpha(255); nextIV.setAlpha(255); break; } ((SwipeRefreshLayout) GradesFragment.gradesLayout).setRefreshing(false); break; /*case HeliniumStudentApp.ERR_UNDEFINED: case HeliniumStudentApp.ERR_OK: //FIXME HANDLE!!! break;*/ } break; } } }
From source file:com.alkacon.opencms.calendar.CmsCalendarDisplay.java
/** * Returns the next time range to show calendar entries for.<p> * Used for the navigation./*w w w . j a v a2 s . c o m*/ * * @param actual the actual date from which the next time range should be calculated * @param type the type of period * @return a date for which a list of calendar entries should be shown */ public Calendar getNextPeriod(Calendar actual, int type) { Calendar cal = (Calendar) actual.clone(); switch (type) { case PERIOD_DAY: cal.add(Calendar.DAY_OF_YEAR, 1); break; case PERIOD_MONTH: cal.add(Calendar.MONTH, 1); break; case PERIOD_WEEK: cal.add(Calendar.WEEK_OF_YEAR, 1); break; case PERIOD_YEAR: cal.add(Calendar.YEAR, 1); break; default: break; } return cal; }
From source file:org.cs.basic.test.util.DateUtils.java
/** * /* w w w . j ava 2 s .c om*/ * @param early_week ?? * @param week_day * @return */ public static String getDateByWeekDay(int early_week, int week_day) { Calendar time = Calendar.getInstance(); if (week_day > -1 && week_day < 7) time.set(Calendar.DAY_OF_WEEK, week_day); if (early_week > -1 && early_week < 54) time.set(Calendar.WEEK_OF_YEAR, time.get(Calendar.WEEK_OF_YEAR) - early_week); SimpleDateFormat fDate = new java.text.SimpleDateFormat("yyyy-MM-dd"); return fDate.format(time.getTime()); }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static int weekNumber(Timestamp stamp, TimeZone timeZone, Locale locale) { Calendar tempCal = toCalendar(stamp, timeZone, locale); return tempCal.get(Calendar.WEEK_OF_YEAR); }
From source file:org.squale.squalecommon.daolayer.component.AuditDAOImpl.java
/** * Dcale l'audit de rotation des partitions la prochaine date prvue Le dlai prvu entre 2 rotations est de 12 * semaines/*from www. j a va 2 s.c om*/ * * @param pSession la session * @throws JrafDaoException en cas d'chec */ public void reportRotationAudit(ISession pSession) throws JrafDaoException { // Rcupre l'audit de rotation Collection result = findRotationAudit(pSession); if (result != null && result.size() != 0) { // il ne doit y avoir qu'un seul lment Iterator it = result.iterator(); AuditBO rotationAudit = (AuditBO) it.next(); Date currentDate = rotationAudit.getDate(); // ajout le dlai prvu GregorianCalendar currentCal = new GregorianCalendar(); currentCal.setTime(currentDate); currentCal.add(Calendar.WEEK_OF_YEAR, ROTATION_DELAY_IN_WEEKS); rotationAudit.setDate(currentCal.getTime()); // et mise jour en base save(pSession, rotationAudit); } }
From source file:com.aurel.track.report.dashboard.AverageTimeToCloseItem.java
public static int getCalendarInterval(int timeInterval) { switch (timeInterval) { case TIME_INTERVAL.DAY: return Calendar.DAY_OF_YEAR; case TIME_INTERVAL.WEEK: return Calendar.WEEK_OF_YEAR; default:// w w w . jav a2s .c om return Calendar.MONTH; } }
From source file:com.alkacon.opencms.calendar.CmsCalendarDisplay.java
/** * Returns the previous time range to show calendar entries for.<p> * Used for the navigation.//from w w w.j av a 2 s .c o m * * @param actual the actual date from which the previous time range should be calculated * @param type the type of period * @return a date for which a list of calendar entries should be shown */ public Calendar getPreviousPeriod(Calendar actual, int type) { Calendar cal = (Calendar) actual.clone(); switch (type) { case PERIOD_DAY: cal.add(Calendar.DAY_OF_YEAR, -1); break; case PERIOD_MONTH: cal.add(Calendar.MONTH, -1); break; case PERIOD_WEEK: cal.add(Calendar.WEEK_OF_YEAR, -1); break; case PERIOD_YEAR: cal.add(Calendar.YEAR, -1); break; default: break; } return cal; }
From source file:org.olat.commons.calendar.ui.components.WeeklyCalendarComponentRenderer.java
private void renderWeekHeader(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); final Calendar calNow = CalendarUtils.createCalendarInstance(locale); cal.set(Calendar.HOUR_OF_DAY, calNow.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, calNow.get(Calendar.MINUTE)); final SimpleDateFormat dayMonth = new SimpleDateFormat("E dd.MM", locale); // render header sb.append("\n<div id=\"o_cal_wv_header\">"); sb.append("<div class=\"o_cal_wv_time o_cal_wv_row0\">"); sb.append("<div class=\"o_cal_wv_legend_hours\"><div></div></div></div>"); int dayToday = -1; 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 ww w . j ava 2s .co m for (int i = 1; i <= days; i++) { final int dayOfWeekIter = cal.get(Calendar.DAY_OF_WEEK); sb.append("\n<div class=\"o_cal_wv_day "); sb.append("o_cal_wv_row"); sb.append(i); sb.append(" "); if (i == 7) { // terminate last day sb.append("o_cal_wv_lastday "); } 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("\">"); sb.append("<div class=\"o_cal_wv_legend_day\"><div>"); if (enableAddEvent) { sb.append("<a href=\""); ubu.buildURI(sb, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM }, new String[] { WeeklyCalendarComponent.CMD_ADD_ALLDAY, dmyDateFormat.format(cal.getTime()) }, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL); sb.append("\" "); if (isIframePostEnabled) { ubu.appendTarget(sb); } sb.append(" onclick=\"return o2cl();\">"); sb.append(dayMonth.format(cal.getTime())); sb.append("</a>"); } else { sb.append(dayMonth.format(cal.getTime())); } sb.append("</div></div></div>"); // add one day to calendar cal.add(Calendar.DAY_OF_YEAR, 1); } sb.append("</div>"); }
From source file:DateFormatUtils.java
/** * <p>Returns a list of Rules given a pattern.</p> * // w ww . j a v a 2 s . c o m * @return a <code>List</code> of Rule objects * @throws IllegalArgumentException if pattern is invalid */ protected List parsePattern() { DateFormatSymbols symbols = new DateFormatSymbols(mLocale); List rules = new ArrayList(); String[] ERAs = symbols.getEras(); String[] months = symbols.getMonths(); String[] shortMonths = symbols.getShortMonths(); String[] weekdays = symbols.getWeekdays(); String[] shortWeekdays = symbols.getShortWeekdays(); String[] AmPmStrings = symbols.getAmPmStrings(); int length = mPattern.length(); int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; String token = parseToken(mPattern, indexRef); i = indexRef[0]; int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen >= 4) { rule = selectNumberRule(Calendar.YEAR, tokenLen); } else { rule = TwoDigitYearField.INSTANCE; } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }