Example usage for java.util Calendar MONDAY

List of usage examples for java.util Calendar MONDAY

Introduction

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

Prototype

int MONDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Monday.

Usage

From source file:org.structr.common.RecurringDateHelper.java

private static String getShortWeekday(final int wd) {

    switch (wd) {

    case Calendar.MONDAY:
        return ShortWeekday.Mo.name();

    case Calendar.TUESDAY:
        return ShortWeekday.Di.name();

    case Calendar.WEDNESDAY:
        return ShortWeekday.Mi.name();

    case Calendar.THURSDAY:
        return ShortWeekday.Do.name();

    case Calendar.FRIDAY:
        return ShortWeekday.Fr.name();

    case Calendar.SATURDAY:
        return ShortWeekday.Sa.name();

    case Calendar.SUNDAY:
        return ShortWeekday.So.name();

    }//from  w ww . j av a  2  s . co m

    return "";

}

From source file:org.mot.common.util.DateBuilder.java

/**
 * @param weekNumber - which week to look for
 * @param pattern - define a pattern in which the result string will be formatted
 * @return String value representing the first monday of the week
 *//*from   w  w w  .  ja  v a 2  s  .  c o m*/
public String getDateForWeekOfYear(int weekNumber, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.WEEK_OF_YEAR, weekNumber);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    //System.out.println(sdf.format(cal.getTime())); 
    return sdf.format(cal.getTime());
}

From source file:de.codesourcery.eve.skills.ui.utils.CalendarWidget.java

private Calendar calcAlignedStartDate(Calendar cal) {
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
    }/* ww w  . jav a2s . c o m*/
    return cal;
}

From source file:com.haulmont.timesheets.service.StatisticServiceBean.java

@Override
public Map<Integer, Map<String, Object>> getStatisticsByProjects(Date start, Date end) {
    LoadContext<TimeEntry> loadContext = new LoadContext<>(TimeEntry.class)
            .setQuery(new LoadContext.Query(
                    "select t from ts$TimeEntry t where t.date >= :start and t.date <= :end order by t.date")
                            .setParameter("start", start).setParameter("end", end))
            .setView(new View(TimeEntry.class)
                    .addProperty("task",
                            new View(Task.class).addProperty("name").addProperty("project",
                                    viewRepository.getView(Project.class, View.MINIMAL)))
                    .addProperty("timeInMinutes").addProperty("date"));
    List<TimeEntry> timeEntries = dataManager.loadList(loadContext);

    Map<WeekAndProject, BigDecimal> statistic = new LinkedHashMap<>();
    Calendar calendar = Calendar.getInstance();
    for (TimeEntry timeEntry : timeEntries) {
        calendar.setTime(timeEntry.getDate());
        int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
        WeekAndProject key = new WeekAndProject(weekOfYear, timeEntry.getTask().getProject());

        BigDecimal sum = statistic.get(key);
        if (sum == null) {
            sum = BigDecimal.ZERO;
        }/*from   ww  w .j  a va2 s .  c o  m*/

        sum = sum.add(HoursAndMinutes.fromTimeEntry(timeEntry).toBigDecimal());
        statistic.put(key, sum);
    }

    Map<Integer, Map<String, Object>> result = new LinkedHashMap<>();
    for (Map.Entry<WeekAndProject, BigDecimal> entry : statistic.entrySet()) {
        Integer week = entry.getKey().week;
        Map<String, Object> projectsByWeek = result.get(week);
        if (projectsByWeek == null) {
            projectsByWeek = new HashMap<>();
            calendar.set(Calendar.WEEK_OF_YEAR, week);
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            projectsByWeek.put("week", DateTimeUtils.getDateFormat().format(calendar.getTime()));

        }
        projectsByWeek.put(entry.getKey().project.getName(), entry.getValue());
        result.put(week, projectsByWeek);
    }

    return result;
}

From source file:org.kuali.kfs.module.endow.document.service.impl.FrequencyDatesServiceImpl.java

/**
 * Method to calculate the next processing week date based on the frequency type
 * adds the appropriate number of days to the current date
 * @param dayOfWeek//from  w w w  . j  av a  2s  .c  om
 * @return next processing date
 */
protected Calendar calculateNextWeeklyDate(String dayOfWeekFromFrequencyCode, Date currentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);

    int daysToAdd = 0;
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); // today's day of the week
    int maximumDaysInWeek = calendar.getActualMaximum(Calendar.DAY_OF_WEEK);

    if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.MONDAY)) {
        if (dayOfWeek < Calendar.MONDAY)
            daysToAdd = Calendar.MONDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.MONDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.TUESDAY)) {
        if (dayOfWeek < Calendar.TUESDAY)
            daysToAdd = Calendar.TUESDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.TUESDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.WEDNESDAY)) {
        if (dayOfWeek < Calendar.WEDNESDAY)
            daysToAdd = Calendar.WEDNESDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.WEDNESDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.THURSDAY)) {
        if (dayOfWeek < Calendar.THURSDAY)
            daysToAdd = Calendar.THURSDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.THURSDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.FRIDAY)) {
        if (dayOfWeek < Calendar.FRIDAY)
            daysToAdd = Calendar.FRIDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.FRIDAY;
    }

    calendar.add(Calendar.DAY_OF_MONTH, daysToAdd);

    return calendar;
}

From source file:org.jasig.schedassist.model.CommonDateOperations.java

/**
 * Helper method to calculate the first week's end date.
 * //  w ww.ja  v a2s.  com
 * @param date
 * @return the number of days from date until the following Sunday
 */
public static int numberOfDaysUntilSunday(final Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    int result = 7;
    switch (dayOfWeek) {
    case Calendar.SUNDAY:
        result = 7;
        break;
    case Calendar.MONDAY:
        result = 6;
        break;
    case Calendar.TUESDAY:
        result = 5;
        break;
    case Calendar.WEDNESDAY:
        result = 4;
        break;
    case Calendar.THURSDAY:
        result = 3;
        break;
    case Calendar.FRIDAY:
        result = 2;
        break;
    case Calendar.SATURDAY:
        result = 1;
        break;
    }
    return result;
}

From source file:com.binary_machinery.avalonschedule.view.ScheduleActivity.java

private static int findTodayCourse(List<ScheduleRecord> records) {
    if (records.isEmpty()) {
        return 0;
    }/*from ww  w .j a  va2 s . c  om*/
    Calendar minDateCalendar = Calendar.getInstance();
    minDateCalendar.setTime(records.get(0).date);
    minDateCalendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    Calendar currentTimeCalendar = Calendar.getInstance();
    return (int) ((currentTimeCalendar.getTimeInMillis() - minDateCalendar.getTimeInMillis())
            / (7 * Constants.DAY_IN_MILLISECONDS));
}

From source file:org.medici.bia.common.util.DateUtils.java

/**
 * /* w w w .  j  ava2  s. c o  m*/
 * @return
 */
public static Date getFirstDayOfCurrentWeek() {
    // Get calendar set to current date and time
    Calendar calendar = Calendar.getInstance();

    // Set the calendar to monday of the current week
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

    return new Date(calendar.getTimeInMillis());
}

From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java

/** Called when the activity is first created. */
@Override//  ww  w  . j av  a2s. c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mood_history);
    mDayDataHandler = new DayDataHandler(this);

    mCurrentSprint = getIntent().getExtras().getParcelable(Sprint.CURRENT_SPRINT);
    mRes = getResources();
    mSprintStartDateInMillis = mCurrentSprint.getStartTime();
    mSprintEndDateInMillis = mCurrentSprint.getEndTime();

    mDaysInSprint = mCurrentSprint.getDaysInSprint();
    ActionBar actionBar = getActionBar();

    Calendar mToday = Calendar.getInstance();
    UtilityMethods.setToDayStart(mToday);
    mToday.setFirstDayOfWeek(Calendar.MONDAY);

    mNumberOfTodayInSprint = mCurrentSprint.getCurrentDayOfTheSprint();

    // Check if the sprint is already over.
    if (mNumberOfTodayInSprint > mDaysInSprint) {
        mNumberOfTodayInSprint = mDaysInSprint;
    }
    actionBar.setSubtitle(mCurrentSprint.getSprintTitle());
    actionBar.setTitle(mNumberOfTodayInSprint + " " + getString(R.string.days));
    actionBar.setBackgroundDrawable(mRes.getDrawable(R.drawable.action_bar_orange));

    mStartDate = Calendar.getInstance();
    mStartDate.setFirstDayOfWeek(Calendar.MONDAY);
    mStartDate.setTimeInMillis(mSprintStartDateInMillis);

    // Calculate the number of weeks in the sprint
    mNumberOfWeeksInSprint = mToday.get(Calendar.WEEK_OF_YEAR) - mStartDate.get(Calendar.WEEK_OF_YEAR) + 1;
    if (mNumberOfWeeksInSprint < 0) {
        mNumberOfWeeksInSprint = 52 + 1 - mStartDate.get(Calendar.WEEK_OF_YEAR)
                + mToday.get(Calendar.WEEK_OF_YEAR);
    } else {

    }

    // Sets the default selections as today or this week.
    mSelectedDay = mNumberOfTodayInSprint - 1;
    mSelectedWeek = mNumberOfWeeksInSprint - 1;
    mViewPager = (ViewPager) findViewById(R.id.activity_mood_history_viewpager);

    titleIndicator = (TitlePageIndicator) findViewById(R.id.indicator);

    // Page change listener to keep the selected week and day in a member.
    titleIndicator.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int arg0) {
            if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                mSelectedDay = arg0;
            } else if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
                mSelectedWeek = arg0;
                MoodHistoryWeekFragment fragment = mPagerAdapterWeek.getWeekFragment(arg0);
                if (fragment != null) {
                    fragment.updateSelectedAttribute(mSelectedAttribute, false);
                }
            }
        }
    });

    setPageTitles();

    // Load correct layout and functionality based on orientation
    if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        loadPortraitView();
    } else if (mRes.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        loadLandscapeView();
    }

}

From source file:com.clustercontrol.jobmanagement.factory.JobPlanSchedule.java

/**
 * ????Cron??//from  www. j  a v  a  2  s  . c o m
 * 
 * @param cron
 */
private void createPlan(String cron) {

    /*
     * cron
     *       
     */

    // * 0 15 * * ? *         1500
    // * 0 23 ? * 1 *         2300
    // * */10 * * * ? *       10??

    String[] planSplit = cron.split(" ");
    String aster = "*";
    String question = "?";
    String slash = "/";
    if (!aster.equals(planSplit[0])) {
        secondType = 0;
        second = Integer.parseInt(planSplit[0]);
    }
    if (!aster.equals(planSplit[1])) {
        String[] slashSplit = planSplit[1].split(slash);
        int num = 0;
        for (String str : slashSplit) {
            m_log.trace("slashSplit[ " + num + " ] =" + str);
            num++;
        }
        //p?q????
        if (slashSplit.length == 2) {
            minuteType = 3;
            minute = Integer.parseInt(slashSplit[0]);
            fromMinutes = Integer.parseInt(slashSplit[0]);
            everyMinutes = Integer.parseInt(slashSplit[1]);
        } else {
            minuteType = 0;
            minute = Integer.parseInt(planSplit[1]);
            m_log.debug("minuteType=" + minuteType);
            m_log.debug("minute=" + minute);
        }
    }
    if (!aster.equals(planSplit[2])) {
        hourType = 0;
        hour = Integer.parseInt(planSplit[2]);
    }
    if (question.equals(planSplit[3])) {
        dayType = 2;
    } else if (!aster.equals(planSplit[3])) {
        dayType = 0;
        day = Integer.parseInt(planSplit[3]);
    }
    if (!aster.equals(planSplit[4])) {
        monthType = 0;
        month = Integer.parseInt(planSplit[4]);
    }
    if (question.equals(planSplit[5])) {
        weekType = 2;
    } else if (!aster.equals(planSplit[5])) {
        weekType = 0;
        week = Integer.parseInt(planSplit[5]);
    }
    switch (week) {
    case 1:
        weekCalendar = Calendar.SUNDAY;
        break;
    case 2:
        weekCalendar = Calendar.MONDAY;
        break;
    case 3:
        weekCalendar = Calendar.TUESDAY;
        break;
    case 4:
        weekCalendar = Calendar.WEDNESDAY;
        break;
    case 5:
        weekCalendar = Calendar.THURSDAY;
        break;
    case 6:
        weekCalendar = Calendar.FRIDAY;
        break;
    case 7:
        weekCalendar = Calendar.SATURDAY;
        break;
    default:
        weekCalendar = Calendar.SUNDAY;
    }
    // weekType?0??????????
    // ??????????*????0?? 
    if (weekType == 0 && isFireDayOfWeek() == false) {
        nextFireDay();
        if (hourType == 1) {
            hour = 0;
        }
    }
}