Java Year Week getSeasonStartWeekOffset(int year)

Here you can find the source of getSeasonStartWeekOffset(int year)

Description

get Season Start Week Offset

License

Apache License

Declaration

public static int getSeasonStartWeekOffset(int year) 

Method Source Code

//package com.java2s;
/*//from   w w w.j  av  a 2 s.c  om
 * Copyright (c) Justin Moore.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

import java.util.Calendar;

public class Main {
    public static int getSeasonStartWeekOffset(int year) {
        // The first week of the season, since at least 2008, is based around the closest
        // thursday to Sept 1.  Which can be figured out based on, the day of Sept 1.
        // The offsets below yield results consistent with ESPN from 2008-2015, and 
        // with educated guesses about the first week of 2016-2018, and are verified
        // in the Unit testing.  The rule is not consistent with all time, since in 2004
        // and earlier, pre-season games (kickoff classics) played a week earlier in August,
        // were deemed week 1 by ESPN
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        switch (cal.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            return 34;
        case Calendar.MONDAY:
            return 34;
        case Calendar.TUESDAY:
            return 35;
        case Calendar.WEDNESDAY:
            return 35;
        case Calendar.THURSDAY:
            return 35;
        case Calendar.FRIDAY:
            return 34;
        case Calendar.SATURDAY:
            return 34;
        default:
            return 34;
        }
    }
}

Related

  1. getLastDayOfWeek(int year, int week)
  2. getLastWeekOfYear()
  3. getMaxWeekNumOfYear(int year)
  4. getNextWeekMonday(int year, int weekOfYear)
  5. getNumberOfWeeksInYear(int year)
  6. getStartDayOfWeekNo(int year, int weekNo)
  7. getTotalWeekOfYear(int year)
  8. getYmd(int year, int week, int days)