/*******************************************************************************
* Copyright (c) 2011 Michel DAVID mimah35-at-gmail.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.
*
* 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/>.
******************************************************************************/
package fr.gotorennes.util;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import android.text.format.DateFormat;
public class JoursUtils {
private static List<String> feries = new ArrayList<String>();
static {
feries.add("28032016");
feries.add("01052016");
feries.add("05052016");
feries.add("08052016");
feries.add("16052016");
feries.add("14072016");
feries.add("15082016");
feries.add("01112016");
feries.add("11112016");
feries.add("25122016");
feries.add("01012017");
feries.add("17042017");
feries.add("01052017");
feries.add("08052017");
feries.add("25052017");
feries.add("05062017");
feries.add("14072017");
feries.add("15082017");
feries.add("01112017");
feries.add("11112017");
feries.add("25122017");
feries.add("01012018");
}
public static boolean isJourFerie(Calendar calendar) {
String date = DateFormat.format("ddMMyyyy", calendar.getTime()).toString();
return feries.contains(date);
}
public static boolean is1erMai(Calendar calendar) {
return calendar.get(Calendar.MONTH) == Calendar.MAY && calendar.get(Calendar.DATE) == 1;
}
public static String getCalendrier(boolean nuit) {
return getCalendrier(Calendar.getInstance(), nuit);
}
public static String getCalendrier(Calendar calendar, boolean nuit) {
Calendar fakeCalendar = Calendar.getInstance();
fakeCalendar.setTimeInMillis(calendar.getTimeInMillis());
int heures = fakeCalendar.get(Calendar.HOUR_OF_DAY);
if (!nuit && heures < 4) {
fakeCalendar.add(Calendar.DATE, -1);
}
if (is1erMai(fakeCalendar)) {
return "0";
}
if (isJourFerie(fakeCalendar)) {
return "64";
}
switch (fakeCalendar.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
return "1";
case Calendar.TUESDAY:
return "2";
case Calendar.WEDNESDAY:
return "4";
case Calendar.THURSDAY:
return "8";
case Calendar.FRIDAY:
return "16";
case Calendar.SATURDAY:
return "32";
case Calendar.SUNDAY:
return "64";
}
return "0";
}
}