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