1
2
3
4
5
6
7
8
9
10
11
12 package fr.hyphonem.conges;
13
14 import java.math.BigInteger;
15 import java.text.ParseException;
16 import java.text.SimpleDateFormat;
17 import java.util.Calendar;
18 import java.util.Date;
19 import java.util.Enumeration;
20 import java.util.Hashtable;
21
22
23
24
25
26
27 public class FeryDays {
28
29
30
31
32 public FeryDays() {
33 super();
34 }
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public Hashtable getNationalDays(String datedeb, String datefin,
50 String paysISO, String dir) throws Exception {
51 Hashtable hjf = new Hashtable();
52
53 String anneedeb = datedeb.substring(datedeb.lastIndexOf("/") + 1);
54 String anneefin = datefin.substring(datefin.lastIndexOf("/") + 1);
55
56 AccessData ad = new AccessDataMng().getInstance(dir);
57
58 if (anneedeb.equals(anneefin)) {
59 hjf = ad.readNationalHolidays(paysISO, anneedeb);
60 } else {
61 Hashtable hJFdeb = ad.readNationalHolidays(paysISO, anneedeb);
62 Hashtable hJFfin = ad.readNationalHolidays(paysISO, anneefin);
63 hJFdeb.putAll(hJFfin);
64 hjf = hJFdeb;
65 }
66 return hjf;
67 }
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public Hashtable getJoursFeries(String datedeb, String datefin,
83 String paysISO) throws ParseException {
84
85
86 Hashtable hJF = new Hashtable();
87 Hashtable hJFFlottant = new Hashtable();
88 Hashtable hJFFixesFlottants = new Hashtable();
89 Hashtable hJFFixe = new Hashtable();
90
91 Date datdeb = new SimpleDateFormat("dd/MM/yyyy").parse(datedeb);
92 Date datfin = new SimpleDateFormat("dd/MM/yyyy").parse(datefin);
93
94
95 if (paysISO.equals("FR")) {
96
97
98 Hashtable vj = new Hashtable();
99
100 vj.put("01", "Jour de l'an");
101 hJF.put("01", vj);
102
103 vj = new Hashtable();
104 vj.put("01", "Fete du Travail");
105 vj.put("08", "Victoire 1945");
106 hJF.put("05", vj);
107
108 vj = new Hashtable();
109 vj.put("14", "Fete Nationale");
110 hJF.put("07", vj);
111
112 vj = new Hashtable();
113 vj.put("15", "Assomption");
114 hJF.put("08", vj);
115
116 vj = new Hashtable();
117 vj.put("01", "Toussaint");
118 vj.put("11", "Armistice 1918");
119 hJF.put("11", vj);
120
121 vj = new Hashtable();
122 vj.put("25", "Noel");
123 hJF.put("12", vj);
124
125 Calendar cal = Calendar.getInstance();
126 cal.setTime(datdeb);
127 int year_deb = cal.get(Calendar.YEAR);
128
129 cal.setTime(datfin);
130 int year_fin = cal.get(Calendar.YEAR);
131
132
133 int[] years;
134
135 if (year_deb == year_fin) {
136 years = new int[1];
137 years[0] = year_deb;
138 } else {
139 int diff1 = year_fin - year_deb;
140
141 if (diff1 == 1) {
142
143 years = new int[2];
144
145 years[0] = year_deb;
146
147 years[1] = year_fin;
148 } else {
149
150 int i = 0;
151 int diff = year_fin - year_deb + 1;
152 years = new int[diff];
153 for (int a = year_deb; a <= year_fin; a++) {
154 years[i] = a;
155
156 i++;
157 }
158 }
159 }
160
161 for (int a = 0; a < years.length; a++) {
162 int annee = years[a];
163
164 for (Enumeration enumr = hJF.keys(); enumr.hasMoreElements();) {
165 String mois = (String) enumr.nextElement();
166
167 Hashtable hjours = (Hashtable) hJF.get(mois);
168 for (Enumeration enumj = hjours.keys(); enumj
169 .hasMoreElements();) {
170 String jour = (String) enumj.nextElement();
171
172 String label = (String) hjours.get(jour);
173
174 String dateJF = jour + "/" + mois + "/" + annee;
175
176 Date djf = new SimpleDateFormat("dd/MM/yyyy")
177 .parse(dateJF);
178 if (djf.compareTo(datdeb) >= 0
179 && djf.compareTo(datfin) <= 0) {
180 hJFFixe.put(dateJF, label);
181 }
182 }
183 }
184
185
186 String paques = getJourPaques("" + annee);
187 Date datePaques = new SimpleDateFormat("dd/MM/yyyy")
188 .parse(paques);
189
190 cal.setTime(datePaques);
191
192 cal.add(Calendar.DATE, 1);
193 Date lundiPaq = cal.getTime();
194 String datLundiPaq = new SimpleDateFormat("dd/MM/yyyy")
195 .format(lundiPaq);
196 if (lundiPaq.compareTo(datdeb) >= 0
197 && lundiPaq.compareTo(datfin) <= 0) {
198 hJFFlottant.put(datLundiPaq, "Lundi de Paques");
199 }
200
201
202 cal.add(Calendar.DATE, 38);
203 Date ascension = cal.getTime();
204 String datAscension = new SimpleDateFormat("dd/MM/yyyy")
205 .format(ascension);
206 if (ascension.compareTo(datdeb) >= 0
207 && ascension.compareTo(datfin) <= 0) {
208 hJFFlottant.put(datAscension, "Ascension");
209 }
210
211
212 cal.add(Calendar.DATE, 11);
213 Date lundiPentecote = cal.getTime();
214 String datlundiPentecote = new SimpleDateFormat("dd/MM/yyyy")
215 .format(lundiPentecote);
216 if (lundiPentecote.compareTo(datdeb) >= 0
217 && lundiPentecote.compareTo(datfin) <= 0) {
218 hJFFlottant.put(datlundiPentecote, "Lundi de Pentecote");
219 }
220 }
221
222
223
224
225
226
227 hJFFixe.putAll(hJFFlottant);
228
229 hJFFixesFlottants = hJFFixe;
230 }
231
232 return hJFFixesFlottants;
233 }
234
235
236
237
238
239
240
241
242
243 private String getJourPaques(String annee) {
244 BigInteger year = new BigInteger(annee);
245 BigInteger G0 = year.mod(new BigInteger("19"));
246 BigInteger G = G0.add(BigInteger.ONE);
247 BigInteger C = year.divide(new BigInteger("100")).add(BigInteger.ONE);
248 BigInteger X = new BigInteger("3").multiply(C).divide(
249 new BigInteger("4")).subtract(new BigInteger("12"));
250 BigInteger Z = ((new BigInteger("8").multiply(C)).add(new BigInteger(
251 "5"))).divide(new BigInteger("25")).subtract(
252 new BigInteger("5"));
253 BigInteger D = ((new BigInteger("5").multiply(year))
254 .divide(new BigInteger("4"))).subtract(X).subtract(
255 new BigInteger("10"));
256 BigInteger E = ((new BigInteger("11").multiply(G)).add(
257 new BigInteger("20")).add(Z).subtract(X)).mod(new BigInteger(
258 "30"));
259
260 if ((E.equals(new BigInteger("25")) && G
261 .compareTo(new BigInteger("11")) > 0)
262 || E.equals(new BigInteger("24"))) {
263 E = E.add(BigInteger.ONE);
264 }
265
266 BigInteger N = new BigInteger("44").subtract(E);
267
268 if (N.compareTo(new BigInteger("21")) < 0) {
269 N = N.add(new BigInteger("30"));
270 }
271
272 BigInteger P = N.add(new BigInteger("7")).subtract(
273 (D.add(N)).mod(new BigInteger("7")));
274 BigInteger J;
275 if (P.compareTo(new BigInteger("31")) > 0) {
276 J = P.subtract(new BigInteger("31"));
277 } else {
278 J = new BigInteger(P.toString());
279 }
280 BigInteger M;
281 if (J.equals(P)) {
282 M = new BigInteger("3");
283 } else {
284 M = new BigInteger("4");
285 }
286
287 return J.toString() + "/" + M.toString() + "/" + year.toString();
288 }
289 }