Java Code Examples for java.util.Calendar#SATURDAY

The following examples show how to use java.util.Calendar#SATURDAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTagsListenersTest.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
String getDayOfWeek(int a){
    switch (1 + (a - 1) % 7){
        case Calendar.SUNDAY:
            return "sunday";
        case Calendar.MONDAY:
            return "monday";
        case Calendar.TUESDAY:
            return "tuesday";
        case Calendar.WEDNESDAY:
            return "wednesday";
        case Calendar.THURSDAY:
            return "thursday";
        case Calendar.FRIDAY:
            return "friday";
        case Calendar.SATURDAY:
            return "saturday";
        default: return null;
    }
}
 
Example 2
Source File: OHDateUtils.java    From oneHookLibraryAndroid with Apache License 2.0 6 votes vote down vote up
public static int getTodayWeekdayNormalized() {
    final Calendar calendar = Calendar.getInstance();
    final int weekday = calendar.get(Calendar.DAY_OF_WEEK);
    switch (weekday) {
        case Calendar.SUNDAY:
            return 0;
        case Calendar.MONDAY:
            return 1;
        case Calendar.TUESDAY:
            return 2;
        case Calendar.WEDNESDAY:
            return 3;
        case Calendar.THURSDAY:
            return 4;
        case Calendar.FRIDAY:
            return 5;
        case Calendar.SATURDAY:
            return 6;
        default:
            return 0;
    }
}
 
Example 3
Source File: ManualRecord.java    From sagetv with Apache License 2.0 6 votes vote down vote up
private static boolean doesMaskHaveDay(int mask, int day)
{
  if (day == Calendar.SUNDAY)
    return (mask & RECUR_SUN_MASK) != 0;
  else if (day == Calendar.MONDAY)
    return (mask & RECUR_MON_MASK) != 0;
  else if (day == Calendar.TUESDAY)
    return (mask & RECUR_TUE_MASK) != 0;
  else if (day == Calendar.WEDNESDAY)
    return (mask & RECUR_WED_MASK) != 0;
  else if (day == Calendar.THURSDAY)
    return (mask & RECUR_THU_MASK) != 0;
  else if (day == Calendar.FRIDAY)
    return (mask & RECUR_FRI_MASK) != 0;
  else if (day == Calendar.SATURDAY)
    return (mask & RECUR_SAT_MASK) != 0;
  else return false;
}
 
Example 4
Source File: TimerHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
private static ArrayList<WeekdayTimer.Day> getExecutionDays(Long timerId) throws Exception {
    ArrayList<WeekdayTimer.Day> days = new ArrayList<>();

    String[] columns = {TimerWeekdayTable.COLUMN_EXECUTION_DAY};
    Cursor cursor = DatabaseHandler.database.query(TimerWeekdayTable.TABLE_NAME, columns,
            TimerWeekdayTable.COLUMN_TIMER_ID + "=" + timerId, null, null, null, null);

    cursor.moveToFirst();

    while (!cursor.isAfterLast()) {
        switch (cursor.getInt(0)) {
            case Calendar.MONDAY:
                days.add(WeekdayTimer.Day.MONDAY);
                break;
            case Calendar.TUESDAY:
                days.add(WeekdayTimer.Day.TUESDAY);
                break;
            case Calendar.WEDNESDAY:
                days.add(WeekdayTimer.Day.WEDNESDAY);
                break;
            case Calendar.THURSDAY:
                days.add(WeekdayTimer.Day.THURSDAY);
                break;
            case Calendar.FRIDAY:
                days.add(WeekdayTimer.Day.FRIDAY);
                break;
            case Calendar.SATURDAY:
                days.add(WeekdayTimer.Day.SATURDAY);
                break;
            case Calendar.SUNDAY:
                days.add(WeekdayTimer.Day.SUNDAY);
                break;
        }
        cursor.moveToNext();
    }

    cursor.close();
    return days;
}
 
Example 5
Source File: WeekWeatherAdapter.java    From privacy-friendly-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBindViewHolder(WeekForecastViewHolder holder, int position) {
    Forecast f = forecastList.get(position);

    setIcon(f.getWeatherID(), holder.weather);
    holder.humidity.setText(StringFormatUtils.formatInt(f.getHumidity(), "%"));

    Calendar c = new GregorianCalendar();
    c.setTime(f.getLocalForecastTime(context));
    int day = c.get(Calendar.DAY_OF_WEEK);

    switch(day) {
        case Calendar.MONDAY:
            day = R.string.abbreviation_monday;
            break;
        case Calendar.TUESDAY:
            day = R.string.abbreviation_tuesday;
            break;
        case Calendar.WEDNESDAY:
            day = R.string.abbreviation_wednesday;
            break;
        case Calendar.THURSDAY:
            day = R.string.abbreviation_thursday;
            break;
        case Calendar.FRIDAY:
            day = R.string.abbreviation_friday;
            break;
        case Calendar.SATURDAY:
            day = R.string.abbreviation_saturday;
            break;
        case Calendar.SUNDAY:
            day = R.string.abbreviation_sunday;
            break;
        default:
            day = R.string.abbreviation_monday;
    }
    holder.day.setText(day);
    holder.temperature.setText(StringFormatUtils.formatTemperature(context, f.getTemperature()));
}
 
Example 6
Source File: CalendarUtils.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
public static int getLastDayOfWeek(Calendar cal) {
    int dow = cal.getFirstDayOfWeek() - 1;

    if (dow == 0) {
        dow = Calendar.SATURDAY;
    }

    return dow;
}
 
Example 7
Source File: DateOperation.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 判断是否周末
 * @param recordDate
 * @return
 */
public boolean isWeekend(Date recordDate) {
	Calendar cal = Calendar.getInstance();
    cal.setTime( recordDate );
    if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
       return true;
    }
	return false;
}
 
Example 8
Source File: DateOperation.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 判断是否周末
 * @param recordDate
 * @return
 */
public boolean isWeekend(Date date) {
	Calendar cal = Calendar.getInstance();
    cal.setTime( date );
    if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
       return true;
    }
	return false;
}
 
Example 9
Source File: DateOperation.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 判断是否周末
 * @param recordDate
 * @return
 */
public boolean isWeekend(Date date) {
	Calendar cal = Calendar.getInstance();
    cal.setTime( date );
    if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
       return true;
    }
	return false;
}
 
Example 10
Source File: CreateMeetings.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * It will give the number of recurrence for certail time frame
 * 
 * @param recurType
 *            a String object.
 * @param effectiveDate
 *            a Date object which defines the starting date.
 * @param untilDate
 *            a Date object which defines the possible ending date.
 * @return
 */
public static int getNumOfRecurrence(String recurType, Date effectiveDate, Date untilDate) {
	int numOfRecurs = 0;
	long firstMeetingEndTime = effectiveDate.getTime();
	int availDaysForRepeat = 0;
	Calendar untilCal = Calendar.getInstance();
	untilCal.setTime(untilDate);
	untilCal.set(Calendar.HOUR_OF_DAY, 23);
	untilCal.set(Calendar.MINUTE, 59);
	untilCal.set(Calendar.SECOND, 59);
	availDaysForRepeat = (int) ((untilCal.getTimeInMillis() - firstMeetingEndTime) / DAY_IN_MILLISEC);

	if (DAILY.equals(recurType) || WEEKDAYS.equals(recurType)) {
		numOfRecurs = availDaysForRepeat / perDay;
	} else if (WEEKLY.equals(recurType)) {
		numOfRecurs = availDaysForRepeat / perWeek;
	} else if (BIWEEKLY.equals(recurType)) {
		numOfRecurs = availDaysForRepeat / perBiweek;
	}
	
	/*Case: weekdays*/
	if(WEEKDAYS.equals(recurType) && numOfRecurs < 2){
		Calendar startCal = Calendar.getInstance();
		startCal.setTime(effectiveDate);
		int dayname = startCal.get(Calendar.DAY_OF_WEEK);
		if(dayname == Calendar.SATURDAY)
			numOfRecurs =0;//no weekdays are there
	}
	return numOfRecurs;
}
 
Example 11
Source File: CreateMeetings.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void removeWeekendDays(){
	if(this.signupMeetings !=null && !this.signupMeetings.isEmpty()){
		for (int i = signupMeetings.size()-1; i >= 0; i--) {		
			SignupMeeting sm = (SignupMeeting) signupMeetings.get(i);				
			Calendar startCal = Calendar.getInstance();
			startCal.setTime(sm.getStartTime());
			int dayOfweek = startCal.get(Calendar.DAY_OF_WEEK);
			if(dayOfweek == Calendar.SATURDAY || dayOfweek == Calendar.SUNDAY)
				signupMeetings.remove(i);
		}
	}
}
 
Example 12
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
* Get the day of the week
  *
  * @param useLocale return locale specific day of week
* e.g. <code>SUNDAY = 1, MONDAY = 2, ...</code> in the U.S.,
*		 <code>MONDAY = 1, TUESDAY = 2, ...</code> in France. 
* @return the day of the week.
*/
public int getDay_Of_Week( boolean useLocale ) 
{
	int dayofweek = m_calendar.get(Calendar.DAY_OF_WEEK);
	if ( useLocale )
	{
		if ( dayofweek >= m_calendar.getFirstDayOfWeek() )
			dayofweek = dayofweek - (m_calendar.getFirstDayOfWeek()-Calendar.SUNDAY);
		else
			dayofweek = dayofweek + Calendar.SATURDAY - (m_calendar.getFirstDayOfWeek()-Calendar.SUNDAY);
	}
	return dayofweek;

}
 
Example 13
Source File: DPCNCalendar.java    From LunarCalendar with Apache License 2.0 5 votes vote down vote up
/**
 * 生成公历某年某月的周末日期集合
 *
 * @param year  某年
 * @param month 某月
 * @return 某年某月的周末日期集合
 */
static Set<Integer> buildMonthWeekend(int year, int month) {
    Set<Integer> set = new HashSet<>();
    calendar.clear();
    //noinspection MagicConstant
    calendar.set(year, month - 1, 1);
    do {
        int day = calendar.get(Calendar.DAY_OF_WEEK);
        if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {
            set.add(calendar.get(Calendar.DAY_OF_MONTH));
        }
        calendar.add(Calendar.DAY_OF_YEAR, 1);
    } while (calendar.get(Calendar.MONTH) == month - 1);
    return set;
}
 
Example 14
Source File: Recurring.java    From material with Apache License 2.0 4 votes vote down vote up
@Override
public String toString(){
    StringBuilder sb = new StringBuilder();
    sb.append(Recurring.class.getSimpleName())
            .append("[mode=");
    switch (mRepeatMode){
        case REPEAT_NONE:
            sb.append("none");
            break;
        case REPEAT_DAILY:
            sb.append("daily")
                    .append("; period=")
                    .append(mPeriod);
            break;
        case REPEAT_WEEKLY:
            sb.append("weekly")
                    .append("; period=")
                    .append(mPeriod)
                    .append("; setting=");

            for(int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++){
                if(isEnabledWeekday(i))
                    sb.append(i);
            }
            break;
        case REPEAT_MONTHLY:
            sb.append("monthly")
                    .append("; period=")
                    .append(mPeriod)
                    .append("; setting=")
                    .append(getMonthRepeatType() == MONTH_SAME_DAY ? "same_day" : "same_weekday");
            break;
        case REPEAT_YEARLY:
            sb.append("yearly")
                    .append("; period=")
                    .append(mPeriod);
            break;
    }

    if(mRepeatMode != REPEAT_NONE){
        switch (mEndMode){
            case END_FOREVER:
                sb.append("; end=forever");
                break;
            case END_UNTIL_DATE:
                sb.append("; end=until ");
                Calendar cal = Calendar.getInstance();
                cal.setTimeInMillis(mEndSetting);
                sb.append(cal.get(Calendar.DAY_OF_MONTH))
                        .append('/')
                        .append(cal.get(Calendar.MONTH) + 1)
                        .append('/')
                        .append(cal.get(Calendar.YEAR));
                break;
            case END_FOR_EVENT:
                sb.append("; end=for ")
                        .append(mEndSetting)
                        .append(" events");
                break;
        }
    }

    sb.append(']');
    return sb.toString();
}
 
Example 15
Source File: Activity1A0001Validation.java    From symphonyx with Apache License 2.0 4 votes vote down vote up
@Override
public void doAdvice(final HTTPRequestContext context, final Map<String, Object> args) throws RequestProcessAdviceException {
    if (Symphonys.getBoolean("activity1A0001Closed")) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activityClosedLabel")));
    }

    final Calendar calendar = Calendar.getInstance();

    final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activity1A0001CloseLabel")));
    }

    final int hour = calendar.get(Calendar.HOUR_OF_DAY);
    final int minute = calendar.get(Calendar.MINUTE);
    if (hour > 14 || (hour == 14 && minute > 55)) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activityEndLabel")));
    }

    final HttpServletRequest request = context.getRequest();

    JSONObject requestJSONObject;
    try {
        requestJSONObject = Requests.parseRequestJSONObject(request, context.getResponse());
        request.setAttribute(Keys.REQUEST, requestJSONObject);
    } catch (final Exception e) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, e.getMessage()));
    }

    final int amount = requestJSONObject.optInt(Common.AMOUNT);
    if (200 != amount && 300 != amount && 400 != amount && 500 != amount) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activityBetFailLabel")));
    }

    final int smallOrLarge = requestJSONObject.optInt(Common.SMALL_OR_LARGE);
    if (0 != smallOrLarge && 1 != smallOrLarge) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activityBetFailLabel")));
    }

    final JSONObject currentUser = (JSONObject) request.getAttribute(User.USER);
    if (null == currentUser) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("reloginLabel")));
    }

    if (UserExt.USER_STATUS_C_VALID != currentUser.optInt(UserExt.USER_STATUS)) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("userStatusInvalidLabel")));
    }

    if (activityQueryService.is1A0001Today(currentUser.optString(Keys.OBJECT_ID))) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("activityParticipatedLabel")));
    }

    final int balance = currentUser.optInt(UserExt.USER_POINT);
    if (balance - amount < 0) {
        throw new RequestProcessAdviceException(new JSONObject().put(Keys.MSG, langPropsService.get("insufficientBalanceLabel")));
    }
}
 
Example 16
Source File: CreateMeetings.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * It will generate a list of SignupMeeting object and wrap up with
 * corresponding contents for saving to DB
 * 
 */
private void createRecurMeetings(Calendar calendar, long numOfRecurs, int intervalOfRecurs) {
	int eday, sday, sdday, edday;

	
	
	if (!ONCE_ONLY.equals(signupMeeting.getRepeatType()) && numOfRecurs < 1) {
		Utilities.addErrorMessage(Utilities.rb.getString("event.repeatbeforestart"));
		return;
	}
	
	if(!ONCE_ONLY.equals(signupMeeting.getRepeatType()) && "0".equals(this.recurLengthDataType))
		numOfRecurs = numOfRecurs - 1;

	for (int i = 0; i <= numOfRecurs; i++) {
		SignupMeeting beta = new SignupMeeting();
		beta = prepareDeepCopy(this.signupMeeting, i * intervalOfRecurs);
		calendar.setTime(this.signupMeeting.getStartTime());
		sday = calendar.get(Calendar.DATE) + i * intervalOfRecurs;
		calendar.set(Calendar.DATE, sday);
		beta.setStartTime(calendar.getTime());
		
		/*add lost event due to weekend*/
		int makeupOnceDueToWeekend=0;
		if(WEEKDAYS.equals(signupMeeting.getRepeatType()) && "0".equals(this.recurLengthDataType)){
			//only makeup for user, who has select repeat-numbers option
			int dayOfweek = calendar.get(Calendar.DAY_OF_WEEK);
			if(dayOfweek == Calendar.SATURDAY || dayOfweek == Calendar.SUNDAY)
				makeupOnceDueToWeekend = 1;
			
		}
		
		calendar.setTime(this.signupMeeting.getEndTime());
		eday = calendar.get(Calendar.DATE) + i * intervalOfRecurs;
		calendar.set(Calendar.DATE, eday);
		beta.setEndTime(calendar.getTime());

		calendar.setTime(this.signupMeeting.getSignupBegins());
		sdday = calendar.get(Calendar.DATE) + i * intervalOfRecurs;
		calendar.set(Calendar.DATE, sdday);
		if(START_NOW.equals(this.signupBeginType)){
			beta.setSignupBegins(Utilities.subTractTimeToDate(new Date(), 6,
					START_NOW));
		}
		else{
			beta.setSignupBegins(calendar.getTime());
		}
		calendar.setTime(this.signupMeeting.getSignupDeadline());
		edday = calendar.get(Calendar.DATE) + i * intervalOfRecurs;
		calendar.set(Calendar.DATE, edday);
		beta.setSignupDeadline(calendar.getTime());
		
		/*set attachments*/
		beta.setSignupAttachments(copyAttachments(this.signupMeeting, numOfRecurs, i));			
		
		/*should publish calendar in a separate blocks at Scheduler Tool? */
		beta.setInMultipleCalendarBlocks(this.signupMeeting.isInMultipleCalendarBlocks());
		
		if (this.assignParticatpantsToFirstOne) {
			/* Turn off after first one copy */
			this.assignParticitpantsToAllEvents = false;
			this.assignParticatpantsToFirstOne = false;
		}

		this.signupMeetings.add(beta);
		/*add lost events due to weekend when user want 5 occurrences for example*/
		numOfRecurs += makeupOnceDueToWeekend;
	}
}
 
Example 17
Source File: DepartmentalInstructor.java    From unitime with Apache License 2.0 4 votes vote down vote up
public Map<Date, Date> getUnavailablePatternDateStringHashMaps() {
	Calendar startDate = Calendar.getInstance(Locale.US);
	startDate.setTime(getUnavailableStartDate());
	Calendar endDate = Calendar.getInstance(Locale.US);
	endDate.setTime(getUnavailableEndDate());

	int startMonth = startDate.get(Calendar.MONTH);
	int endMonth = endDate.get(Calendar.MONTH);
	int startYear = startDate.get(Calendar.YEAR);
	int endYear = endDate.get(Calendar.YEAR);
	if (endYear > startYear){
		endMonth += (12 * (endYear - startYear));
	}
	
	Map<Date, Date> mapStartToEndDate = new HashMap<Date, Date>();
	Date first = null, previous = null;
	char[] ptrn = getUnavailableDays().toCharArray();
	int charPosition = 0;
	int dayOfWeek = startDate.get(Calendar.DAY_OF_WEEK);
	Calendar cal = Calendar.getInstance(Locale.US);

	for (int m=startMonth;m<=endMonth;m++) {
		int daysOfMonth = DateUtils.getNrDaysOfMonth(m, startYear);
		int d;
		if (m == startMonth){
			d = startDate.get(Calendar.DAY_OF_MONTH);
		} else {
			d = 1;
		}
		for (;d<=daysOfMonth && charPosition < ptrn.length ;d++) {
			if (ptrn[charPosition] == '1' || (first != null && dayOfWeek == Calendar.SUNDAY && charPosition + 1 < ptrn.length && ptrn[1 + charPosition] == '1')) {
				if (first==null){
					//first = ((m<0?12+m:m%12)+1)+"/"+d+"/"+((m>=12)?startYear+1:startYear);
					cal.setTime(getUnavailableStartDate());
					cal.add(Calendar.DAY_OF_YEAR, charPosition);
					first = cal.getTime();
				}
			} else {
				if (first!=null) {
					mapStartToEndDate.put(first, previous);
					first=null;
				}
			}
			//previous = ((m<0?12+m:m%12)+1)+"/"+d+"/"+((m>=12)?startYear+1:startYear);
			cal.setTime(getUnavailableStartDate());
			cal.add(Calendar.DAY_OF_YEAR, charPosition);
			previous = cal.getTime();
			
			charPosition++;
			dayOfWeek++;
			if (dayOfWeek > Calendar.SATURDAY){
				dayOfWeek = Calendar.SUNDAY;
			}
		}
	}
	if (first!=null) {
		mapStartToEndDate.put(first, previous);
		first=null;
	}
	return(mapStartToEndDate);
}
 
Example 18
Source File: MockStockPriceEntityManagerFactory.java    From training with MIT License 4 votes vote down vote up
protected <T> T findWithHistory(DataHolder dh, Object o) {
    StockPricePK pk = (StockPricePK) o;
    StockPriceEagerLazyImpl sp = new StockPriceEagerLazyImpl(pk);
    dh.calendar.setTime(pk.getDate());
    if (dh.calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ||
        dh.calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
        return null;
    }
    
    if (dh.symbol == null || !dh.symbol.equals(pk.getSymbol())) {
        dh.symbol = pk.getSymbol();
        sp.setOpeningPrice(
                new BigDecimal(
                     dh.random.nextDouble() * 100).
                         setScale(2, BigDecimal.ROUND_HALF_UP));
    }
    else {
        sp.setOpeningPrice(dh.lastClose);
    }
    double pctChange = dh.random.nextDouble() * dh.random.nextDouble();
    pctChange *= (dh.random.nextDouble() < 0.6) ? 0.1 : -0.1;
    pctChange += 1.0;
    sp.setClosingPrice(sp.getOpeningPrice().
        multiply(new BigDecimal(pctChange).
        setScale(2, BigDecimal.ROUND_HALF_UP)).
        setScale(2, BigDecimal.ROUND_HALF_UP));
    if (sp.getClosingPrice().compareTo(BigDecimal.ZERO) < 0) {
        sp.setClosingPrice(BigDecimal.ZERO);
    }
    
    pctChange = dh.random.nextDouble() * dh.random.nextDouble() * 0.1;
    sp.setHigh(sp.getOpeningPrice().
        multiply(new BigDecimal(pctChange * dh.random.nextDouble())).
        setScale(2, BigDecimal.ROUND_HALF_UP));
    if (sp.getHigh().compareTo(sp.getClosingPrice()) < 0) {
        sp.setHigh(sp.getClosingPrice());
    }
    if (sp.getHigh().compareTo(sp.getOpeningPrice()) < 0) {
        sp.setHigh(sp.getOpeningPrice());
    }
    
    pctChange = dh.random.nextDouble() * dh.random.nextDouble() * 0.1;
    BigDecimal dailyLoss = sp.getClosingPrice().
        multiply(new BigDecimal(pctChange).
        setScale(2, BigDecimal.ROUND_HALF_UP)).
        setScale(2, BigDecimal.ROUND_HALF_UP);
    sp.setLow(sp.getOpeningPrice().subtract(dailyLoss));
    if (sp.getLow().compareTo(sp.getClosingPrice()) > 0) {
        sp.setLow(sp.getClosingPrice());
    }
    dh.lastClose = sp.getClosingPrice();

    return (T) sp;
}
 
Example 19
Source File: Utils.java    From android-utils with MIT License 4 votes vote down vote up
/**
 * Gets the name of the day of the week.
 *
 * @param date ISO format date
 * @return The name of the day of the week
 **/
public static String getDayOfWeek(String date) {
    // TODO: move to DateUtils
    Date dateDT = DateUtils.parseDate(date);

    if (dateDT == null) {
        return null;
    }

    // Get current date
    Calendar c = Calendar.getInstance();
    // it is very important to
    // set the date of
    // the calendar.
    c.setTime(dateDT);
    int day = c.get(Calendar.DAY_OF_WEEK);

    String dayStr = null;

    switch (day) {

        case Calendar.SUNDAY:
            dayStr = "Sunday";
            break;

        case Calendar.MONDAY:
            dayStr = "Monday";
            break;

        case Calendar.TUESDAY:
            dayStr = "Tuesday";
            break;

        case Calendar.WEDNESDAY:
            dayStr = "Wednesday";
            break;

        case Calendar.THURSDAY:
            dayStr = "Thursday";
            break;

        case Calendar.FRIDAY:
            dayStr = "Friday";
            break;

        case Calendar.SATURDAY:
            dayStr = "Saturday";
            break;
    }

    return dayStr;
}
 
Example 20
Source File: InfoFragment.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public void updateTime() {
    Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH) + 1;
    int date = c.get(Calendar.DATE);
    int hours = c.get(Calendar.HOUR_OF_DAY);
    int minutes = c.get(Calendar.MINUTE);
    int week = c.get(Calendar.DAY_OF_WEEK);

    String hour;
    String minute;
    String weekDay;

    if (hours < 10) {
        hour = "0" + hours;
    } else {
        hour = "" + hours;
    }
    if (minutes < 10) {
        minute = "0" + minutes;
    } else {
        minute = "" + minutes;
    }

    String[] weeks = getResources().getStringArray(R.array.info_week);

    switch (week) {
        case Calendar.MONDAY:
            weekDay = weeks[0];
            break;
        case Calendar.TUESDAY:
            weekDay = weeks[1];
            break;
        case Calendar.WEDNESDAY:
            weekDay = weeks[2];
            break;
        case Calendar.THURSDAY:
            weekDay = weeks[3];
            break;
        case Calendar.FRIDAY:
            weekDay = weeks[4];
            break;
        case Calendar.SATURDAY:
            weekDay = weeks[5];
            break;
        case Calendar.SUNDAY:
            weekDay = weeks[6];
            break;
        default:
            weekDay = "";
            break;
    }

    mTimeText.setText(hour + ":" + minute);
    if (mShowYear) {
        mDateText.setText(year + getResources().getString(R.string.info_year)
                + month + getResources().getString(R.string.info_month)
                + date + getResources().getString(R.string.info_day));
    } else {
        mDateText.setText(month + getResources().getString(R.string.info_month)
                + date + getResources().getString(R.string.info_day));
    }
    mWeekText.setText(getResources().getString(R.string.info_week) + weekDay);
    mHandler.removeMessages(REFRESH_TIME);
    mHandler.sendEmptyMessageDelayed(REFRESH_TIME, 1000);
}