Example usage for java.util Calendar THURSDAY

List of usage examples for java.util Calendar THURSDAY

Introduction

In this page you can find the example usage for java.util Calendar THURSDAY.

Prototype

int THURSDAY

To view the source code for java.util Calendar THURSDAY.

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Thursday.

Usage

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  .java2 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:cn.mypandora.util.MyDateUtils.java

/**
 * ./*from  w w  w  .j a v a  2 s .  c  o  m*/
 *
 * @param c
 * @return
 */
public static String getWeekDay(Calendar c) {
    if (c == null) {
        return "";
    }
    switch (c.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        return "";
    case Calendar.TUESDAY:
        return "";
    case Calendar.WEDNESDAY:
        return "";
    case Calendar.THURSDAY:
        return "";
    case Calendar.FRIDAY:
        return "";
    case Calendar.SATURDAY:
        return "";
    default:
        return "";
    }
}

From source file:com.ubundude.timesheet.ReportFragment.java

/**
 * Method to get the Calendar day of week Integer
 * /*from   www.  ja  v a 2s.c  om*/
 * @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:com.autentia.intra.bean.activity.ObjectiveBean.java

/**
 * Move a date to one of its surrounding fridays.
 *
 * @param d        the reference date//from w w w. j a  v  a 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.kuali.coeus.common.committee.impl.bo.CommitteeScheduleBase.java

/**
 * This UI support method to find day Of week from BO's persistent field scheduledDate.
 * @return/*from   ww w  .  j  a  va  2  s. c o  m*/
 */
public String getDayOfWeek() {
    Calendar cl = new GregorianCalendar();
    cl.setTime(scheduledDate);
    DayOfWeek dayOfWeek = null;
    switch (cl.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.SUNDAY:
        dayOfWeek = DayOfWeek.Sunday;
        break;
    case Calendar.MONDAY:
        dayOfWeek = DayOfWeek.Monday;
        break;
    case Calendar.TUESDAY:
        dayOfWeek = DayOfWeek.Tuesday;
        break;
    case Calendar.WEDNESDAY:
        dayOfWeek = DayOfWeek.Wednesday;
        break;
    case Calendar.THURSDAY:
        dayOfWeek = DayOfWeek.Thursday;
        break;
    case Calendar.FRIDAY:
        dayOfWeek = DayOfWeek.Friday;
        break;
    case Calendar.SATURDAY:
        dayOfWeek = DayOfWeek.Saturday;
        break;
    }
    return dayOfWeek.name().toUpperCase();
}

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  ww w .  j a  v a  2 s.c  o  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:com.projity.pm.calendar.WorkingCalendar.java

static WorkingCalendar getNightShiftInstance() {
    if (nightShiftInstance != null)
        return nightShiftInstance;
    nightShiftInstance = WorkingCalendar.getStandardBasedInstance();
    WorkDay nonWorking = null;//from   w w  w. ja v  a2s .  c o m
    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.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);/*from w ww  .  ja  v  a2s  .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.activequant.util.charting.IntradayMarketTimeline.java

private long getActiveTimePerDay(int day) {
    long closedTime = 0;

    if (day == Calendar.SUNDAY) {
        closedTime = this.sundayActive;
    } else if (day == Calendar.MONDAY) {
        closedTime = this.mondayActive;
    } else if (day == Calendar.TUESDAY) {
        closedTime = this.tuesdayActive;
    } else if (day == Calendar.WEDNESDAY) {
        closedTime = this.wednesdayActive;
    } else if (day == Calendar.THURSDAY) {
        closedTime = this.thursdayActive;
    } else if (day == Calendar.FRIDAY) {
        closedTime = this.fridayActive;
    } else if (day == Calendar.SATURDAY) {
        closedTime = this.saturdayActive;
    }/*from w ww. ja  va  2s.  c  o m*/

    return closedTime;
}

From source file:com.castis.xylophone.adsmadapter.common.util.InventorySizePolicyGenerator.java

private List<String> getTimeExternalID(InventoryBoxDayCode dayCode, List<String> timeValueList) {
    List<String> externalIDList = new ArrayList<String>();
    switch (dayCode) {
    case WEEKDAY:
        for (String timeValue : timeValueList) {
            timeValue = timeValue.length() < 2 ? "0" + timeValue : timeValue;
            externalIDList.add("W.*.W" + Calendar.MONDAY + ".H" + timeValue);
            externalIDList.add("W.*.W" + Calendar.TUESDAY + ".H" + timeValue);
            externalIDList.add("W.*.W" + Calendar.WEDNESDAY + ".H" + timeValue);
            externalIDList.add("W.*.W" + Calendar.THURSDAY + ".H" + timeValue);
            externalIDList.add("W.*.W" + Calendar.FRIDAY + ".H" + timeValue);
        }//  ww w . j  a v a 2 s . c om
        break;
    case WEEKEND:
        for (String timeValue : timeValueList) {
            timeValue = timeValue.length() < 2 ? "0" + timeValue : timeValue;
            externalIDList.add("W.*.W" + Calendar.SUNDAY + ".H" + timeValue);
            externalIDList.add("W.*.W" + Calendar.SATURDAY + ".H" + timeValue);
        }
        break;
    }

    return externalIDList;
}