List of usage examples for java.util Calendar SATURDAY
int SATURDAY
To view the source code for java.util Calendar SATURDAY.
Click Source Link
From source file:com.ubundude.timesheet.ReportFragment.java
/** * Method to get the Calendar day of week Integer * //from w w w . j a va 2 s . co m * @param lFirstDay The day of the from the shared preferences * @return DOW The integer for the day of the week */ private int getFirstDay(String lFirstDay) { int DOW = Calendar.SUNDAY; if (lFirstDay == "MONDAY") DOW = Calendar.MONDAY; else if (lFirstDay == "TUESDAY") DOW = Calendar.TUESDAY; else if (lFirstDay == "WEDNESDAY") DOW = Calendar.WEDNESDAY; else if (lFirstDay == "THURSDAY") DOW = Calendar.THURSDAY; else if (lFirstDay == "FRIDAY") DOW = Calendar.FRIDAY; else if (lFirstDay == "SATURDAY") DOW = Calendar.SATURDAY; return DOW; }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * Create blocks that span noon./*w w w . ja v a 2 s . c o m*/ * * @throws Exception */ @Test public void testCreateBlocksExample4() throws Exception { SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); Date startDate = dateFormat.parse("20080601"); Date endDate = dateFormat.parse("20080630"); Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("11:45 AM", "12:15 PM", "MTWRF", startDate, endDate); assertEquals(21, blocks.size()); for (AvailableBlock block : blocks) { assertEquals(30, block.getDurationInMinutes()); Calendar cal = Calendar.getInstance(); cal.setTime(block.getStartTime()); assertEquals(11, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(45, cal.get(Calendar.MINUTE)); cal.setTime(block.getEndTime()); assertEquals(12, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(15, cal.get(Calendar.MINUTE)); assertNotSame(Calendar.SATURDAY, cal.get(Calendar.DAY_OF_WEEK)); assertNotSame(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK)); assertEquals(1, block.getVisitorLimit()); } blocks = AvailableBlockBuilder.createBlocks("11:45 AM", "12:15 PM", "MTWRF", startDate, endDate, 2); assertEquals(21, blocks.size()); for (AvailableBlock block : blocks) { assertEquals(30, block.getDurationInMinutes()); Calendar cal = Calendar.getInstance(); cal.setTime(block.getStartTime()); assertEquals(11, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(45, cal.get(Calendar.MINUTE)); cal.setTime(block.getEndTime()); assertEquals(12, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(15, cal.get(Calendar.MINUTE)); assertNotSame(Calendar.SATURDAY, cal.get(Calendar.DAY_OF_WEEK)); assertNotSame(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK)); assertEquals(2, block.getVisitorLimit()); } }
From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java
/** * Groups the original values into a sparse array. * The outer sparse array is indexed by the group field. * The inner sparse array is indexed by the index field. * If groupField and indexField are the same, then the outer sparse array contains only 1 entry * index by 0 and the inner sparse array is indexed by indexField. * @param original the original value returned from the SQL query. * @param groupField the field used to group the outer sparse array. * @param indexField the field used to group the inner sparse array. * @return a bidimensional sparse array indexed by groupField and indexField. *//*www . j av a2 s . c o m*/ private SparseArray<SparseArray<Double>> groupValues(final SparseArray<Pair<Date, Double>> original, final int groupField, final int indexField) { final Calendar calendar = Calendar.getInstance(); final SparseArray<SparseArray<Double>> weeks = new SparseArray<>(); for (int i = 0; i < original.size(); i++) { try { final int key = original.keyAt(i); calendar.setTime(original.get(key).first); final double value = original.get(key).second; final int indexValue = calendar.get(indexField); final int groupValue = groupField == indexField ? 0 : calendar.get(groupField); SparseArray<Double> currentWeek = weeks.get(groupValue); if (currentWeek == null) { currentWeek = new SparseArray<>(); weeks.put(groupValue, currentWeek); } currentWeek.put(indexValue, value); } catch (Exception e) { Log.e(e.getMessage()); } } // normalize the data // if the index field is DAY_OF_WEEK, then we'll add the remaining days to fill // the week from sunday until saturday if (indexField == Calendar.DAY_OF_WEEK) { for (int i = 0; i < weeks.size(); i++) { final int key = weeks.keyAt(i); SparseArray<Double> currentWeek = weeks.get(key); for (int j = Calendar.SUNDAY; j <= Calendar.SATURDAY; j++) { if (currentWeek.get(j) == null) { currentWeek.put(j, 0.0); } } } } return weeks; }
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on date start and resource * @param start// w ww .j av a 2 s .c om * @param resource * @return CategoryDataset */ protected CategoryDataset createDataset(Timestamp start, MResource resource) { 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); Timestamp date = start; String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID()); int days = 1; long hours = t.getTimeSlotHours(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Long Hours = new Long(hours); int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", resource.getS_Resource_ID()); MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID); if (!uom.isHour()) { return dataset; } long summary = 0; while (days < 32) { String day = new String(new Integer(date.getDate()).toString()); long HoursLoad = getLoad(resource, date).longValue(); Long Hours = new Long(hours); switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: days++; if (t.isOnSunday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.MONDAY: days++; if (t.isOnMonday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.TUESDAY: days++; if (t.isOnTuesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.WEDNESDAY: days++; if (t.isOnWednesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.THURSDAY: days++; if (t.isOnThursday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.FRIDAY: days++; if (t.isOnFriday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.SATURDAY: days++; if (t.isOnSaturday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } } } return dataset; }
From source file:com.autentia.intra.bean.activity.ObjectiveBean.java
/** * Move a date to one of its surrounding fridays. * * @param d the reference date//from www.j a va 2 s. c o m * @param inFuture whether to move to future/previous friday * @return the requested friday */ private Date moveToFriday(Date d, boolean inFuture) { Calendar cal = Calendar.getInstance(); cal.setTime(d); switch (cal.get(Calendar.DAY_OF_WEEK)) { case Calendar.MONDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 4 : -3); break; case Calendar.TUESDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 3 : -4); break; case Calendar.WEDNESDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 2 : -5); break; case Calendar.THURSDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 1 : -6); break; case Calendar.FRIDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 0 : -7); break; case Calendar.SATURDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 6 : -1); break; case Calendar.SUNDAY: cal.add(Calendar.DAY_OF_WEEK, inFuture ? 5 : -2); break; } return cal.getTime(); }
From source file:org.activequant.util.charting.IntradayMarketTimeline.java
/** * Translates a value relative to this timeline into a domain value. The * domain value obtained by this method is not always the same domain value * that could have been supplied to/*from w ww. ja va 2 s . c o m*/ * translateDomainValueToTimelineValue(domainValue). * This is because the original tranformation may not be complete * reversable. * * @see org.jfree.chart.axis.SegmentedTimeline * * @param timelineValue a timeline value. * * @return A domain value. */ public long toMillisecond(long timelineValue) { if (this.activeTimePerWeek == 0L) return 0; //starting from Jan 1, 1970 work backwards. //find out the number of whole weeks in the timelineValue Long l = new Long(timelineValue / this.activeTimePerWeek); int numWeeks = (int) Math.floor(l.doubleValue()); //the amount of time left on the timeline from the last thursday long timeLeftSinceThursday = timelineValue - (numWeeks * this.activeTimePerWeek); int day = Calendar.THURSDAY; int numDays = 0; //from last friday until the current day //if the amount of time left is greater than //the active time for that day, increment the number of //days and subtract from the time left while (numDays < 7) { if (day == Calendar.SUNDAY) { if (timeLeftSinceThursday > this.sundayActive) { timeLeftSinceThursday -= this.sundayActive; numDays++; } else { break; } } else if (day == Calendar.MONDAY) { if (timeLeftSinceThursday > this.mondayActive) { timeLeftSinceThursday -= this.mondayActive; numDays++; } else { break; } } else if (day == Calendar.TUESDAY) { if (timeLeftSinceThursday > this.tuesdayActive) { timeLeftSinceThursday -= this.tuesdayActive; numDays++; } else { break; } } else if (day == Calendar.WEDNESDAY) { if (timeLeftSinceThursday > this.wednesdayActive) { timeLeftSinceThursday -= this.wednesdayActive; numDays++; } else { break; } } else if (day == Calendar.THURSDAY) { if (timeLeftSinceThursday > this.thursdayActive) { timeLeftSinceThursday -= this.thursdayActive; numDays++; //thursday numDays = " + Integer.toString(numDays)); } else { break; } } else if (day == Calendar.FRIDAY) { if (timeLeftSinceThursday > this.fridayActive) { timeLeftSinceThursday -= this.fridayActive; numDays++; } else { break; } } else if (day == Calendar.SATURDAY) { if (timeLeftSinceThursday > this.saturdayActive) { timeLeftSinceThursday -= this.saturdayActive; numDays++; } else { break; } } day = this.nextDay(day); } long millis = numWeeks * MILLIS_PER_WEEK + numDays * MILLIS_PER_DAY + this.getStartTime(day) + timeLeftSinceThursday; return millis; }
From source file:org.energy_home.jemma.internal.ah.eh.esp.ESPHapServiceObject.java
private Float getFloatValueMonthlyForecast(AHContainerAddress dailyContainerId, AHContainerAddress wdHourlyAvgContainerId) throws M2MHapException { Calendar c = Calendar.getInstance(); long now = c.getTimeInMillis(); int todayDayOfWeek = c.get(Calendar.DAY_OF_WEEK); int todayMonth = c.get(Calendar.MONTH); int todayDayOfYear = c.get(Calendar.DAY_OF_YEAR); float currentMonthEstimation = 0; boolean useTodayEstimation = false; float todayEstimation = 0; long totalDuration = 0; long startTime = getNormalizedStartTime(c, now, ESPService.MONTH_RESOLUTION); long endTime = now; long lastTime = startTime; long lastDuration = 0; int todayEstimationFirstHour = 0; int todayEstimationLastHour = 0; ContentInstance ci = null;//from w w w . jav a 2 s. c om Float lastValue = null; Float value = null; // Retrieves current month daily consumption and sum ContentInstanceItems items = getItemsWithHapCache(c, dailyContainerId, startTime, endTime, ESPService.DAY_RESOLUTION); if (items != null) { List<ContentInstance> resultList = items.getContentInstances(); if (resultList != null) { ContentInstance contentInstance = null; FloatDV floatDV = null; for (Iterator<ContentInstance> iterator = resultList.iterator(); iterator.hasNext();) { contentInstance = iterator.next(); floatDV = (FloatDV) contentInstance.getContent(); if (floatDV != null) { value = floatDV.getValue(); if (!iterator.hasNext()) { lastValue = value; lastTime = contentInstance.getId().longValue(); lastDuration = floatDV.getDuration(); } else if (value != null) { currentMonthEstimation += value.floatValue(); totalDuration += floatDV.getDuration(); } } } log.info("getFloatValueMonthlyForecast - current month daily consumption returned: monthTotal=" + currentMonthEstimation + ", monthTotalDuration=" + totalDuration + ", lastValue=" + lastValue + ", lastTime=" + lastTime + ", lastDuration=" + lastDuration); } } else { return null; } // Fix duration error for all daily measures but the last one long durationError = (lastTime - startTime) - totalDuration; if (totalDuration != 0 && durationError > DateUtils.MILLISEC_IN_ONE_HOUR) currentMonthEstimation += currentMonthEstimation * ((float) durationError) / (lastTime - startTime); // // If total error for daily measures is greater than max error // tolerance a null value is returned // totalDuration += lastDuration; // if ((now - startTime) > totalDuration*(1+DURATION_ERROR_TOLERANCE)) // return null; // If a partial estimation for today is available, use it current day // estimation if (lastDuration > 0 && lastTime >= getNormalizedStartTime(c, now, ESPService.DAY_RESOLUTION)) { c.setTimeInMillis(lastTime); todayEstimationFirstHour = c.get(Calendar.HOUR_OF_DAY); c.setTimeInMillis(lastTime + lastDuration); todayEstimationLastHour = c.get(Calendar.HOUR_OF_DAY) - 1; if (c.get(Calendar.DAY_OF_YEAR) != todayDayOfYear) todayEstimationLastHour = 23; int estimatedNrOfHours = todayEstimationLastHour - todayEstimationFirstHour + 1; if (estimatedNrOfHours > 0) { useTodayEstimation = true; // Fix last duration error todayEstimation = (lastValue / lastDuration) * estimatedNrOfHours * DateUtils.MILLISEC_IN_ONE_HOUR; } } // Calculate an estimation for the average consumption of each week day, // including today estimation float[] weekDayEstimation = { 0, 0, 0, 0, 0, 0, 0 }; weekDayEstimation[todayDayOfWeek - 1] = todayEstimation; ContentInstanceItems weekDayItems = getNormalizedWeekDayItems(wdHourlyAvgContainerId, getHourlyDayOfWeekStartIndex(Calendar.SUNDAY), getHourlyDayOfWeekEndIndex(Calendar.SATURDAY)); if (weekDayItems == null) { log.warn("getFloatValueMonthlyForecast - week day average consumption returned null items\n"); return null; } List<ContentInstance> weekDayItemList = weekDayItems.getContentInstances(); if (weekDayItemList == null || weekDayItemList.size() == 0) { log.warn( "getFloatValueMonthlyForecast - week day average consumption returned null or 0 sized item list\n"); return null; } log.info("getFloatValueMonthlyForecast - week day average consumption returned\n" + weekDayItems); int weekDayIndex = 1; int hourlyIndex = 0; int nrOfMissingAvgValues = 0; for (Iterator<ContentInstance> iterator = weekDayItemList.iterator(); iterator.hasNext();) { ci = (ContentInstance) iterator.next(); value = toFloat(ci); if (value != null && value.floatValue() >= 0) { if (!useTodayEstimation || weekDayIndex != todayDayOfWeek || (hourlyIndex < todayEstimationFirstHour || hourlyIndex > todayEstimationLastHour)) { weekDayEstimation[weekDayIndex - 1] += value.floatValue(); } } else { nrOfMissingAvgValues++; } hourlyIndex++; if (hourlyIndex % 24 == 0) { weekDayIndex++; hourlyIndex = 0; } } if (nrOfMissingAvgValues * DateUtils.MILLISEC_IN_ONE_HOUR >= DateUtils.MILLISEC_IN_ONE_DAY) { log.info("getFloatValueMonthlyForecast: too many average missing values - " + nrOfMissingAvgValues); return null; } else if (nrOfMissingAvgValues > 0) { log.info("getFloatValueMonthlyForecast: found some missing values - " + nrOfMissingAvgValues); } // The following update to lastTime value is necessary to manage legal // time switch c.setTimeInMillis(lastTime); c.set(Calendar.HOUR_OF_DAY, 12); lastTime = c.getTimeInMillis(); while (c.get(Calendar.MONTH) == todayMonth) { currentMonthEstimation += weekDayEstimation[c.get(Calendar.DAY_OF_WEEK) - 1]; lastTime += DateUtils.MILLISEC_IN_ONE_DAY; c.setTimeInMillis(lastTime); } return currentMonthEstimation * ((float) (weekDayItemList.size() + nrOfMissingAvgValues)) / weekDayItemList.size(); }
From source file:de.micromata.genome.util.types.DateUtils.java
/** * Ensure workday.// www . j a v a 2 s . c o m * * @param cal the cal */ protected static void ensureWorkday(Calendar cal) { int dow = cal.get(Calendar.DAY_OF_WEEK); while (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) { cal.add(Calendar.DAY_OF_YEAR, 1); dow = cal.get(Calendar.DAY_OF_WEEK); } }
From source file:com.xandy.calendar.month.MonthByWeekFragment.java
@Override protected void setUpHeader() { if (mIsMiniMonth) { super.setUpHeader(); return;//from www. ja va 2 s . c o m } mDayLabels = new String[7]; for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) { mDayLabels[i - Calendar.SUNDAY] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_MEDIUM) .toUpperCase(); } }
From source file:de.austinpadernale.holidays.Holiday.java
public Calendar shift(Calendar cal, String country, String region) { int dow = cal.get(Calendar.DAY_OF_WEEK); if (dow != Calendar.SATURDAY && dow != Calendar.SUNDAY) { return cal; }//www.jav a2s.c o m HolidayShift hs = getShift(country, region); if (hs == null || hs.getShiftType() == ShiftType.None) { return cal; } int step; switch (hs.getShiftType()) { case Back: step = -1; break; case Forth: step = 1; break; case BackAndForth: step = dow == Calendar.SATURDAY ? -1 : 1; break; default: return cal; } while (dow == Calendar.SATURDAY || dow == Calendar.SUNDAY) { cal.add(Calendar.DATE, step); dow = cal.get(Calendar.DAY_OF_WEEK); } return cal; }