|
|
@ -6,142 +6,142 @@ import java.util.GregorianCalendar; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.time.DateUtils; |
|
|
|
import org.apache.commons.lang.time.DateUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class FestivitaUtil { |
|
|
|
public class FestivitaUtil { |
|
|
|
|
|
|
|
|
|
|
|
public final static boolean isFestivo(Date date) { |
|
|
|
public final static boolean isFestivo(Date date) { |
|
|
|
|
|
|
|
|
|
|
|
int year = DateUtils.toCalendar(date).get(Calendar.YEAR); |
|
|
|
int year = DateUtils.toCalendar(date).get(Calendar.YEAR); |
|
|
|
|
|
|
|
|
|
|
|
boolean isCapodanno = is(date, 1, 1); |
|
|
|
boolean isCapodanno = is(date, 1, 1); |
|
|
|
boolean isBefana = is(date, 6, 1); |
|
|
|
boolean isBefana = is(date, 6, 1); |
|
|
|
boolean isPasqua = isPasqua(date); |
|
|
|
boolean isPasqua = isPasqua(date); |
|
|
|
|
|
|
|
|
|
|
|
boolean isPasquetta = false; |
|
|
|
boolean isPasquetta = false; |
|
|
|
Date dtPasqua = findPasqua(year); |
|
|
|
Date dtPasqua = findPasqua(year); |
|
|
|
if (dtPasqua != null) { |
|
|
|
if (dtPasqua != null) { |
|
|
|
Calendar calendar = DateUtils.toCalendar(dtPasqua); |
|
|
|
Calendar calendar = DateUtils.toCalendar(dtPasqua); |
|
|
|
while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { |
|
|
|
while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { |
|
|
|
calendar.add(Calendar.DATE, 1); |
|
|
|
calendar.add(Calendar.DATE, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
isPasquetta = is(date, calendar.getTime()); |
|
|
|
isPasquetta = is(date, calendar.getTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean isFestaDellaLiberazione = is(date, 25, 4); |
|
|
|
boolean isFestaDellaLiberazione = is(date, 25, 4); |
|
|
|
boolean isFestaDeiLavoratori = is(date, 1, 5); |
|
|
|
boolean isFestaDeiLavoratori = is(date, 1, 5); |
|
|
|
boolean isFestaDellaRepubblica = is(date, 2, 6); |
|
|
|
boolean isFestaDellaRepubblica = is(date, 2, 6); |
|
|
|
boolean isFerragosto = is(date, 15, 8); |
|
|
|
boolean isFerragosto = is(date, 15, 8); |
|
|
|
boolean isOgnissanti = is(date, 1, 11); |
|
|
|
boolean isOgnissanti = is(date, 1, 11); |
|
|
|
boolean isImmacolataConcezione = is(date, 8, 12); |
|
|
|
boolean isImmacolataConcezione = is(date, 8, 12); |
|
|
|
boolean isNatale = is(date, 25, 12); |
|
|
|
boolean isNatale = is(date, 25, 12); |
|
|
|
boolean isSantoStefano = is(date, 26, 12); |
|
|
|
boolean isSantoStefano = is(date, 26, 12); |
|
|
|
|
|
|
|
|
|
|
|
return isCapodanno || isBefana || isPasqua || isPasquetta || isFestaDellaLiberazione || isFestaDeiLavoratori |
|
|
|
return isCapodanno || isBefana || isPasqua || isPasquetta || isFestaDellaLiberazione |
|
|
|
|| isFestaDellaRepubblica || isFerragosto || isOgnissanti || isImmacolataConcezione || isNatale |
|
|
|
|| isFestaDeiLavoratori || isFestaDellaRepubblica || isFerragosto || isOgnissanti |
|
|
|
|| isSantoStefano; |
|
|
|
|| isImmacolataConcezione || isNatale || isSantoStefano; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final static boolean isPasqua(Date date) { |
|
|
|
private final static boolean isPasqua(Date date) { |
|
|
|
|
|
|
|
|
|
|
|
Calendar calendar = new GregorianCalendar(); |
|
|
|
Calendar calendar = new GregorianCalendar(); |
|
|
|
calendar.setTime(date); |
|
|
|
calendar.setTime(date); |
|
|
|
|
|
|
|
|
|
|
|
int year = calendar.get(Calendar.YEAR); |
|
|
|
int year = calendar.get(Calendar.YEAR); |
|
|
|
int dateYMD = year * 10000 + calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DAY_OF_MONTH); |
|
|
|
int dateYMD = year * 10000 + calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DAY_OF_MONTH); |
|
|
|
|
|
|
|
|
|
|
|
Date pasqua = findPasqua(year); |
|
|
|
Date pasqua = findPasqua(year); |
|
|
|
if (pasqua != null) { |
|
|
|
if (pasqua != null) { |
|
|
|
calendar.setTime(pasqua); |
|
|
|
calendar.setTime(pasqua); |
|
|
|
int pasquaYMD = year * 10000 + calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DAY_OF_MONTH); |
|
|
|
int pasquaYMD = year * 10000 + calendar.get(Calendar.MONTH) * 100 |
|
|
|
return (pasquaYMD == dateYMD); |
|
|
|
+ calendar.get(Calendar.DAY_OF_MONTH); |
|
|
|
} |
|
|
|
return (pasquaYMD == dateYMD); |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
private final static boolean is(Date date, int day, int month) { |
|
|
|
|
|
|
|
Calendar calendar = DateUtils.toCalendar(date); |
|
|
|
private final static boolean is(Date date, int day, int month) { |
|
|
|
return calendar.get(Calendar.DATE) == day && (calendar.get(Calendar.MONTH) + 1) == month; |
|
|
|
Calendar calendar = DateUtils.toCalendar(date); |
|
|
|
} |
|
|
|
return calendar.get(Calendar.DATE) == day && (calendar.get(Calendar.MONTH) + 1) == month; |
|
|
|
|
|
|
|
} |
|
|
|
private final static boolean is(Date date, Date date2) { |
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
private final static boolean is(Date date, Date date2) { |
|
|
|
calendar.setTime(date); |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
Calendar calendar2 = Calendar.getInstance(); |
|
|
|
calendar.setTime(date); |
|
|
|
calendar2.setTime(date2); |
|
|
|
Calendar calendar2 = Calendar.getInstance(); |
|
|
|
return calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE) |
|
|
|
calendar2.setTime(date2); |
|
|
|
&& calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH); |
|
|
|
return calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE) |
|
|
|
} |
|
|
|
&& calendar.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH); |
|
|
|
|
|
|
|
} |
|
|
|
private final static Date findPasqua(int year) { |
|
|
|
|
|
|
|
|
|
|
|
private final static Date findPasqua(int year) { |
|
|
|
if ((year < 1573) || (year > 2499)) { |
|
|
|
|
|
|
|
throw null; |
|
|
|
if ((year < 1573) || (year > 2499)) { |
|
|
|
} |
|
|
|
throw null; |
|
|
|
|
|
|
|
} |
|
|
|
int a = year % 19; |
|
|
|
|
|
|
|
int b = year % 4; |
|
|
|
int a = year % 19; |
|
|
|
int c = year % 7; |
|
|
|
int b = year % 4; |
|
|
|
|
|
|
|
int c = year % 7; |
|
|
|
int m = 0; |
|
|
|
|
|
|
|
int n = 0; |
|
|
|
int m = 0; |
|
|
|
|
|
|
|
int n = 0; |
|
|
|
if ((year >= 1583) && (year <= 1699)) { |
|
|
|
|
|
|
|
m = 22; |
|
|
|
if ((year >= 1583) && (year <= 1699)) { |
|
|
|
n = 2; |
|
|
|
m = 22; |
|
|
|
} |
|
|
|
n = 2; |
|
|
|
if ((year >= 1700) && (year <= 1799)) { |
|
|
|
} |
|
|
|
m = 23; |
|
|
|
if ((year >= 1700) && (year <= 1799)) { |
|
|
|
n = 3; |
|
|
|
m = 23; |
|
|
|
} |
|
|
|
n = 3; |
|
|
|
if ((year >= 1800) && (year <= 1899)) { |
|
|
|
} |
|
|
|
m = 23; |
|
|
|
if ((year >= 1800) && (year <= 1899)) { |
|
|
|
n = 4; |
|
|
|
m = 23; |
|
|
|
} |
|
|
|
n = 4; |
|
|
|
if ((year >= 1900) && (year <= 2099)) { |
|
|
|
} |
|
|
|
m = 24; |
|
|
|
if ((year >= 1900) && (year <= 2099)) { |
|
|
|
n = 5; |
|
|
|
m = 24; |
|
|
|
} |
|
|
|
n = 5; |
|
|
|
if ((year >= 2100) && (year <= 2199)) { |
|
|
|
} |
|
|
|
m = 24; |
|
|
|
if ((year >= 2100) && (year <= 2199)) { |
|
|
|
n = 6; |
|
|
|
m = 24; |
|
|
|
} |
|
|
|
n = 6; |
|
|
|
if ((year >= 2200) && (year <= 2299)) { |
|
|
|
} |
|
|
|
m = 25; |
|
|
|
if ((year >= 2200) && (year <= 2299)) { |
|
|
|
n = 0; |
|
|
|
m = 25; |
|
|
|
} |
|
|
|
n = 0; |
|
|
|
if ((year >= 2300) && (year <= 2399)) { |
|
|
|
} |
|
|
|
m = 26; |
|
|
|
if ((year >= 2300) && (year <= 2399)) { |
|
|
|
n = 1; |
|
|
|
m = 26; |
|
|
|
} |
|
|
|
n = 1; |
|
|
|
if ((year >= 2400) && (year <= 2499)) { |
|
|
|
} |
|
|
|
m = 25; |
|
|
|
if ((year >= 2400) && (year <= 2499)) { |
|
|
|
n = 1; |
|
|
|
m = 25; |
|
|
|
} |
|
|
|
n = 1; |
|
|
|
|
|
|
|
} |
|
|
|
int d = (19 * a + m) % 30; |
|
|
|
|
|
|
|
int e = (2 * b + 4 * c + 6 * d + n) % 7; |
|
|
|
int d = (19 * a + m) % 30; |
|
|
|
|
|
|
|
int e = (2 * b + 4 * c + 6 * d + n) % 7; |
|
|
|
Calendar calendar = new GregorianCalendar(); |
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year); |
|
|
|
Calendar calendar = new GregorianCalendar(); |
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year); |
|
|
|
if (d + e < 10) { |
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year); |
|
|
|
if (d + e < 10) { |
|
|
|
calendar.set(Calendar.MONTH, Calendar.MARCH); |
|
|
|
calendar.set(Calendar.YEAR, year); |
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, d + e + 22); |
|
|
|
calendar.set(Calendar.MONTH, Calendar.MARCH); |
|
|
|
} else { |
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, d + e + 22); |
|
|
|
calendar.set(Calendar.MONTH, Calendar.APRIL); |
|
|
|
} else { |
|
|
|
int day = d + e - 9; |
|
|
|
calendar.set(Calendar.MONTH, Calendar.APRIL); |
|
|
|
if (26 == day) { |
|
|
|
int day = d + e - 9; |
|
|
|
day = 19; |
|
|
|
if (26 == day) { |
|
|
|
} |
|
|
|
day = 19; |
|
|
|
if ((25 == day) && (28 == d) && (e == 6) && (a > 10)) { |
|
|
|
} |
|
|
|
day = 18; |
|
|
|
if ((25 == day) && (28 == d) && (e == 6) && (a > 10)) { |
|
|
|
} |
|
|
|
day = 18; |
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, day); |
|
|
|
} |
|
|
|
} |
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, day); |
|
|
|
|
|
|
|
} |
|
|
|
return calendar.getTime(); |
|
|
|
|
|
|
|
} |
|
|
|
return calendar.getTime(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|