Java Day of Week dayOfWeekFromInt(final int theDay)

Here you can find the source of dayOfWeekFromInt(final int theDay)

Description

Conversion utility for getting a print friendly string representation of a day of the week from a numeric between 1 and 7.

License

Open Source License

Parameter

Parameter Description
theDay an integer between 1 and 7 denoting the day of the week. 1 being Sunday.

Exception

Parameter Description
IllegalArgumentException if argument theDay is not in range of 1 to 7

Return

a print friendly string representation of a day of the week. 1 being Sunday.

Declaration

public static String dayOfWeekFromInt(final int theDay) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/*//from w w w  .  jav  a2 s . c  o m
 * #%L
 * org.bml
 * %%
 * Copyright (C) 2006 - 2014 Brian M. Lima
 * %%
 * This file is part of ORG.BML.
 * 
 *     ORG.BML 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.
 * 
 *     ORG.BML 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 Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with ORG.BML.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */

public class Main {
    /**
     * Conversion utility for getting a print friendly string representation of
     * a day of the week from a numeric between 1 and 7. Sunday is 1.
     *
     * @param theDay an integer between 1 and 7 denoting the day of the week. 1
     * being Sunday.
     * @return a print friendly string representation of a day of the week. 1
     * being Sunday.
     * @throws IllegalArgumentException if argument theDay is not in range of 1 to 7
     */
    public static String dayOfWeekFromInt(final int theDay) throws IllegalArgumentException {
        if (theDay > 7 || theDay < 1) {
            throw new IllegalArgumentException("Argument theDay is not in range of 1 to 7");
        }
        switch (theDay) {
        case 1:
            return "Sunday";
        case 2:
            return "Monday";
        case 3:
            return "Tuesday";
        case 4:
            return "Wednesday";
        case 5:
            return "Thursday";
        case 6:
            return "Friday";
        case 7:
            return "Saturday";
        default: //unreachable but the compiler wants it!
            return null;
        }
    }
}

Related

  1. dayOfWeek(Date date)
  2. dayOfWeek(Date inDate, TimeZone timeZone)
  3. dayOfWeek(Date time)
  4. dayOfWeek(int dayMark)
  5. dayOfWeek(int year, int month, int day)
  6. dayOfWeekFromInteger(String aDay, boolean longName)
  7. dayOfWeekNames()
  8. endOfWeek(Date inDate, TimeZone timeZone)
  9. extractDayOfWeek(Date date)