Java Calendar Week lastDayOfWeek(Calendar cal)

Here you can find the source of lastDayOfWeek(Calendar cal)

Description

Get the last day of the week respecting the first day of the week for the provided Calendar.

License

Open Source License

Parameter

Parameter Description
cal a parameter

Declaration

public static int lastDayOfWeek(Calendar cal) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) Nov 2, 2012 NetXForge.//w ww  .j a  va2 s. com
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details. You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 * 
 * Contributors: Christophe Bouhier - initial API and implementation and/or
 * initial documentation
 *******************************************************************************/

import java.util.Calendar;

public class Main {
    /**
     * Get the last day of the week respecting the first day of the week for the
     * provided Calendar.
     * 
     * @param cal
     * @return
     */
    public static int lastDayOfWeek(Calendar cal) {
        final int firstDayOfWeek = cal.getFirstDayOfWeek();

        final int lastDayOfWeek;
        if (firstDayOfWeek != 1) {
            lastDayOfWeek = firstDayOfWeek - 1; // One before the first day...
        } else {
            lastDayOfWeek = cal.getActualMaximum(Calendar.DAY_OF_WEEK); // Expect
        }
        return lastDayOfWeek;
    }
}

Related

  1. isThisWeek(Calendar time)
  2. isWeekday(Calendar cal)
  3. isWeekEnd(Calendar c)
  4. isWeekend(Calendar cal)
  5. isWeekend(GregorianCalendar date)
  6. lastDayOfWeek(Calendar calendar)
  7. setStartOfWeek(Calendar date)
  8. setTimeAsFirstDayOfWeek(Calendar calendar)
  9. truncateToWeek(GregorianCalendar date)