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.op4j.functions.FnCalendar.java
/** * <p>// w ww .j a v a 2 s . co m * Modifies a Calendar by adding a positive or negative amount to one the * "week" property (<tt>java.util.Calendar.WEEK_OF_YEAR</tt>). * </p> * * @param amount the positive or negative amount to be added * @return the modified Calendar */ public static final Function<Calendar, Calendar> addWeeks(final int amount) { return new Add(Calendar.WEEK_OF_YEAR, amount); }
From source file:org.projectforge.business.gantt.GanttTest.java
private GanttTask createTestChart() { // final GanttObjectImpl root = createGanttObject(null, "--", "rootNode", "0"); final GanttTaskImpl phase1 = createGanttObject(null, "P1", "Phase 1", "5"); final GanttTaskImpl task1 = createGanttObject(phase1, "001", "Task 1", "10"); final DayHolder day = new DayHolder(); day.setDate(2010, Calendar.JUNE, 1); task1.setStartDate(day.getDate());//ww w . ja va 2s .c o m createGanttObject(phase1, "002", "Task 2 (finish-start)", "10", task1, GanttRelationType.FINISH_START, 10); final GanttTaskImpl task3 = createGanttObject(phase1, "003", "Task 3 (finish-start II)", "5", task1, null, 0); createGanttObject(phase1, "004", "Task 4 (finish-start, depth = 2)", "5", task3, null, -3); final GanttTaskImpl task5 = createGanttObject(phase1, "005", "Task 5", "5"); day.add(Calendar.MONTH, 1); task5.setStartDate(day.getDate()); createGanttObject(phase1, "006", "Task 6 (finish-finish)", "3", task5, GanttRelationType.FINISH_FINISH, 0); createGanttObject(phase1, "007", "Task 7 (finish_finish)", "3", task5, GanttRelationType.FINISH_FINISH, -8); final GanttTaskImpl task8 = createGanttObject(phase1, "008", "Task 8 (finish_finish)", "3", task5, GanttRelationType.FINISH_FINISH, 3); createGanttObject(phase1, "009", "Task 9 (start-start)", "3", task8, GanttRelationType.START_START, 0); createGanttObject(phase1, "010", "Task 10 (start-start)", "3", task8, GanttRelationType.START_START, 5); createGanttObject(phase1, "011", "Task 11 (start-start)", "3", task8, GanttRelationType.START_START, -5); final GanttTaskImpl task12 = createGanttObject(phase1, "012", "Task 12", "5"); day.add(Calendar.WEEK_OF_YEAR, 3); task12.setStartDate(day.getDate()); createGanttObject(phase1, "013", "Task 13 (start-finish)", "3", task12, GanttRelationType.START_FINISH, -5); createGanttObject(phase1, "014", "Task 14 (start-finish)", "3", task12, GanttRelationType.START_FINISH, 5); createGanttObject(phase1, "015", "Task 15 (start-finish)", "3", task12, GanttRelationType.START_FINISH, 0); final GanttTaskImpl task16 = createGanttObject(phase1, "016", "Task 16", "6"); day.add(Calendar.WEEK_OF_YEAR, 1); task16.setStartDate(day.getDate()); return phase1; }
From source file:org.op4j.functions.FnDate.java
/** * <p>//www.j ava2 s . c o m * Modifies a Date by adding a positive or negative amount to one the * "week" property (<tt>java.util.Calendar.WEEK</tt>). * </p> * * @param amount the positive or negative amount to be added * @return the modified Date */ public static final Function<Date, Date> addWeeks(final int amount) { return new Add(Calendar.WEEK_OF_YEAR, amount); }
From source file:de.kurashigegollub.dev.gcatest.Utils.java
public static DateTime getDateTime2Weeks(DateTime dtFrom) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(dtFrom.getValue()); c.add(Calendar.WEEK_OF_YEAR, 2); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59);// www .j ava2 s. c o m c.set(Calendar.SECOND, 59); c.set(Calendar.MILLISECOND, 999); return new DateTime(c.getTime(), TimeZone.getDefault()); }
From source file:com.redhat.rhn.manager.monitoring.ModifyFilterCommand.java
/** * Update the recurrance logic of the filter. If <code>recurring</code> is * {@link Boolean#TRUE}, set the filter to be active for <code>duration</code> * time units every <code>frequency</code>; the time units are given * by <code>durationType</code>. The frequency is one of the constants mentioned in * {@link Filter#setRecurringFrequency}//from www .j a v a 2s. com * @param recurring whether the filter is recurring or not * @param duration the number of time units the filter is active for * @param durationType one of {@link Calendar#YEAR}, {@link Calendar#WEEK_OF_YEAR}, * {@link Calendar#DAY_OF_MONTH}, {@link Calendar#HOUR_OF_DAY}, * {@link Calendar#HOUR_OF_DAY} * @param frequency the frequency with which the filter is activated, as described in * {@link Filter#setRecurringFrequency} */ public void updateRecurring(Boolean recurring, int duration, int durationType, Long frequency) { filter.setRecurringBool(recurring); if (recurring.booleanValue()) { // Calculate duration Calendar expires = Calendar.getInstance(); expires.setTime(filter.getStartDate()); expires.add(durationType, duration); if (durationType == Calendar.MINUTE) { // durationType == 12 // NOOP since minutes is the base type. } else if (durationType == Calendar.HOUR_OF_DAY) { // durationType == 11 duration = duration * 60; } else if (durationType == Calendar.DAY_OF_MONTH) { // durationType == 5 duration = duration * 60 * 24; } else if (durationType == Calendar.WEEK_OF_YEAR) { // durationType == 3 duration = duration * 60 * 24 * 7; } else if (durationType == Calendar.YEAR) { // durationType == 1 duration = duration * 60 * 24 * 7 * 365; } else { throw new IllegalArgumentException("Durration for recurring " + "should be either Calendar.MINUTE, HOURS_OF_DAY, " + "DAY_OF_MONTH, WEEK_OF_YEAR, YEAR"); } filter.setRecurringDuration(new Long(duration)); filter.setRecurringFrequency(frequency); filter.setRecurringDurationType(new Long(durationType)); } }
From source file:org.apache.ranger.audit.utils.RollingTimeUtil.java
private Date computeTopOfWeekDate(int weeks) { Date ret = null;//from w ww . j a v a 2 s. c o m Calendar calendarWeek = Calendar.getInstance(); calendarWeek.set(Calendar.DAY_OF_WEEK, calendarWeek.getFirstDayOfWeek()); calendarWeek.add(Calendar.WEEK_OF_YEAR, weeks); calendarWeek.set(Calendar.HOUR_OF_DAY, 0); calendarWeek.clear(Calendar.MINUTE); calendarWeek.clear(Calendar.SECOND); calendarWeek.clear(Calendar.MILLISECOND); ret = calendarWeek.getTime(); return ret; }
From source file:org.callistasoftware.netcare.core.repository.HealthPlanRepositoryTest.java
@Test @Transactional// w w w . ja va2 s . c om @Rollback(true) public void testInsertFind() throws Exception { final CountyCouncilEntity cc = ccRepo.save(CountyCouncilEntity.newEntity(CountyCouncil.STOCKHOLM)); final CareUnitEntity cu = CareUnitEntity.newEntity("cu-123", cc); this.cuRepo.save(cu); final CareActorEntity ca = CareActorEntity.newEntity("Doctor Hook", "", "12345-67", cu); careActorRepo.save(ca); careActorRepo.flush(); final PatientEntity patient = PatientEntity.newEntity("Peter", "", "123456"); patientRepo.save(patient); patientRepo.flush(); final HealthPlanEntity e1 = HealthPlanEntity.newEntity(ca, patient, "Hlsoplan B", new Date(), 20, DurationUnit.WEEK); ActivityDefinitionEntity ad = createActivityDefinition(e1, ca); actRepo.save(ad); repo.save(e1); repo.flush(); final List<HealthPlanEntity> all = repo.findAll(); assertNotNull(all); assertEquals(1, all.size()); HealthPlanEntity e2 = all.get(0); assertEquals("Hlsoplan B", e2.getName()); assertEquals(DurationUnit.WEEK, e2.getDurationUnit()); assertEquals(20, e2.getDuration()); Calendar c = Calendar.getInstance(); c.setTime(e2.getStartDate()); c.add(Calendar.WEEK_OF_YEAR, e2.getDuration()); assertEquals(ApiUtil.dayEnd(c).getTime(), e2.getEndDate()); assertEquals(1, e2.getActivityDefinitions().size()); }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * Generate the histogram buckets based on the time frame requested and the interval. This will * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0. * @param rval//from w w w .j a v a2 s. c o m * @param from * @param to * @param interval */ public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval, DateTime from, DateTime to, HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) { Map<K, T> index = new HashMap<>(); Calendar fromCal = from.toGregorianCalendar(); Calendar toCal = to.toGregorianCalendar(); switch (interval) { case day: fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case hour: fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case minute: fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case month: fromCal.set(Calendar.DAY_OF_MONTH, 1); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case week: fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; default: break; } while (fromCal.before(toCal)) { String label = formatDateWithMillis(fromCal); T point; try { point = dataType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } point.setLabel(label); rval.addDataPoint(point); if (keyType == String.class) { index.put((K) label, point); } else { index.put((K) new Long(fromCal.getTimeInMillis()), point); } switch (interval) { case day: fromCal.add(Calendar.DAY_OF_YEAR, 1); break; case hour: fromCal.add(Calendar.HOUR_OF_DAY, 1); break; case minute: fromCal.add(Calendar.MINUTE, 1); break; case month: fromCal.add(Calendar.MONTH, 1); break; case week: fromCal.add(Calendar.WEEK_OF_YEAR, 1); break; default: break; } } return index; }
From source file:com.ibm.mil.readyapps.physio.fragments.LandingFragment.java
private void setupMetricsTabs(View view) { LinearLayout metricsTabsArea = (LinearLayout) view.findViewById(R.id.metrics_tabs_area); heartRateTab = new HeartRateMetricsTab(getActivity(), null); heartRateTab.setOnClickListener(new View.OnClickListener() { @Override/*from w w w . j av a 2s . co m*/ public void onClick(View v) { openDetailedMetricsScreen(HealthDataRetriever.DataType.HEART_RATE); } }); metricsTabsArea.addView(heartRateTab); if (DataManager.getCurrentPatient() == null) { return; } stepsTab = new StepsMetricsTab(getActivity(), null); stepsTab.setStepsGoal(DataManager.getCurrentPatient().getStepGoal()); stepsTab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openDetailedMetricsScreen(HealthDataRetriever.DataType.STEPS); } }); metricsTabsArea.addView(stepsTab); weightTab = new WeightMetricsTab(getActivity(), null); weightTab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openDetailedMetricsScreen(HealthDataRetriever.DataType.WEIGHT); } }); metricsTabsArea.addView(weightTab); Calendar cal = Calendar.getInstance(); Date now = new Date(); cal.setTime(now); cal.add(Calendar.WEEK_OF_YEAR, -1); Date startDate = cal.getTime(); HealthDataRetriever.Builder builder = new HealthDataRetriever.Builder().startDate(startDate).endDate(now) .timeUnit(TimeUnit.DAYS).timeInterval(1); HealthDataRetriever stepsRetriever = builder.dataType(HealthDataRetriever.DataType.STEPS) .handler(new HealthDataRetriever.Handler() { @Override public void handle(final List<Integer> data) { if (data != null) { stepsTab.setSteps(Utils.sum(data)); } } }).build(); stepsRetriever.retrieve(mClient); HealthDataRetriever weightRetriever = builder.dataType(HealthDataRetriever.DataType.WEIGHT) .handler(new HealthDataRetriever.Handler() { @Override public void handle(final List<Integer> data) { if (data != null) { int lastWeight = data.get(data.size() - 1); int firstWeight = data.get(0); int netWeight = lastWeight - firstWeight; weightTab.setWeight(lastWeight); weightTab.setNetWeight(netWeight); } } }).build(); weightRetriever.retrieve(mClient); HealthDataRetriever heartRateRetriever = builder.dataType(HealthDataRetriever.DataType.HEART_RATE) .handler(new HealthDataRetriever.Handler() { @Override public void handle(final List<Integer> data) { if (data != null) { heartRateTab.setBeatsPerMin(Utils.average(data)); heartRateTab.setMinMaxBpm(Utils.min(data), Utils.max(data)); } } }).build(); heartRateRetriever.retrieve(mClient); RelativeLayout metricsSwipeArea = (RelativeLayout) view.findViewById(R.id.metrics_swipe_area); metricsSwipeArea.setOnTouchListener(new OnSwipeTouchListener(getActivity()) { @Override public void onSwipeLeft() { if (!metricsIsOpen) { animateMetricsIn(false); metricsIsOpen = true; } } @Override public void onSwipeRight() { if (metricsIsOpen) { animateMetricsOut(false); metricsIsOpen = false; } } }); animateMetricsOut(true); }
From source file:com.antsdb.saltedfish.sql.vdm.FuncDateFormat.java
private String format(String format, Timestamp time) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < format.length(); i++) { char ch = format.charAt(i); if (ch != '%') { buf.append(ch);/* w ww .ja v a 2s.com*/ continue; } if (i >= (format.length() - 1)) { buf.append(ch); continue; } char specifier = format.charAt(++i); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time.getTime()); if (specifier == 'a') { throw new NotImplementedException(); } else if (specifier == 'b') { throw new NotImplementedException(); } else if (specifier == 'c') { buf.append(calendar.get(Calendar.MONTH + 1)); } else if (specifier == 'd') { int day = calendar.get(Calendar.DAY_OF_MONTH); if (day < 10) { buf.append('0'); } buf.append(day); } else if (specifier == 'D') { throw new NotImplementedException(); } else if (specifier == 'e') { buf.append(calendar.get(Calendar.DAY_OF_MONTH)); } else if (specifier == 'f') { buf.append(calendar.get(Calendar.MILLISECOND * 1000)); } else if (specifier == 'H') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'h') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'i') { buf.append(calendar.get(Calendar.MINUTE)); } else if (specifier == 'I') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'j') { buf.append(calendar.get(Calendar.DAY_OF_YEAR)); } else if (specifier == 'k') { buf.append(calendar.get(Calendar.HOUR)); } else if (specifier == 'l') { buf.append(calendar.get(Calendar.HOUR) % 13); } else if (specifier == 'm') { int month = calendar.get(Calendar.MONTH) + 1; if (month < 10) { buf.append('0'); } buf.append(calendar.get(Calendar.MONTH) + 1); } else if (specifier == 'M') { buf.append(calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())); } else if (specifier == 'p') { int hour = calendar.get(Calendar.HOUR); buf.append(hour < 12 ? "AM" : "PM"); } else if (specifier == 'r') { int hour = calendar.get(Calendar.HOUR); hour = hour % 13; if (hour < 10) { buf.append('0'); } buf.append(hour); buf.append(':'); int minute = calendar.get(Calendar.MINUTE); if (minute < 10) { buf.append('0'); } buf.append(minute); buf.append(':'); int second = calendar.get(Calendar.SECOND); if (second < 10) { buf.append('0'); } buf.append(second); buf.append(hour < 12 ? " AM" : " PM"); } else if (specifier == 's') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'S') { buf.append(calendar.get(Calendar.SECOND)); } else if (specifier == 'T') { throw new NotImplementedException(); } else if (specifier == 'u') { buf.append(calendar.get(Calendar.WEEK_OF_YEAR)); } else if (specifier == 'U') { throw new NotImplementedException(); } else if (specifier == 'v') { throw new NotImplementedException(); } else if (specifier == 'V') { throw new NotImplementedException(); } else if (specifier == 'w') { throw new NotImplementedException(); } else if (specifier == 'W') { throw new NotImplementedException(); } else if (specifier == 'x') { throw new NotImplementedException(); } else if (specifier == 'X') { throw new NotImplementedException(); } else if (specifier == 'y') { buf.append(calendar.get(Calendar.YEAR) % 100); } else if (specifier == 'Y') { buf.append(calendar.get(Calendar.YEAR)); } else if (specifier == '%') { buf.append('%'); } else { buf.append(specifier); } } return buf.toString(); }