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.openmrs.module.clinicalsummary.rule.util.ZScoreUtils.java
/** * Calculate the z-score value based on the stored values of the WHO standard * * @param patient the patient//from w w w.j a v a 2s . com * @param asOfDate the reference point for the z-score calculation * @param weight the weight of the patient * @return the calculated z-score */ public static Double calculateZScore(final Patient patient, final Date asOfDate, final Double weight) { Double zScore = null; Date birthDate = patient.getBirthdate(); // apparently there are records with null birth date if (birthDate != null) { Calendar birthCalendar = Calendar.getInstance(); birthCalendar.setTime(birthDate); birthCalendar.add(Calendar.YEAR, 5); Date fiveYars = birthCalendar.getTime(); Calendar todayCalendar = Calendar.getInstance(); todayCalendar.setTime(asOfDate); // only do processing for kids younger than 5 years old if (fiveYars.after(todayCalendar.getTime())) { // decide the gender. // our database contains both F or Female and M or Male Gender gender = null; if (StringUtils.equalsIgnoreCase(MALE_LONG_STRING, patient.getGender()) || StringUtils.equalsIgnoreCase(MALE_SHORT_STRING, patient.getGender())) gender = Gender.GENDER_MALE; else if (StringUtils.equalsIgnoreCase(FEMALE_LONG_STRING, patient.getGender()) || StringUtils.equalsIgnoreCase(FEMALE_SHORT_STRING, patient.getGender())) gender = Gender.GENDER_FEMALE; birthCalendar.setTime(birthDate); birthCalendar.add(Calendar.WEEK_OF_YEAR, 13); WeightStandard standard; UtilService utilService = Context.getService(UtilService.class); if (todayCalendar.after(birthCalendar)) { Integer ageInMonth = calculateAgeInMonth(patient.getBirthdate(), asOfDate); standard = utilService.getWeightStandard(gender, AgeUnit.UNIT_MONTH, ageInMonth); } else { Integer ageInWeek = calculateAgeInWeek(patient.getBirthdate(), asOfDate); standard = utilService.getWeightStandard(gender, AgeUnit.UNIT_WEEK, ageInWeek); } if (standard != null) zScore = zScore(standard.getCurve(), standard.getMean(), standard.getCoef(), weight); } if (log.isDebugEnabled()) log.debug("Patient: " + patient.getPatientId() + ", zscore: " + zScore); } return zScore; }
From source file:org.sqlite.date.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *//*from w w w .ja v a 2s . co m*/ protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final 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 == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } 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 'X': // ISO 8601 rule = Iso8601_Rule.getRule(tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else if (tokenLen == 2) { rule = TimeZoneNumberRule.INSTANCE_ISO_8601; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final 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; }
From source file:org.wso2.siddhi.extension.time.ExtractAttributesFunctionExtension.java
@Override protected Object execute(Object[] data) { String source = null;//from w w w. jav a2s. co m if (data.length == 3 || useDefaultDateFormat) { try { if (data[1] == null) { throw new ExecutionPlanRuntimeException("Invalid input given to time:extract(unit,dateValue," + "dateFormat) function" + ". Second " + "argument cannot be null"); } if (!useDefaultDateFormat) { if (data[2] == null) { throw new ExecutionPlanRuntimeException( "Invalid input given to time:extract(unit,dateValue," + "dateFormat) function" + ". Third " + "argument cannot be null"); } dateFormat = (String) data[2]; } FastDateFormat userSpecificFormat; source = (String) data[1]; userSpecificFormat = FastDateFormat.getInstance(dateFormat); Date userSpecifiedDate = userSpecificFormat.parse(source); cal.setTime(userSpecifiedDate); } catch (ParseException e) { String errorMsg = "Provided format " + dateFormat + " does not match with the timestamp " + source + e.getMessage(); throw new ExecutionPlanRuntimeException(errorMsg, e); } catch (ClassCastException e) { String errorMsg = "Provided Data type cannot be cast to desired format. " + e.getMessage(); throw new ExecutionPlanRuntimeException(errorMsg, e); } } else { if (data[0] == null) { throw new ExecutionPlanRuntimeException( "Invalid input given to time:extract(timestampInMilliseconds," + "unit) function" + ". First " + "argument cannot be null"); } try { long millis = (Long) data[0]; cal.setTimeInMillis(millis); } catch (ClassCastException e) { String errorMsg = "Provided Data type cannot be cast to desired format. " + e.getMessage(); throw new ExecutionPlanRuntimeException(errorMsg, e); } } int returnValue = 0; if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_YEAR)) { returnValue = cal.get(Calendar.YEAR); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_MONTH)) { returnValue = (cal.get(Calendar.MONTH) + 1); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_SECOND)) { returnValue = cal.get(Calendar.SECOND); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_MINUTE)) { returnValue = cal.get(Calendar.MINUTE); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_HOUR)) { returnValue = cal.get(Calendar.HOUR_OF_DAY); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_DAY)) { returnValue = cal.get(Calendar.DAY_OF_MONTH); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_WEEK)) { returnValue = cal.get(Calendar.WEEK_OF_YEAR); } else if (unit.equals(TimeExtensionConstants.EXTENSION_TIME_UNIT_QUARTER)) { returnValue = (cal.get(Calendar.MONTH) / 3) + 1; } return returnValue; }
From source file:com.ibm.mil.readyapps.physio.fragments.ProgressFragment.java
private void gatherDetailedData(List<Integer> data, String route, StringBuilder builder) { Locale locale = getResources().getConfiguration().locale; NumberFormat numberFormat = NumberFormat.getNumberInstance(locale); // set performance String performance = numberFormat.format(data.get(data.size() - 1)); builder.append("scope.setPerformance('"); builder.append(performance);/* w w w . jav a 2 s .com*/ builder.append("');"); // set time frame String format; String unit; String timeSpan = route.split("_")[2]; switch (timeSpan) { case "day": format = "MMMM d - ha"; unit = "Today"; break; case "week": format = "MMMM d"; unit = "Today"; break; case "month": format = "MMM d"; unit = "This Week"; break; default: format = "MMMM yyyy"; unit = "This Month"; break; } SimpleDateFormat dateFormat = new SimpleDateFormat(format, locale); String timeFrame = dateFormat.format(new Date()); // add additional time frame text for month if (timeSpan.equals("month")) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.WEEK_OF_YEAR, -1); dateFormat.applyLocalizedPattern("MMMM d"); timeFrame = dateFormat.format(calendar.getTime()) + " - " + timeFrame; } builder.append("scope.setTimeFrame('"); builder.append(timeFrame); builder.append("');"); builder.append("scope.setUnit('"); builder.append(unit); builder.append("');"); // set optional goal if (route.contains("steps") || route.contains("calories")) { String goal; if (route.contains("steps")) { goal = numberFormat.format(DataManager.getCurrentPatient().getStepGoal()); } else { goal = numberFormat.format(DataManager.getCurrentPatient().getCalorieGoal()); } builder.append("scope.setGoal('"); builder.append(goal); builder.append("');"); } }
From source file:com.google.gwt.benchmark.dashboard.server.controller.BenchmarkController.java
private WeekSpan createWeekSpan(long commitTimeMsEpoch) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(commitTimeMsEpoch)); int week = cal.get(Calendar.WEEK_OF_YEAR); int year = cal.get(Calendar.YEAR); Calendar calendar = Calendar.getInstance(); calendar.clear();// w w w.ja v a2 s. c o m calendar.set(Calendar.WEEK_OF_YEAR, week); calendar.set(Calendar.YEAR, year); long startSearch = calendar.getTimeInMillis(); calendar.add(Calendar.DAY_OF_YEAR, 7); long endSearch = calendar.getTimeInMillis(); return new WeekSpan(week, year, startSearch, endSearch); }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
@SuppressWarnings("ConstantConditions") @Override/*from w w w .ja va 2 s .c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) { mainContext = (AppCompatActivity) getActivity(); scheduleLayout = inflater.inflate(R.layout.fragment_schedule, viewGroup, false); MainActivity.setToolbarTitle(mainContext, getResources().getString(R.string.schedule), null); weekDaysLV = (ListView) scheduleLayout.findViewById(R.id.lv_weekDays_fs); final boolean restart = PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("forced_restart", false); if (restart) PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putBoolean("forced_restart", false) .apply(); if (restart) { //TODO Database check? MainActivity.setStatusBar(mainContext); scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null); if (MainActivity.isOnline()) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } else if (scheduleJson == null) { final boolean online = MainActivity.isOnline(); scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); if (online && PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_updates_auto_update", true)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) new UpdateClass(mainContext, false).execute(); else new UpdateClass(mainContext, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } if (online && (PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_schedule_init", true) || PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null) == null)) { getSchedule(HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { MainActivity.setStatusBar(mainContext); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null); if (online) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } } ((SwipeRefreshLayout) scheduleLayout).setColorSchemeResources(MainActivity.accentSecondaryColor, MainActivity.accentPrimaryColor, MainActivity.primaryColor); ((SwipeRefreshLayout) scheduleLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); MainActivity.prevIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { scheduleFocus--; getSchedule(HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN); } else { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (scheduleFocus > currentWeek + 1) { scheduleFocus = currentWeek + 1; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.historyIV.setOnClickListener(new OnClickListener() { //FIXME Huge mess private int year; private int monthOfYear; private int dayOfMonth; @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { MainActivity.setUI(HeliniumStudentApp.VIEW_SCHEDULE, HeliniumStudentApp.ACTION_ONLINE); final AlertDialog.Builder weekpickerDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); final View view = View.inflate(mainContext, R.layout.dialog_schedule, null); weekpickerDialogBuilder.setView(view); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.np_weekpicker_dw); year = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.YEAR); monthOfYear = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.MONTH); dayOfMonth = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.DAY_OF_MONTH); weekpickerDialogBuilder.setTitle(getString(R.string.go_to)); weekpickerDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final GregorianCalendar date = new GregorianCalendar( HeliniumStudentApp.LOCALE); final GregorianCalendar today = new GregorianCalendar( HeliniumStudentApp.LOCALE); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, monthOfYear); date.set(Calendar.DAY_OF_MONTH, dayOfMonth); date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); today.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); scheduleFocus = (today.get(Calendar.WEEK_OF_YEAR)) - ((int) ((today.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7)) - (date.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7)))); getSchedule(HeliniumStudentApp.DIREC_OTHER, HeliniumStudentApp.ACTION_REFRESH_IN); } }); weekpickerDialogBuilder.setNegativeButton(getString(android.R.string.cancel), null); final AlertDialog weekPickerDialog = weekpickerDialogBuilder.create(); final GregorianCalendar minDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); minDate.set(Calendar.YEAR, 2000); minDate.set(Calendar.WEEK_OF_YEAR, 1); final GregorianCalendar maxDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); maxDate.set(Calendar.YEAR, 2038); maxDate.set(Calendar.WEEK_OF_YEAR, 1); datePicker.init(year, monthOfYear, dayOfMonth, new DatePicker.OnDateChangedListener() { final GregorianCalendar newDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); @Override public void onDateChanged(DatePicker view, int dialogYear, int dialogMonthOfYear, int dialogDayOfMonth) { newDate.set(year, monthOfYear, dayOfMonth); year = dialogYear; monthOfYear = dialogMonthOfYear; dayOfMonth = dialogDayOfMonth; if (minDate != null && minDate.after(newDate)) view.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH), this); else if (maxDate != null && maxDate.before(newDate)) view.init(maxDate.get(Calendar.YEAR), maxDate.get(Calendar.MONTH), maxDate.get(Calendar.DAY_OF_MONTH), this); else view.init(year, monthOfYear, dayOfMonth, this); } }); weekPickerDialog.setCanceledOnTouchOutside(true); weekPickerDialog.show(); weekPickerDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor)); weekPickerDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor)); } else { scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.nextIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { scheduleFocus++; getSchedule(HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN); } else { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1", null) != null && scheduleFocus >= currentWeek) { scheduleFocus = currentWeek + 1; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); return scheduleLayout; }
From source file:com.rockagen.commons.util.CommUtil.java
/** * Return the current week of year/*from w ww .j a va2 s . co m*/ * * @param date Date * @return current week of year */ public static int getCurrentWeekOfYear(Date date) { Calendar cal = getCalendar(date); return cal.get(Calendar.WEEK_OF_YEAR); }
From source file:org.apache.logging.log4j.core.util.datetime.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *//*from www . ja v a 2 s. c om*/ protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) case 'Y': // week year if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } if (c == 'Y') { rule = new WeekYear((NumberRule) rule); } 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 'u': // day in week (number) rule = new DayInWeekField(selectNumberRule(Calendar.DAY_OF_WEEK, tokenLen)); 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 'X': // ISO 8601 rule = Iso8601_Rule.getRule(tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else if (tokenLen == 2) { rule = Iso8601_Rule.ISO8601_HOURS_COLON_MINUTES; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final 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; }
From source file:org.adempiere.apps.graph.ChartBuilder.java
private Date increment(Date lastDate, String timeUnit, int qty) { if (lastDate == null) return null; Calendar cal = Calendar.getInstance(); cal.setTime(lastDate);//from w ww .j a va2 s. c om if (timeUnit.equals(MChart.TIMEUNIT_Day)) cal.add(Calendar.DAY_OF_YEAR, qty); else if (timeUnit.equals(MChart.TIMEUNIT_Week)) cal.add(Calendar.WEEK_OF_YEAR, qty); else if (timeUnit.equals(MChart.TIMEUNIT_Month)) cal.add(Calendar.MONTH, qty); else if (timeUnit.equals(MChart.TIMEUNIT_Quarter)) cal.add(Calendar.MONTH, 3 * qty); else if (timeUnit.equals(MChart.TIMEUNIT_Year)) cal.add(Calendar.YEAR, qty); return cal.getTime(); }
From source file:fr.paris.lutece.plugins.form.utils.FormUtils.java
/** * return the week of the timestamp/*from www .ja v a 2 s . c o m*/ * in parameter * @param timestamp date * @return the week of the timestamp in parameter */ public static int getWeek(Timestamp timestamp) { Calendar caldate = new GregorianCalendar(); caldate.setTime(timestamp); return caldate.get(Calendar.WEEK_OF_YEAR); }