List of usage examples for java.util Calendar MONDAY
int MONDAY
To view the source code for java.util Calendar MONDAY.
Click Source Link
From source file:org.squale.welcom.outils.Util.java
public static Date getNextMonday() { java.util.Date jour = new java.util.Date(); final Calendar cal = new GregorianCalendar(); cal.setTime(new java.util.Date(jour.getTime() + (24 * 60 * 60))); while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { jour = new java.util.Date(jour.getTime() + (24 * 60 * 60)); cal.setTime(jour);// w w w . j av a 2s . c om } return jour; }
From source file:com.baifendian.swordfish.execserver.parameter.placeholder.TimePlaceholderUtil.java
/** * ? <p>// w w w .ja v a 2s . co m */ public static Date getSunday(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); // ? cal.setFirstDayOfWeek(Calendar.MONDAY); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); return cal.getTime(); }
From source file:com.provision.alarmemi.paper.fragments.SetAlarmFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { mActivity.setOnLifeCycleChangeListener(this); isChanged = isCloud = false;//from w w w . ja v a 2s . co m // Override the default content view. root = (ViewGroup) super.onCreateView(inflater, container, bundle); final ImageView moreAlarm = (ImageView) root.findViewById(R.id.more_alarm); FragmentChangeActivity.moreAlarm = moreAlarm; moreAlarm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (menu.isMenuShowing()) { menu.showContent(); } else { menu.showMenu(true); } } }); // Make the entire view selected when focused. moreAlarm.setOnFocusChangeListener(new View.OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { v.setSelected(hasFocus); } }); addPreferencesFromResource(R.xml.alarm_prefs); myUUID = SplashActivity.myUUID; // Get each preference so we can retrieve the value later. mLabel = findPreference("label"); mLabel.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showEditTextPreference(mLabel.getKey(), mLabel.getTitle(), mLabelText); return true; } }); Preference.OnPreferenceChangeListener preferceChangedListener = new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference p, Object newValue) { isChanged = true; return true; } }; mEnabledPref = (CheckBoxPreference) findPreference("enabled"); mEnabledPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (!isCloud) { isChanged = true; if ((Boolean) newValue) showCategory(); else hideCategory(); return true; } if ((Boolean) newValue) { try { tempjson = new JSONArray("[]"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } selectedDevice = ""; for (int i = 0; i < json.length(); i++) { if (UIDitems[i].toString().equals(myUUID)) checkedItems[i] = true; if (checkedItems[i]) { Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } if (!selectedDevice.equals("")) selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2); } else { try { tempjson = new JSONArray("[]"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } selectedDevice = ""; for (int i = 0; i < json.length(); i++) { if (UIDitems[i].toString().equals(myUUID)) checkedItems[i] = false; if (checkedItems[i]) { Map<String, String> map = new HashMap<String, String>(); map.put("name", URLDecoder.decode(items[i].toString())); map.put("uid", UIDitems[i].toString()); tempjson.put(map); selectedDevice += items[i] + ", "; } } if (!selectedDevice.equals("")) selectedDevice = selectedDevice.substring(0, selectedDevice.length() - 2); } mForest.setSummary(selectedDevice); isChanged = true; return true; } }); mTimePref = findPreference("time"); mVibratePref = (CheckBoxPreference) findPreference("vibrate"); mVibratePref.setOnPreferenceChangeListener(preferceChangedListener); mRepeatPref = findPreference("setRepeat"); mRepeatPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { String[] values = new String[] { DateUtils.getDayOfWeekString(Calendar.MONDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.TUESDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.WEDNESDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.THURSDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.FRIDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.SATURDAY, DateUtils.LENGTH_LONG), DateUtils.getDayOfWeekString(Calendar.SUNDAY, DateUtils.LENGTH_LONG) }; Intent intent = new Intent(mActivity, RepeatListPreference.class); intent.putExtra("key", mRepeatPref.getKey()); intent.putExtra("title", mRepeatPref.getTitle()); intent.putExtra("lists", values); intent.putExtra("multi", true); startActivity(intent); return true; } }); mForestName = findPreference("forest_name"); mForest = findPreference("forest"); mColorPref = (AmbilWarnaPreference) findPreference("color"); prefs = mActivity.getSharedPreferences("forest", mActivity.MODE_PRIVATE); Intent i = mActivity.setAlarmGetIntent; mId = i.getIntExtra(Alarms.ALARM_ID, -1); alarm = null; if (mId == -1) { // No alarm id means create a new alarm. alarm = new Alarm(); isChanged = true; } else { // * load alarm details from database alarm = Alarms.getAlarm(mActivity.getContentResolver(), mId); // Bad alarm, bail to avoid a NPE. if (alarm == null) { finish(); return root; } isCloud = wasCloud = alarm.cloudEnabled; } mOriginalAlarm = alarm; if (wasCloud) { try { Log.e("url", " : " + alarm.cloudName); json = new JSONArray(prefs.getString(alarm.cloudName + "_registeredDevice", "")); String cloud_uid = alarm.cloudUID; if (cloud_uid.equals("")) cloud_uid = "[]"; Log.e("url", cloud_uid); tempjson = new JSONArray(cloud_uid); items = new String[json.length()]; UIDitems = new CharSequence[json.length()]; checkedItems = new boolean[json.length()]; for (int j = 0; j < json.length(); j++) { JSONObject jsonObj = json.getJSONObject(j); items[j] = jsonObj.getString("name"); UIDitems[j] = jsonObj.getString("uid"); checkedItems[j] = alarm.cloudUID.contains(jsonObj.getString("uid")); } } catch (Exception e) { Log.e("url", e.toString()); } selectedDevice = alarm.cloudDevices; mForestName.setEnabled(false); } else { if (prefs.getString("name", "").length() > 0) { names = prefs.getString("name", "").substring(1).split("\\|"); nameCheckedIndex = -1; } else mForestName.setEnabled(false); mForest.setEnabled(false); } memi_count = alarm.memiCount; snooze_strength = alarm.snoozeStrength; snooze_count = alarm.snoozeCount; updatePrefs(mOriginalAlarm); mTimePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { showTimePicker(); return false; } }); mForestName.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showListPreference(mForestName.getKey(), mForestName.getTitle(), names, String.valueOf(nameCheckedIndex), false); return true; } }); mForest.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { showListPreference(mForest.getKey(), mForest.getTitle(), items, booleanArrayToString(checkedItems), true); return true; } }); mColorPref.setOnPreferenceChangeListener(preferceChangedListener); // We have to do this to get the save/cancel buttons to highlight on // their own. ((ListView) root.findViewById(android.R.id.list)).setItemsCanFocus(true); // Attach actions to each button. View.OnClickListener back_click = new View.OnClickListener() { public void onClick(View v) { DontSaveDialog(false, null, false); } }; ImageView b = (ImageView) root.findViewById(R.id.back); b.setOnClickListener(back_click); b = (ImageView) root.findViewById(R.id.logo); b.setOnClickListener(back_click); b = (ImageView) root.findViewById(R.id.alarm_save); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { saveAlarm(); } }); b = (ImageView) root.findViewById(R.id.alarm_delete); if (mId == -1) { b.setEnabled(false); } else { b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { deleteAlarm(); } }); } // The last thing we do is pop the time picker if this is a new alarm. if (mId == -1) { // Assume the user hit cancel mTimePickerCancelled = true; showTimePicker(); } if (!isCloud && !alarm.enabled) hideCategory(); FragmentChangeActivity.OnNotifyArrived.sendEmptyMessage(0); return root; }
From source file:CalendarUtils.java
/** * This constructs an Iterator that will start and stop over a date * range based on the focused date and the range style. For instance, * passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return * an Iterator that starts with Sunday, June 30, 2002 and ends with * Saturday, August 3, 2002.//from ww w . j a v a 2s.co m */ public static Iterator getCalendarIterator(Calendar focus, int rangeStyle) { Calendar start = null; Calendar end = null; int startCutoff = Calendar.SUNDAY; int endCutoff = Calendar.SATURDAY; switch (rangeStyle) { case RANGE_MONTH_SUNDAY: case RANGE_MONTH_MONDAY: //Set start to the first of the month start = trunc(focus, Calendar.MONTH); //Set end to the last of the month end = (Calendar) start.clone(); end.add(Calendar.MONTH, 1); end.add(Calendar.DATE, -1); //Loop start back to the previous sunday or monday if (rangeStyle == RANGE_MONTH_MONDAY) { startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; } break; case RANGE_WEEK_SUNDAY: case RANGE_WEEK_MONDAY: case RANGE_WEEK_RELATIVE: case RANGE_WEEK_CENTER: //Set start and end to the current date start = trunc(focus, Calendar.DATE); end = trunc(focus, Calendar.DATE); switch (rangeStyle) { case RANGE_WEEK_SUNDAY: //already set by default break; case RANGE_WEEK_MONDAY: startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; break; case RANGE_WEEK_RELATIVE: startCutoff = focus.get(Calendar.DAY_OF_WEEK); endCutoff = startCutoff - 1; break; case RANGE_WEEK_CENTER: startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3; endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3; break; } break; default: throw new RuntimeException("The range style " + rangeStyle + " is not valid."); } if (startCutoff < Calendar.SUNDAY) { startCutoff += 7; } if (endCutoff > Calendar.SATURDAY) { endCutoff -= 7; } while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) { start.add(Calendar.DATE, -1); } while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) { end.add(Calendar.DATE, 1); } final Calendar startFinal = start; final Calendar endFinal = end; Iterator it = new Iterator() { Calendar spot = null; { spot = startFinal; spot.add(Calendar.DATE, -1); } public boolean hasNext() { return spot.before(endFinal); } public Object next() { if (spot.equals(endFinal)) { throw new NoSuchElementException(); } spot.add(Calendar.DATE, 1); return spot.clone(); } public void remove() { throw new UnsupportedOperationException(); } }; return it; }
From source file:GenAppStoreSales.java
private static void readSales(String periodTime, boolean restoreSales, boolean computeSales) throws IOException { countryLabels = new ArrayList<String>(); countryUnits = new ArrayList<ArrayList<Integer>>(); countryInAppLabels = new ArrayList<String>(); countryInAppUnits = new ArrayList<ArrayList<Integer>>(); int t = 0, periodDays = 0; boolean anotherDay = true; if (periodTime.equals("day")) periodDays = 1;/*from ww w . ja v a 2 s .c om*/ else if (periodTime.equals("week")) periodDays = 7; else if (periodTime.equals("month")) periodDays = rollCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); else if (periodTime.equals("year")) periodDays = rollCalendar.getActualMaximum(Calendar.DAY_OF_YEAR); else if (periodTime.equals("custom")) { while (rollCalendar.compareTo(customCalendar) > 0) { rollCalendar.add(Calendar.DATE, -1); periodDays++; } rollCalendar.add(Calendar.DATE, periodDays); } while (anotherDay) { String dateCode = String.format("%d%02d%02d", pursuedYear, pursuedMonth, pursuedDay); String reportName = "S_D_" + appID + "_" + dateCode + ".txt"; File salesFile = new File(sourcePath + "/" + reportName); if (salesFile.isFile()) { String SKU, productCountry; int productUnits; boolean update; float productPrice; BufferedReader salesFileReader = new BufferedReader(new FileReader(sourcePath + "/" + reportName)); String line = salesFileReader.readLine(); // skips the first line while ((line = salesFileReader.readLine()) != null) { String[] columns = line.split("\t"); // SKU SKU = columns[2]; // Product Units if (columns[6].equals("7T")) update = true; else update = false; productUnits = Integer.parseInt(columns[7]); // Product Price productPrice = Float.parseFloat(columns[8]); // Country Code productCountry = columns[12]; // System.out.println("SKU " + SKU + " Units " + productUnits + " Country Code " + productCountry); if (SKU.equals(appSKU)) { if (periodTime.equals("day")) { dayUnits += productUnits; } if (computeSales) { totalUnits += productUnits; if (update) { totalUpdateUnits += productUnits; } } if (restoreSales) { int index = countryLabels.indexOf(productCountry); if (index < 0) { countryLabels.add(productCountry); countryUnits.add(new ArrayList<Integer>(Collections.nCopies(periodDays, 0))); countryUnits.get(countryUnits.size() - 1).set(t, productUnits); } else countryUnits.get(index).set(t, productUnits); } } else { if (periodTime.equals("day")) { dayINAPPUnits += productUnits; } if (computeSales) { totalInAppUnits += productUnits; } if (restoreSales) { int index = countryInAppLabels.indexOf(productCountry); if (index < 0) { countryInAppLabels.add(productCountry); countryInAppUnits.add(new ArrayList<Integer>(Collections.nCopies(periodDays, 0))); countryInAppUnits.get(countryInAppUnits.size() - 1).set(t, productUnits); } else countryInAppUnits.get(index).set(t, productUnits); } } } salesFileReader.close(); } if (periodTime.equals("day")) { anotherDay = false; } else if (periodTime.equals("week")) { if (rollCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) { anotherDay = false; } } else if (periodTime.equals("month")) { if (rollCalendar.get(Calendar.DAY_OF_MONTH) == 1) { anotherDay = false; } } else if (periodTime.equals("year")) { if (rollCalendar.get(Calendar.DAY_OF_YEAR) == 1) { anotherDay = false; } } else if (periodTime.equals("custom")) { if (rollCalendar.compareTo(customCalendar) <= 0) { anotherDay = false; } } rollCalendar.add(Calendar.DATE, -1); updateRollCalendar(); t++; } }
From source file:com.projity.pm.calendar.WorkingCalendar.java
static WorkingCalendar getNightShiftInstance() { if (nightShiftInstance != null) return nightShiftInstance; nightShiftInstance = WorkingCalendar.getStandardBasedInstance(); WorkDay nonWorking = null;//from w w w .jav a2 s . c om WorkDay working = null; nonWorking = new WorkDay(); working = new WorkDay(); nonWorking.getWorkingHours().setNonWorking(); nightShiftInstance.setWeekDay(Calendar.SUNDAY - 1, null); // will revert to overall default for sunday which is not working WorkDay monday = new WorkDay(); try { monday.getWorkingHours().setInterval(0, hourTime(23), hourTime(0)); } catch (WorkRangeException e) { e.printStackTrace(); } nightShiftInstance.setWeekDay(Calendar.MONDAY - 1, monday); try { working.getWorkingHours().setInterval(0, hourTime(0), hourTime(3)); working.getWorkingHours().setInterval(1, hourTime(4), hourTime(8)); working.getWorkingHours().setInterval(2, hourTime(23), hourTime(0)); } catch (WorkRangeException e) { e.printStackTrace(); } nightShiftInstance.setWeekDay(Calendar.TUESDAY - 1, working); nightShiftInstance.setWeekDay(Calendar.WEDNESDAY - 1, working); nightShiftInstance.setWeekDay(Calendar.THURSDAY - 1, working); nightShiftInstance.setWeekDay(Calendar.FRIDAY - 1, working); WorkDay saturday = new WorkDay(); try { saturday.getWorkingHours().setInterval(0, hourTime(0), hourTime(3)); saturday.getWorkingHours().setInterval(1, hourTime(4), hourTime(8)); } catch (WorkRangeException e) { e.printStackTrace(); } nightShiftInstance.setWeekDay(Calendar.SATURDAY - 1, saturday); nightShiftInstance.setName(Messages.getString("Calendar.NightShift")); nightShiftInstance.setFixedId(3); CalendarService.getInstance().add(nightShiftInstance); // put night shift calendar in list return nightShiftInstance; }
From source file:org.callistasoftware.netcare.core.spi.HealthPlanServiceTest.java
@Test @Transactional/*from w ww . jav a2 s .c o m*/ @Rollback(true) public void testAddActivityDefintion() throws Exception { final CountyCouncilEntity cc = ccRepo.save(CountyCouncilEntity.newEntity(CountyCouncil.STOCKHOLM)); final ActivityCategoryEntity cat = this.catRepo.save(ActivityCategoryEntity.newEntity("Fysisk aktivitet")); final CareUnitEntity cu = CareUnitEntity.newEntity("cu", cc); this.cuRepo.save(cu); final ActivityTypeEntity type = ActivityTypeEntity.newEntity("Lpning", cat, cu, AccessLevel.CAREUNIT); MeasurementTypeEntity.newEntity(type, "Distans", MeasurementValueType.SINGLE_VALUE, newMeasureUnit("m", "Meter", cc), false, 0); MeasurementTypeEntity me = MeasurementTypeEntity.newEntity(type, "Vikt", MeasurementValueType.INTERVAL, newMeasureUnit("kg", "Kilogram", cc), true, 1); final ActivityTypeEntity savedType = typeRepo.saveAndFlush(type); final CareActorEntity ca = CareActorEntity.newEntity("Test Testgren", "", "hsa-123", cu); final CareActorEntity savedCa = this.careActorRepo.save(ca); final PatientEntity patient = PatientEntity.newEntity("Marcus Krantz", "", "123456789004"); final PatientEntity savedPatient = this.patientRepo.save(patient); // the date and duration can't be changed without breaking the test, see // further below. final HealthPlanEntity ord = HealthPlanEntity.newEntity(savedCa, savedPatient, "Test", ApiUtil.parseDate("2012-12-01"), 12, DurationUnit.WEEK); final HealthPlanEntity savedOrd = this.ordinationRepo.save(ord); final ActivityTypeImpl typeImpl = new ActivityTypeImpl(); typeImpl.setId(savedType.getId()); typeImpl.setName("Lpning"); final ActivityItemTypeImpl mdType = new ActivityItemTypeImpl(); mdType.setId(me.getId()); mdType.setName(me.getName()); final MeasurementDefinitionImpl md = new MeasurementDefinitionImpl(); md.setTarget(1200); md.setActivityItemType(mdType); final ActivityDefinitionImpl impl = new ActivityDefinitionImpl(); impl.setHealthPlanId(savedOrd.getId()); impl.setType(typeImpl); impl.setActivityRepeat(2); impl.setGoalValues(new MeasurementDefinitionImpl[] { md }); // Monday and saturday final DayTimeImpl dt = new DayTimeImpl(); dt.setDay("monday"); dt.setTimes(new String[] { "12:15", "18:45" }); final DayTimeImpl dt2 = new DayTimeImpl(); dt2.setDay("saturday"); dt2.setTimes(new String[] { "12:15", "18:45" }); final DayTimeImpl[] dts = new DayTimeImpl[2]; dts[0] = dt; dts[1] = dt2; impl.setDayTimes(dts); final CareActorBaseView cabv = CareActorBaseViewImpl.newFromEntity(savedCa); this.runAs(cabv); final ServiceResult<ActivityDefinition> result = this.service.addActvitiyToHealthPlan(impl); assertTrue(result.isSuccess()); final ActivityDefinitionImpl impl2 = new ActivityDefinitionImpl(); impl2.setHealthPlanId(savedOrd.getId()); impl2.setType(typeImpl); impl2.setActivityRepeat(0); impl2.setStartDate("2013-01-30"); impl2.setGoalValues(new MeasurementDefinitionImpl[] { md }); // Wednesday (1 time activity) final DayTimeImpl dt3 = new DayTimeImpl(); dt3.setDay("wednesday"); dt3.setTimes(new String[] { "07:15", "12:00", "22:45" }); impl2.setDayTimes(new DayTimeImpl[] { dt3 }); this.runAs(CareActorBaseViewImpl.newFromEntity(ca)); final ServiceResult<ActivityDefinition> result2 = this.service.addActvitiyToHealthPlan(impl2); assertTrue(result2.isSuccess()); this.schedRepo.flush(); this.ordinationRepo.flush(); final HealthPlanEntity after = this.ordinationRepo.findOne(savedOrd.getId()); final ActivityDefinitionEntity ent = after.getActivityDefinitions().get(0); // FIXME: multi-values assertEquals(newMeasureUnit("m", "Meter", cc), ((MeasurementTypeEntity) ent.getActivityItemDefinitions().get(0).getActivityItemType()).getUnit()); assertEquals("Lpning", ent.getActivityType().getName()); // FIXME: multi-values // assertEquals(12, ent.getActivityTarget()); final Frequency fr = ent.getFrequency(); final List<FrequencyTime> times = fr.getDay(Calendar.MONDAY).getTimes(); assertEquals(2, times.size()); assertEquals("2012-12-01", ApiUtil.formatDate(after.getStartDate())); assertEquals(12, times.get(0).getHour()); assertEquals(15, times.get(0).getMinute()); assertEquals(18, times.get(1).getHour()); assertEquals(45, times.get(1).getMinute()); assertTrue(fr.isDaySet(Calendar.MONDAY)); assertTrue(fr.isDaySet(Calendar.SATURDAY)); assertEquals(2, fr.getWeekFrequency()); assertEquals("7,12:15,18:45", FrequencyDay.marshal(fr.getDay(Calendar.SATURDAY))); // check Date startDate = after.getStartDate(); Date endDate = after.getEndDate(); List<ScheduledActivityEntity> scheduledActivities = schedRepo .findByPatientAndScheduledTimeBetween(savedPatient, startDate, endDate); Collections.sort(scheduledActivities); int n = scheduledActivities.size(); // 26 (every other week * 2) + 3 (single day * 3) assertEquals(29, n); assertEquals("2013-02-23", ApiUtil.formatDate(scheduledActivities.get(n - 1).getScheduledTime())); }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on Weight , date start and resource * @param start/*from w w w .ja v a 2 s .c om*/ * @param resource * @return CategoryDataset */ protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID()); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?", rosource.getAD_Client_ID()); double dailyCapacity = rosource.getDailyCapacity().doubleValue(); double utilization = rosource.getPercentUtilization().doubleValue(); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:org.kuali.student.r2.core.scheduling.service.impl.TestSchedulingServiceImpl.java
@Test public void testgetTimeSlot() throws Exception { // test get by id for (int i = 1; i <= 16; i++) { int tsId = 100 + i; TimeSlot ts = schedulingService.getTimeSlot("ts" + tsId, contextInfo); assertNotNull(ts);/*ww w . ja v a 2 s. c o m*/ assertEquals("ts" + tsId, ts.getId()); } // test specific records - 2 TimeSlot ts = schedulingService.getTimeSlot("ts102", contextInfo); List<Integer> dow = ts.getWeekdays(); // should contain Monday, Wednesday, Friday assertTrue(dow.contains(Calendar.MONDAY)); assertTrue(dow.contains(Calendar.WEDNESDAY)); assertTrue(dow.contains(Calendar.FRIDAY)); // should not contain Tuesday or Thursday assertFalse(dow.contains(Calendar.TUESDAY)); assertFalse(dow.contains(Calendar.THURSDAY)); assertEquals(ts.getStartTime(), TOD_8_AM); assertEquals(ts.getEndTime(), TOD_9_10_AM); // test specific records - 3 ts = schedulingService.getTimeSlot("ts103", contextInfo); dow = ts.getWeekdays(); // should not contain Monday, Wednesday, Friday assertFalse(dow.contains(Calendar.MONDAY)); assertFalse(dow.contains(Calendar.WEDNESDAY)); assertFalse(dow.contains(Calendar.FRIDAY)); // should contain Tuesday or Thursday assertTrue(dow.contains(Calendar.TUESDAY)); assertTrue(dow.contains(Calendar.THURSDAY)); assertEquals(ts.getStartTime(), TOD_8_AM); assertEquals(ts.getEndTime(), TOD_8_50_AM); // test specific records - 10 ts = schedulingService.getTimeSlot("ts110", contextInfo); dow = ts.getWeekdays(); // should contain Monday, Wednesday, Friday assertTrue(dow.contains(Calendar.MONDAY)); assertTrue(dow.contains(Calendar.WEDNESDAY)); assertTrue(dow.contains(Calendar.FRIDAY)); // should not contain Tuesday or Thursday assertFalse(dow.contains(Calendar.TUESDAY)); assertFalse(dow.contains(Calendar.THURSDAY)); assertEquals(ts.getStartTime(), TOD_1_PM); assertEquals(ts.getEndTime(), TOD_2_10_PM); }
From source file:org.web4thejob.web.panel.DefaultCalendarViewPanel.java
@Override protected void registerSettings() { super.registerSettings(); registerSetting(SettingEnum.MOLD, null); registerSetting(CalendarSettingEnum.CALENDAR_DAYS, 7); registerSetting(CalendarSettingEnum.CALENDAR_TIMESLOTS, 2); registerSetting(CalendarSettingEnum.CALENDAR_TIMEZONE, null); registerSetting(CalendarSettingEnum.CALENDAR_FIRST_DAY_OF_WEEK, Calendar.MONDAY); registerSetting(CalendarSettingEnum.CALENDAR_WEEK_OF_YEAR, false); registerSetting(CalendarSettingEnum.CALENDAR_START_TIME, 7); registerSetting(CalendarSettingEnum.CALENDAR_END_TIME, 24); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_START, null); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_END, null); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_TITLE, null); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_TITLE_COLOR, null); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_CONTENT, null); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_CONTENT_COLOR, null); registerSetting(CalendarSettingEnum.CALENDAR_EVENT_LOCKED, null); }