1 | /*
|
---|
2 | * Class TimeAndDate
|
---|
3 | *
|
---|
4 | * USAGE: Methods concerned with returning times dates and timing events
|
---|
5 | *
|
---|
6 | * WRITTEN BY: Dr Michael Thomas Flanagan
|
---|
7 | *
|
---|
8 | * DATE: 28 September 2009
|
---|
9 | * AMENDED: 2-3 October 2009
|
---|
10 | *
|
---|
11 | * DOCUMENTATION:
|
---|
12 | * See Michael Thomas Flanagan's Java library on-line web pages:
|
---|
13 | * http://www.ee.ucl.ac.uk/~mflanaga/java/
|
---|
14 | * http://www.ee.ucl.ac.uk/~mflanaga/java/TimeAndDate.html
|
---|
15 | *
|
---|
16 | * Copyright (c) 2009
|
---|
17 | *
|
---|
18 | * PERMISSION TO COPY:
|
---|
19 | *
|
---|
20 | * Redistributions of this source code, or parts of, must retain the above
|
---|
21 | * copyright notice, this list of conditions and the following disclaimer.
|
---|
22 | *
|
---|
23 | * Redistribution in binary form of all or parts of this class, must reproduce
|
---|
24 | * the above copyright, this list of conditions and the following disclaimer in
|
---|
25 | * the documentation and/or other materials provided with the distribution.
|
---|
26 | *
|
---|
27 | * Permission to use, copy and modify this software and its documentation for
|
---|
28 | * NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
|
---|
29 | * to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all
|
---|
30 | * copies and associated documentation or publications.
|
---|
31 | *
|
---|
32 | * Dr Michael Thomas Flanagan makes no representations about the suitability
|
---|
33 | * or fitness of the software for any or for a particular purpose.
|
---|
34 | * Michael Thomas Flanagan shall not be liable for any damages suffered
|
---|
35 | * as a result of using, modifying or distributing this software or its derivatives.
|
---|
36 | *
|
---|
37 | ***************************************************************************************/
|
---|
38 |
|
---|
39 | package agents.anac.y2015.agentBuyogV2.flanagan.math;
|
---|
40 |
|
---|
41 | import java.util.Calendar;
|
---|
42 |
|
---|
43 | public class TimeAndDate{
|
---|
44 |
|
---|
45 | private Calendar cal = Calendar.getInstance(); // instance of abstract class Calendar
|
---|
46 | private String dayOfTheWeek = null; // day of the week
|
---|
47 | private int dayOfTheMonth = 0; // day of the month
|
---|
48 | private String monthOfTheYear = null; // month of the year
|
---|
49 | private int monthAsInteger = 0; // month as integer
|
---|
50 | private int year = 0; // year
|
---|
51 | private String fullDate = null; // date as 'day name', 'day of month' 'month name' year
|
---|
52 | private String date = null; // 'day of month' 'month name' 'year'
|
---|
53 | private String shortDateUK = null; // UK Format - 'day of month'.'month'.'year final two digits'
|
---|
54 | private String shortDateUS = null; // US Format - 'month'/'day of month'/'year final two digits'
|
---|
55 |
|
---|
56 | private String[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
---|
57 | private String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
|
---|
58 | private int[] monthDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
---|
59 |
|
---|
60 | private int hour24 = -1; // hour of the day (24 hour clock)
|
---|
61 | private String hour12 = null; // hour of the day as am or pm (12 hour clock)
|
---|
62 | private int minute = -1; // minute of the hour
|
---|
63 | private int second = -1; // seconds of the minute
|
---|
64 | private int millisecond = -1; // milliseconds of the second
|
---|
65 | private String shortTime24 = null; // time as hour.minute (24 hour clock)
|
---|
66 | private String shortTime12 = null; // time as hour.minute AM or PM (12 hour clock)
|
---|
67 | private String midTime24 = null; // time as hour.minute.second (24 hour clock)
|
---|
68 | private String midTime12 = null; // time as hour.minute.second AM or PM (12 hour clock)
|
---|
69 | private String fullTime24 = null; // time as hour.minute.second.millisecond (24 hour clock)
|
---|
70 | private String fullTime12 = null; // time as hour.minute.second.millisecond AM OR PM (12 hour clock)
|
---|
71 |
|
---|
72 | private long tStart = 0L; // start time
|
---|
73 | private boolean startCheck = false; // = true when timing start set
|
---|
74 | private long tEnd = 0L; // end time
|
---|
75 | private boolean endCheck = false; // = true when timing end set
|
---|
76 | private long totalTime = 0L; // tEnd - tStart
|
---|
77 |
|
---|
78 | private String changeDate = null; // next BST change
|
---|
79 | private boolean backForw = true; // = true next BST change is back, i.e if date is within BST; = false next BST change = forward
|
---|
80 |
|
---|
81 | private int easterMonth = 0; // Easter Sunday month
|
---|
82 | private int easterDay = 0; // Easter Sunday day of the month
|
---|
83 | private String easterDayName = null; // Easter Sunday day name, i.e. "Sunday" - calculated as a check of the method
|
---|
84 |
|
---|
85 | private int yearHold = 0; // Last calculated year
|
---|
86 | private int monthHold = 0; // Last calculated month
|
---|
87 | private int dayHold = 0; // Last calculated day of the month
|
---|
88 | private String dayNameHold = null; // Last calculated day name
|
---|
89 |
|
---|
90 |
|
---|
91 | // CONSTRUCTOR
|
---|
92 | public TimeAndDate(){
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | // Causes the program to wait for nSeconds seconds before continuing (int)
|
---|
97 | public void waitFor(int nSeconds){
|
---|
98 | long t0,t1;
|
---|
99 | t0=System.currentTimeMillis();
|
---|
100 | do{
|
---|
101 | t1=System.currentTimeMillis();
|
---|
102 | }
|
---|
103 | while ((t1-t0)<nSeconds*1000);
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Causes the program to wait for nSeconds seconds before continuing (long)
|
---|
107 | public void waitFor(long nSeconds){
|
---|
108 | if(nSeconds>Long.MAX_VALUE/1000){
|
---|
109 | System.out.println("Class: TimeAndDate, method: wait(long nSeconds), nSeconds is too large for this method - the value has been replaced by " + Long.MAX_VALUE/1000);
|
---|
110 | nSeconds = Long.MAX_VALUE/1000;
|
---|
111 | }
|
---|
112 | long t0,t1;
|
---|
113 | t0=System.currentTimeMillis();
|
---|
114 | do{
|
---|
115 | t1=System.currentTimeMillis();
|
---|
116 | }
|
---|
117 | while ((t1-t0)<nSeconds*1000);
|
---|
118 | }
|
---|
119 |
|
---|
120 | // Causes the program to wait for nSeconds seconds before continuing (double)
|
---|
121 | public void waitFor(double nSeconds){
|
---|
122 | long tt = 0L;
|
---|
123 | if(nSeconds>Math.pow(2.0, 63)-1.0){
|
---|
124 | System.out.println("Class: TimeAndDate, method: wait(double nSeconds), nSeconds is too large for this method - the value has been replaced by " + Long.MAX_VALUE/1000);
|
---|
125 | tt = Long.MAX_VALUE;
|
---|
126 | }
|
---|
127 | else{
|
---|
128 | tt = Conv.convert_double_to_long(nSeconds*1000);
|
---|
129 | }
|
---|
130 | long t0,t1;
|
---|
131 | t0=System.currentTimeMillis();
|
---|
132 | do{
|
---|
133 | t1=System.currentTimeMillis();
|
---|
134 | }
|
---|
135 | while ((t1-t0)<tt);
|
---|
136 | }
|
---|
137 |
|
---|
138 | // Marker method for starting the timing of a bloc of code
|
---|
139 | public void blocStart(){
|
---|
140 | this.tStart = System.currentTimeMillis();
|
---|
141 | this.startCheck = true;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Marker method for ending the timing of a bloc of code and for returning the total time
|
---|
145 | public long blocEnd(){
|
---|
146 | if(this.startCheck){
|
---|
147 | this.tEnd = System.currentTimeMillis();
|
---|
148 | this.totalTime = this.tEnd - this.tStart;
|
---|
149 | this.endCheck = true;
|
---|
150 | }
|
---|
151 | else{
|
---|
152 | throw new IllegalArgumentException("No start marker has been set");
|
---|
153 | }
|
---|
154 | return this.totalTime;
|
---|
155 | }
|
---|
156 |
|
---|
157 | // Returns total time taken to run a bloc of code
|
---|
158 | public long blocTime(){
|
---|
159 | if(this.endCheck){
|
---|
160 | return this.totalTime;
|
---|
161 | }
|
---|
162 | else{
|
---|
163 | if(!this.startCheck){
|
---|
164 | System.out.println("Class Time: method totalTime: No start marker has been set - -9999 rturned");
|
---|
165 | return -9999L;
|
---|
166 | }
|
---|
167 | else{
|
---|
168 | System.out.println("Class Time: method totalTime: No end marker has been set - -8888 rturned");
|
---|
169 | return -8888L;
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | // Get the hour of the day (24 hour clock)
|
---|
175 | public int getHour24(){
|
---|
176 | this.hour24 = cal.get(Calendar.HOUR_OF_DAY);
|
---|
177 | return this.hour24;
|
---|
178 | }
|
---|
179 |
|
---|
180 | // Get the hour of the day, am or pm (12 hour clock)
|
---|
181 | public String getHour12(){
|
---|
182 | int hour = cal.get(Calendar.HOUR);
|
---|
183 | int amPm = cal.get(Calendar.AM_PM);
|
---|
184 | if(amPm==0){
|
---|
185 | this.hour12 = (new Integer(hour)).toString() + " AM";
|
---|
186 | }
|
---|
187 | else{
|
---|
188 | this.hour12 = (new Integer(hour)).toString() + " PM";
|
---|
189 | }
|
---|
190 | return this.hour12;
|
---|
191 | }
|
---|
192 |
|
---|
193 | // Get the minute of the hour
|
---|
194 | public int getMinute(){
|
---|
195 | this.minute = cal.get(Calendar.MINUTE);
|
---|
196 | return this.minute;
|
---|
197 | }
|
---|
198 |
|
---|
199 | // Get the second of the minute
|
---|
200 | public int getSecond(){
|
---|
201 | this.second = cal.get(Calendar.SECOND);
|
---|
202 | return this.second;
|
---|
203 | }
|
---|
204 |
|
---|
205 | // Get the millisecond of the second
|
---|
206 | public int getMilliSecond(){
|
---|
207 | this.millisecond = cal.get(Calendar.MILLISECOND);
|
---|
208 | return this.millisecond;
|
---|
209 | }
|
---|
210 |
|
---|
211 | // Get time as hour.minute (24 hour clock)
|
---|
212 | public String getShortTime24(){
|
---|
213 | int hourI = this.getHour24();
|
---|
214 | this.shortTime24 = (new Integer(hourI)).toString();
|
---|
215 | int minI = this.getMinute();
|
---|
216 | if(minI<10){
|
---|
217 | this.shortTime24 += ".0" + minI;
|
---|
218 | }
|
---|
219 | else{
|
---|
220 | this.shortTime24 += "." + minI;
|
---|
221 | }
|
---|
222 | return this.shortTime24;
|
---|
223 | }
|
---|
224 |
|
---|
225 | // Get time as hour.minute AM or PM (12 hour clock)
|
---|
226 | public String getShortTime12(){
|
---|
227 | int hourI = cal.get(Calendar.HOUR);
|
---|
228 | int amPm = cal.get(Calendar.AM_PM);
|
---|
229 | this.shortTime12 = (new Integer(hourI)).toString();
|
---|
230 | int minI = this.getMinute();
|
---|
231 | if(minI<10){
|
---|
232 | this.shortTime12 += ".0" + minI;
|
---|
233 | }
|
---|
234 | else{
|
---|
235 | this.shortTime12 += "." + minI;
|
---|
236 | }
|
---|
237 | if(amPm==0){
|
---|
238 | this.shortTime12 += " " + "AM";
|
---|
239 | }
|
---|
240 | else{
|
---|
241 | this.shortTime12 += " " + "PM";
|
---|
242 | }
|
---|
243 | return this.shortTime12;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // Get time as hour.minute.second (24 hour clock)
|
---|
247 | public String getMidTime24(){
|
---|
248 | int hourI = this.getHour24();
|
---|
249 | this.midTime24 = (new Integer(hourI)).toString();
|
---|
250 | int minI = this.getMinute();
|
---|
251 | if(minI<10){
|
---|
252 | this.midTime24 += ".0" + minI;
|
---|
253 | }
|
---|
254 | else{
|
---|
255 | this.midTime24 += "." + minI;
|
---|
256 | }
|
---|
257 | int secI = this.getSecond();
|
---|
258 | if(secI<10){
|
---|
259 | this.midTime24 += ".0" + secI;
|
---|
260 | }
|
---|
261 | else{
|
---|
262 | this.midTime24 += "." + secI;
|
---|
263 | }
|
---|
264 | return this.midTime24;
|
---|
265 | }
|
---|
266 |
|
---|
267 | // Get time as hour.minute.second AM or PM (12 hour clock)
|
---|
268 | public String getMidTime12(){
|
---|
269 | int hourI = cal.get(Calendar.HOUR);
|
---|
270 | int amPm = cal.get(Calendar.AM_PM);
|
---|
271 | this.midTime12 = (new Integer(hourI)).toString();
|
---|
272 | int minI = this.getMinute();
|
---|
273 | if(minI<10){
|
---|
274 | this.midTime12 += ".0" + minI;
|
---|
275 | }
|
---|
276 | else{
|
---|
277 | this.midTime12 += "." + minI;
|
---|
278 | }
|
---|
279 | int secI = this.getSecond();
|
---|
280 | if(secI<10){
|
---|
281 | this.midTime12 += ".0" + secI;
|
---|
282 | }
|
---|
283 | else{
|
---|
284 | this.midTime12 += "." + secI;
|
---|
285 | }
|
---|
286 | if(amPm==0){
|
---|
287 | this.midTime12 += " " + "AM";
|
---|
288 | }
|
---|
289 | else{
|
---|
290 | this.midTime12 += " " + "PM";
|
---|
291 | }
|
---|
292 | return this.midTime12;
|
---|
293 | }
|
---|
294 |
|
---|
295 | // Get time as hour.minute.second.millisecond (24 hour clock)
|
---|
296 | public String getFullTime24(){
|
---|
297 | int hourI = this.getHour24();
|
---|
298 | this.fullTime24 = (new Integer(hourI)).toString();
|
---|
299 | int minI = this.getMinute();
|
---|
300 | if(minI<10){
|
---|
301 | this.fullTime24 += ".0" + minI;
|
---|
302 | }
|
---|
303 | else{
|
---|
304 | this.fullTime24 += "." + minI;
|
---|
305 | }
|
---|
306 | int secI = this.getSecond();
|
---|
307 | if(secI<10){
|
---|
308 | this.fullTime24 += ".0" + secI;
|
---|
309 | }
|
---|
310 | else{
|
---|
311 | this.fullTime24 += "." + secI;
|
---|
312 | }
|
---|
313 | int msecI = this.getMilliSecond();
|
---|
314 | if(msecI<10){
|
---|
315 | this.fullTime24 += ".00" + msecI;
|
---|
316 | }
|
---|
317 | else{
|
---|
318 | if(msecI<100){
|
---|
319 | this.fullTime24 += ".0" + msecI;
|
---|
320 | }
|
---|
321 | else{
|
---|
322 | this.fullTime24 += "." + msecI;
|
---|
323 | }
|
---|
324 | }
|
---|
325 | return this.fullTime24;
|
---|
326 | }
|
---|
327 |
|
---|
328 | // Get time as hour.minute.second.millisecond AM OR PM (12 hour clock)
|
---|
329 | public String getFullTime12(){
|
---|
330 | int hourI = cal.get(Calendar.HOUR);
|
---|
331 | int amPm = cal.get(Calendar.AM_PM);
|
---|
332 | this.fullTime12 = (new Integer(hourI)).toString();
|
---|
333 | int minI = this.getMinute();
|
---|
334 | if(minI<10){
|
---|
335 | this.fullTime12 += ".0" + minI;
|
---|
336 | }
|
---|
337 | else{
|
---|
338 | this.fullTime12 += "." + minI;
|
---|
339 | }
|
---|
340 | int secI = this.getSecond();
|
---|
341 | if(secI<10){
|
---|
342 | this.fullTime12 += ".0" + secI;
|
---|
343 | }
|
---|
344 | else{
|
---|
345 | this.fullTime12 += "." + secI;
|
---|
346 | }
|
---|
347 | int msecI = this.getMilliSecond();
|
---|
348 | if(msecI<10){
|
---|
349 | this.fullTime12 += ".00" + msecI;
|
---|
350 | }
|
---|
351 | else{
|
---|
352 | if(msecI<100){
|
---|
353 | this.fullTime12 += ".0" + msecI;
|
---|
354 | }
|
---|
355 | else{
|
---|
356 | this.fullTime12 += "." + msecI;
|
---|
357 | }
|
---|
358 | }
|
---|
359 | if(amPm==0){
|
---|
360 | this.fullTime12 += " " + "AM";
|
---|
361 | }
|
---|
362 | else{
|
---|
363 | this.fullTime12 += " " + "PM";
|
---|
364 | }
|
---|
365 | return this.fullTime12;
|
---|
366 | }
|
---|
367 |
|
---|
368 | // Return the current computer time in milliseconds
|
---|
369 | public long getComputerTime(){
|
---|
370 | return System.currentTimeMillis();
|
---|
371 | }
|
---|
372 |
|
---|
373 | // Converts a date to milliseconds since 0 hours 0 minutes 0 seconds on 1 Jan 1970
|
---|
374 | public long dateToJavaMilliSecondsUK(int year, int month, int dayOfTheMonth, String dayOfTheWeek, int hour, int min, int sec, int millisec){
|
---|
375 |
|
---|
376 | long ms = 0L; // milliseconds since 0 hours 0 minutes 0 seconds and o milliseconds on 1 Jan 1970
|
---|
377 |
|
---|
378 | // Day of the week as integer
|
---|
379 | int dayIndicator = this.getDayOfTheWeekAsInteger(dayOfTheWeek);
|
---|
380 |
|
---|
381 | // British Summer Time adjustment
|
---|
382 | long bst = 0;
|
---|
383 | this.backForw = checkBST(dayOfTheWeek, dayOfTheMonth, hour, month, dayIndicator);
|
---|
384 | if(this.backForw)bst = 1;
|
---|
385 |
|
---|
386 | // millisecond calculation
|
---|
387 | if(year>=1970){
|
---|
388 | // Date after the zero computer time
|
---|
389 | long yearDiff = 0L;
|
---|
390 | int yearTest = year-1;
|
---|
391 | while(yearTest>=1970){
|
---|
392 | yearDiff += 365;
|
---|
393 | if(this.leapYear(yearTest))yearDiff++;
|
---|
394 | yearTest--;
|
---|
395 | }
|
---|
396 | yearDiff *= 24L*60L*60L*1000L;
|
---|
397 |
|
---|
398 | long monthDiff = 0L;
|
---|
399 | int monthTest = month - 1;
|
---|
400 | while(monthTest>0){
|
---|
401 | monthDiff += monthDays[monthTest-1];
|
---|
402 | if(this.leapYear(year) && monthTest==2)monthDiff++;
|
---|
403 | monthTest--;
|
---|
404 | }
|
---|
405 | monthDiff *= 24L*60L*60L*1000L;
|
---|
406 |
|
---|
407 | long dayDiff = (dayOfTheMonth - 1)*24L*60L*60L*1000L;
|
---|
408 |
|
---|
409 | ms = yearDiff + monthDiff + dayDiff + (hour - bst)*60L*60L*1000L + min*60L*1000L + sec*1000L + millisec;
|
---|
410 | }
|
---|
411 | else{
|
---|
412 | // Date before the zero computer time
|
---|
413 | long yearDiff = 0L;
|
---|
414 | int yearTest = year + 1;
|
---|
415 | while(yearTest<1970){
|
---|
416 | yearDiff += 365;
|
---|
417 | if(this.leapYear(yearTest))yearDiff++;
|
---|
418 | yearTest++;
|
---|
419 | }
|
---|
420 | yearDiff *= 24L*60L*60L*1000L;
|
---|
421 |
|
---|
422 | long monthDiff = 0L;
|
---|
423 | int monthTest = month - 1;
|
---|
424 | while(monthTest>0){
|
---|
425 | monthDiff += monthDays[monthTest-1];
|
---|
426 | if(this.leapYear(year) && monthTest==2)monthDiff++;
|
---|
427 | monthTest--;
|
---|
428 | }
|
---|
429 |
|
---|
430 | monthDiff *= 24L*60L*60L*1000L;
|
---|
431 |
|
---|
432 | long dayDiff = (dayOfTheMonth - 1)*24L*60L*60L*1000L;
|
---|
433 |
|
---|
434 | monthDiff = monthDiff + dayDiff + (hour - bst)*60L*60L*1000L + min*60L*1000L + sec*1000L + millisec;
|
---|
435 |
|
---|
436 | long myear = 365L;
|
---|
437 | if(this.leapYear(year))myear++;
|
---|
438 | myear *= 24L*60L*60L*1000L;
|
---|
439 |
|
---|
440 | ms = myear - monthDiff;
|
---|
441 | ms += yearDiff;
|
---|
442 | ms = -ms;
|
---|
443 | }
|
---|
444 |
|
---|
445 | return ms;
|
---|
446 | }
|
---|
447 |
|
---|
448 | // Check whether within British summer time period
|
---|
449 | public boolean checkBST(){
|
---|
450 |
|
---|
451 | String dayOfTheWeek = this.getDayOfTheWeek();
|
---|
452 | int dayOfTheMonth = this.getDayOfTheMonth();
|
---|
453 | int hour = this.getMonthAsInteger();
|
---|
454 | int month = this.getMonthAsInteger();
|
---|
455 | int dayIndicator = this.getDayOfTheWeekAsInteger(dayOfTheWeek);
|
---|
456 |
|
---|
457 | return this.checkBST(dayOfTheWeek, dayOfTheMonth, hour, month, dayIndicator);
|
---|
458 | }
|
---|
459 |
|
---|
460 | // Check whether within British summer time period - private method for internal use
|
---|
461 | private boolean checkBST(String dayOfTheWeek, int dayOfTheMonth, int hour, int month, int dayIndicator){
|
---|
462 |
|
---|
463 | if(month>3 && month<10){
|
---|
464 | this.backForw = true;
|
---|
465 | }
|
---|
466 | else{
|
---|
467 | if(month==3 && dayOfTheMonth>24){
|
---|
468 | if(dayIndicator==0){
|
---|
469 | if(hour>=1)this.backForw = true;
|
---|
470 | }
|
---|
471 | else{
|
---|
472 | if(dayIndicator>0 && dayIndicator<dayOfTheMonth-24)this.backForw = true;
|
---|
473 | }
|
---|
474 | }
|
---|
475 | else{
|
---|
476 | if(month==10 && dayOfTheMonth>24){
|
---|
477 | if(dayIndicator==0){
|
---|
478 | if(hour<=2)this.backForw = true;
|
---|
479 | }
|
---|
480 | else{
|
---|
481 | this.backForw = true;
|
---|
482 | if(dayIndicator>0 && dayIndicator<dayOfTheMonth-24)this.backForw = false;
|
---|
483 | }
|
---|
484 | }
|
---|
485 | }
|
---|
486 | }
|
---|
487 |
|
---|
488 | return this.backForw;
|
---|
489 | }
|
---|
490 |
|
---|
491 | // Returns the day of the week as an integer (Sunday = 1, Monday = 1 etc)
|
---|
492 | public int getDayOfTheWeekAsInteger(){
|
---|
493 |
|
---|
494 | String dayOfTheWeek = this.getDayOfTheWeek();
|
---|
495 |
|
---|
496 | return this.getDayOfTheWeekAsInteger(dayOfTheWeek) + 1;
|
---|
497 | }
|
---|
498 |
|
---|
499 | // Returns the day of the week as an integer (Sunday = 0, Monday = 1 etc) - private method for internal use
|
---|
500 | private int getDayOfTheWeekAsInteger(String dayOfTheWeek){
|
---|
501 |
|
---|
502 |
|
---|
503 | // Day of the week as integer
|
---|
504 | int counter = 0;
|
---|
505 | int dayIndicator = 0;
|
---|
506 | boolean test = true;
|
---|
507 | while(test){
|
---|
508 | if(dayOfTheWeek.equals(days[counter])){
|
---|
509 | dayIndicator = counter;
|
---|
510 | test = false;
|
---|
511 | }
|
---|
512 | else{
|
---|
513 | counter++;
|
---|
514 | if(counter>6)throw new IllegalArgumentException(dayOfTheWeek + " is not recognised as a day of the week");
|
---|
515 | }
|
---|
516 | }
|
---|
517 |
|
---|
518 | return dayIndicator;
|
---|
519 | }
|
---|
520 |
|
---|
521 | // Calculates the next British Summer Time clock change for the current date
|
---|
522 | public String nextBstClockChange(){
|
---|
523 |
|
---|
524 | this.backForw = true; // = true change back, i.e if date is within bst; = false change = forward
|
---|
525 |
|
---|
526 | String dayOfTheWeek = this.getDayOfTheWeek();
|
---|
527 | int dayOfTheMonth = this.getDayOfTheMonth();
|
---|
528 | int hour = this.getMonthAsInteger();
|
---|
529 | int month = this.getMonthAsInteger();
|
---|
530 |
|
---|
531 | // Day of the week as integer
|
---|
532 | int dayIndicator = this.getDayOfTheWeekAsInteger(dayOfTheWeek);
|
---|
533 |
|
---|
534 | // Check whether within British summer time period
|
---|
535 | this.backForw = checkBST(dayOfTheWeek, dayOfTheMonth, hour, month, dayIndicator);
|
---|
536 |
|
---|
537 | // Find next Sunday to today's date
|
---|
538 | int daysDiff = 0;
|
---|
539 | int newDayOfTheMonth = dayOfTheMonth;
|
---|
540 | int newMonth = month;
|
---|
541 | int newYear = year;
|
---|
542 | int oldNewDayOfTheMonth = newDayOfTheMonth;
|
---|
543 | int oldMonth = newMonth;
|
---|
544 | int oldYear = newYear;
|
---|
545 | if(dayIndicator!=0)daysDiff = 7-dayIndicator;
|
---|
546 | newDayOfTheMonth = dayOfTheMonth + daysDiff;
|
---|
547 | int monthD = monthDays[newMonth-1];
|
---|
548 | if(newMonth==2 && this.leapYear(newYear))monthD++;
|
---|
549 | if(newDayOfTheMonth>monthD){
|
---|
550 | newDayOfTheMonth -= monthD;
|
---|
551 | newMonth++;
|
---|
552 | if(newMonth==13){
|
---|
553 | newMonth = 1;
|
---|
554 | newYear = oldYear + 1;
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 | if(!backForw){
|
---|
559 | boolean test = true;
|
---|
560 | while(test){
|
---|
561 | if(newMonth==3 && newDayOfTheMonth>24){
|
---|
562 | this.changeDate = "Sunday, " + newDayOfTheMonth + " March " + year + ", one hour forward";
|
---|
563 | test = false;
|
---|
564 | }
|
---|
565 | else{
|
---|
566 | newDayOfTheMonth += 7;
|
---|
567 | monthD = monthDays[newMonth-1];
|
---|
568 | if(newMonth==2 && this.leapYear(newYear))monthD++;
|
---|
569 | if(newDayOfTheMonth>monthD){
|
---|
570 | newDayOfTheMonth -= monthD;
|
---|
571 | newMonth++;
|
---|
572 | if(newMonth==13){
|
---|
573 | newMonth = 1;
|
---|
574 | newYear = newYear + 1;
|
---|
575 | }
|
---|
576 | }
|
---|
577 | }
|
---|
578 | }
|
---|
579 | }
|
---|
580 | else{
|
---|
581 | boolean test = true;
|
---|
582 | while(test){
|
---|
583 | if(newMonth==10 && newDayOfTheMonth>24){
|
---|
584 | this.changeDate = "Sunday, " + newDayOfTheMonth + " October " + year + ", one hour back";
|
---|
585 | test = false;
|
---|
586 | }
|
---|
587 | else{
|
---|
588 | newDayOfTheMonth += 7;
|
---|
589 | monthD = monthDays[newMonth-1];
|
---|
590 | if(newMonth==2 && this.leapYear(newYear))monthD++;
|
---|
591 | if(newDayOfTheMonth>monthD){
|
---|
592 | newDayOfTheMonth -= monthD;
|
---|
593 | newMonth++;
|
---|
594 | if(newMonth==13){
|
---|
595 | newMonth = 1;
|
---|
596 | newYear = newYear + 1;
|
---|
597 | }
|
---|
598 | }
|
---|
599 | }
|
---|
600 | }
|
---|
601 | }
|
---|
602 | return this.changeDate;
|
---|
603 | }
|
---|
604 |
|
---|
605 |
|
---|
606 | // Returns the the day of the week by name, e.g. Sunday
|
---|
607 | public String getDayOfTheWeek(){
|
---|
608 | int dayAsInt = cal.get(Calendar.DAY_OF_WEEK);
|
---|
609 | this.dayOfTheWeek = this.days[dayAsInt - 1];
|
---|
610 | return this.dayOfTheWeek;
|
---|
611 | }
|
---|
612 |
|
---|
613 | // Returns the the day of the month as integer, e.g. 24 for the 24th day of the month
|
---|
614 | public int getDayOfTheMonth(){
|
---|
615 | this.dayOfTheMonth = cal.get(Calendar.DAY_OF_MONTH);
|
---|
616 | return this.dayOfTheMonth;
|
---|
617 | }
|
---|
618 |
|
---|
619 | // Returns the the month by name, e.g. January
|
---|
620 | public String getMonth(){
|
---|
621 | int monthAsInt = cal.get(Calendar.MONTH);
|
---|
622 | this.monthOfTheYear = this.months[monthAsInt];
|
---|
623 | return this.monthOfTheYear;
|
---|
624 | }
|
---|
625 |
|
---|
626 | // Returns the month as an integer, e.g. January as 1
|
---|
627 | public int getMonthAsInteger(){
|
---|
628 | this.monthAsInteger = cal.get(Calendar.MONTH) + 1;
|
---|
629 | return this.monthAsInteger;
|
---|
630 | }
|
---|
631 |
|
---|
632 | // Returns the month as an integer, e.g. January as 1, private method for internal use
|
---|
633 | public int getMonthAsInteger(String month){
|
---|
634 | int monthI = 0;
|
---|
635 | boolean test = true;
|
---|
636 | int counter = 0;
|
---|
637 | while(test){
|
---|
638 | if(month.equals(this.months[counter])){
|
---|
639 | monthI = counter + 1;
|
---|
640 | test = false;
|
---|
641 | }
|
---|
642 | else{
|
---|
643 | counter++;
|
---|
644 | if(counter==12)throw new IllegalArgumentException(month + " is not recognised as a valid month name");
|
---|
645 | }
|
---|
646 | }
|
---|
647 | return monthI;
|
---|
648 | }
|
---|
649 |
|
---|
650 | // Returns the year as four digit number
|
---|
651 | public int getYear(){
|
---|
652 | this.year = cal.get(Calendar.YEAR);
|
---|
653 | return this.year;
|
---|
654 | }
|
---|
655 |
|
---|
656 | // Returns the date as 'day of month' 'month name' 'year'
|
---|
657 | public String getDate(){
|
---|
658 | this.date = (new Integer(this.getDayOfTheMonth())).toString();
|
---|
659 | this.date += " " + this.getMonth();
|
---|
660 | this.date += " " + this.getYear();
|
---|
661 | return this.date;
|
---|
662 | }
|
---|
663 |
|
---|
664 | // Returns the date as 'day name', 'day of month' 'month name' year
|
---|
665 | public String getFullDate(){
|
---|
666 | this.fullDate = this.getDayOfTheWeek();
|
---|
667 | this.fullDate += ", " + this.getDayOfTheMonth();
|
---|
668 | this.fullDate += " " + this.getMonth();
|
---|
669 | this.fullDate += " " + this.getYear();
|
---|
670 | return this.fullDate;
|
---|
671 | }
|
---|
672 |
|
---|
673 | // Returns the date as the UK short format - 'day of month'.'month number'.'year final two digits'
|
---|
674 | public String getShortDateUK(){
|
---|
675 | this.shortDateUK = (new Integer(this.getDayOfTheMonth())).toString();
|
---|
676 | if(this.shortDateUK.length()<2)this.shortDateUK = "0" + this.shortDateUK;
|
---|
677 | int monthI = this.getMonthAsInteger();
|
---|
678 | if(monthI<10){
|
---|
679 | this.shortDateUK += ".0" + monthI;
|
---|
680 | }
|
---|
681 | else{
|
---|
682 | this.shortDateUK += "." + monthI;
|
---|
683 | }
|
---|
684 | String yearS = (new Integer(this.getYear())).toString();
|
---|
685 | this.shortDateUK += "." + yearS.substring(2);
|
---|
686 | return this.shortDateUK;
|
---|
687 | }
|
---|
688 |
|
---|
689 | // Returns the date as the US short format - 'month number'/'day of month'/'year final two digits'
|
---|
690 | public String getShortDateUS(){
|
---|
691 | this.shortDateUS = (new Integer(this.getMonthAsInteger())).toString();
|
---|
692 | if(this.shortDateUS.length()<2)this.shortDateUS = "0" + this.shortDateUS;
|
---|
693 | int dayI = this.getDayOfTheMonth();
|
---|
694 | if(dayI<10){
|
---|
695 | this.shortDateUS += "/0" + dayI;
|
---|
696 | }
|
---|
697 | else{
|
---|
698 | this.shortDateUS += "/" + dayI;
|
---|
699 | }
|
---|
700 | String yearS = (new Integer(this.getYear())).toString();
|
---|
701 | this.shortDateUS+= "/" + yearS.substring(2);
|
---|
702 | return this.shortDateUS;
|
---|
703 | }
|
---|
704 |
|
---|
705 | // Returns true if entered date (xxxT) is later than the current date (xxx) otherwise returns false, private method for internal use
|
---|
706 | private boolean direction(int dayOfTheMonthT, int monthT, int yearT, int dayOfTheMonth, int month, int year){
|
---|
707 | boolean test = true;
|
---|
708 | boolean direction = false;
|
---|
709 | if(year>yearT){
|
---|
710 | direction = true;
|
---|
711 | }
|
---|
712 | else{
|
---|
713 | if(year<yearT){
|
---|
714 | direction = false;
|
---|
715 | }
|
---|
716 | else{
|
---|
717 | if(month>monthT){
|
---|
718 | direction = true;
|
---|
719 | }
|
---|
720 | else{
|
---|
721 | if(month<monthT){
|
---|
722 | direction = false;
|
---|
723 | }
|
---|
724 | else{
|
---|
725 | if(dayOfTheMonth>=dayOfTheMonthT){
|
---|
726 | direction = true;
|
---|
727 | }
|
---|
728 | else{
|
---|
729 | direction = false;
|
---|
730 | }
|
---|
731 | }
|
---|
732 | }
|
---|
733 | }
|
---|
734 | }
|
---|
735 | return direction;
|
---|
736 | }
|
---|
737 |
|
---|
738 | // Returns the day of the week for a given date - month as String, e.g. January
|
---|
739 | public String getDayOfDate(int dayOfTheMonth, String month, int year){
|
---|
740 | int monthI = this.getMonthAsInteger(month);
|
---|
741 | return getDayOfDate(dayOfTheMonth, monthI, year);
|
---|
742 | }
|
---|
743 |
|
---|
744 |
|
---|
745 | // Returns the day of the week for a given date - month as integer, January = 1
|
---|
746 | public String getDayOfDate(int dayOfTheMonth, int month, int year){
|
---|
747 |
|
---|
748 | String dayOfDate = null;
|
---|
749 | int yearT = this.getYear();
|
---|
750 | int monthT = this.getMonthAsInteger();
|
---|
751 | int dayOfTheMonthT = this.getDayOfTheMonth();
|
---|
752 | int dayI = this.getDayOfTheWeekAsInteger();
|
---|
753 | int febOrRest = 0;
|
---|
754 |
|
---|
755 |
|
---|
756 | boolean direction = direction(dayOfTheMonthT, monthT, yearT, dayOfTheMonth, month, year);
|
---|
757 |
|
---|
758 | if(direction){
|
---|
759 | boolean test = true;
|
---|
760 | while(test){
|
---|
761 | if(yearT==year && monthT==month && dayOfTheMonthT==dayOfTheMonth){
|
---|
762 | dayOfDate = days[dayI-1];
|
---|
763 | test = false;
|
---|
764 | }
|
---|
765 | else{
|
---|
766 | dayOfTheMonthT++;
|
---|
767 | febOrRest = this.monthDays[monthT-1];
|
---|
768 | if(this.leapYear(yearT) && monthT==2)febOrRest++;
|
---|
769 | if(dayOfTheMonthT>febOrRest){
|
---|
770 | dayOfTheMonthT -= febOrRest;
|
---|
771 | monthT++;
|
---|
772 | }
|
---|
773 | if(monthT==13){
|
---|
774 | monthT = 1;
|
---|
775 | yearT++;
|
---|
776 | }
|
---|
777 | dayI++;
|
---|
778 | if(dayI==8)dayI=1;
|
---|
779 | }
|
---|
780 | }
|
---|
781 | }
|
---|
782 | else{
|
---|
783 | boolean test = true;
|
---|
784 | while(test){
|
---|
785 | if(yearT==year && monthT==month && dayOfTheMonthT==dayOfTheMonth){
|
---|
786 | dayOfDate = days[dayI-1];
|
---|
787 | test = false;
|
---|
788 | }
|
---|
789 | else{
|
---|
790 | dayOfTheMonthT--;
|
---|
791 | int monthIndex = monthT - 2;
|
---|
792 | if(monthIndex<0)monthIndex = 11;
|
---|
793 | febOrRest = this.monthDays[monthIndex];
|
---|
794 | if(this.leapYear(yearT) && monthT==3)febOrRest++;
|
---|
795 | if(dayOfTheMonthT==0){
|
---|
796 | dayOfTheMonthT = febOrRest;
|
---|
797 | monthT--;
|
---|
798 | }
|
---|
799 | if(monthT==0){
|
---|
800 | monthT = 12;
|
---|
801 | yearT--;
|
---|
802 | }
|
---|
803 | dayI--;
|
---|
804 | if(dayI==0)dayI=7;
|
---|
805 | }
|
---|
806 | }
|
---|
807 | }
|
---|
808 |
|
---|
809 |
|
---|
810 | return dayOfDate;
|
---|
811 | }
|
---|
812 |
|
---|
813 | // Returns date of next Easter Sunday (1700 - 2299)
|
---|
814 | // Western Church - Gregorian calendar
|
---|
815 | // Uses the 'BBC algorithm' (http://www.bbc.co.uk/dna/h2g2/A653267) - checked only between 1700 and 2299
|
---|
816 | public String easterSunday(){
|
---|
817 | int year = this.getYear();
|
---|
818 | if(year>2299)System.out.println(year + " is outside the range for which this algorithm has been checked, 1700 - 2299");
|
---|
819 | int month = this.getMonthAsInteger();
|
---|
820 | int day = this.getDayOfTheMonth();
|
---|
821 |
|
---|
822 | int rem1 = year%19;
|
---|
823 | int quo1 = year/100;
|
---|
824 | int rem2 = year%100;
|
---|
825 | int quo2 = quo1/4;
|
---|
826 | int rem3 = quo1%4;
|
---|
827 | int quo3 = rem2/4;
|
---|
828 | int rem4 = rem2%4;
|
---|
829 |
|
---|
830 | int quo4 = (quo1 + 8)/25;
|
---|
831 | int quo5 = (quo1 - quo4 + 1)/3;
|
---|
832 | int rem5 = (19*rem1 + quo1 - quo2 - quo5 + 15)%30;
|
---|
833 | int rem6 = (32 + 2*rem3 + 2*quo3 - rem5 - rem4)%7;
|
---|
834 | int quo6 = (rem1 + 11*rem5 + 22*rem6)/451;
|
---|
835 | int sum1 = rem5 + rem6 - 7*quo6 + 114;
|
---|
836 |
|
---|
837 | this.easterMonth = sum1/31;
|
---|
838 | this.easterDay = (sum1%31) + 1;
|
---|
839 |
|
---|
840 | boolean direction = this.direction(day, month, year, this.easterDay, this.easterMonth, year);
|
---|
841 | if(direction){
|
---|
842 | this.dayHold = this.easterDay;
|
---|
843 | this.monthHold = this.easterMonth;
|
---|
844 | this.yearHold = year;
|
---|
845 | this.dayNameHold = "Sunday";
|
---|
846 | this.easterDayName = this.getDayOfDate(this.easterDay, this.easterMonth, year);
|
---|
847 | return this.easterDayName + ", " + this.easterDay + " " + months[this.easterMonth-1] + " " + year;
|
---|
848 | }
|
---|
849 | else{
|
---|
850 | return easterSunday(++year);
|
---|
851 | }
|
---|
852 | }
|
---|
853 |
|
---|
854 | // Returns date of the Easter Sunday (1700 - 2299)
|
---|
855 | // Western Church - Gregorian calendar
|
---|
856 | // Uses the 'BBC algorithm' (http://www.bbc.co.uk/dna/h2g2/A653267) - checked only between 1700 and 2299
|
---|
857 | public String easterSunday(int year){
|
---|
858 | if(year<1700 || year>2299)System.out.println(year + " is outside the range for which this algorithm has been checked, 1700 - 2299");
|
---|
859 |
|
---|
860 | int rem1 = year%19;
|
---|
861 | int quo1 = year/100;
|
---|
862 | int rem2 = year%100;
|
---|
863 | int quo2 = quo1/4;
|
---|
864 | int rem3 = quo1%4;
|
---|
865 | int quo3 = rem2/4;
|
---|
866 | int rem4 = rem2%4;
|
---|
867 |
|
---|
868 | int quo4 = (quo1 + 8)/25;
|
---|
869 | int quo5 = (quo1 - quo4 + 1)/3;
|
---|
870 | int rem5 = (19*rem1 + quo1 - quo2 - quo5 + 15)%30;
|
---|
871 | int rem6 = (32 + 2*rem3 + 2*quo3 - rem5 - rem4)%7;
|
---|
872 | int quo6 = (rem1 + 11*rem5 + 22*rem6)/451;
|
---|
873 | int sum1 = rem5 + rem6 - 7*quo6 + 114;
|
---|
874 |
|
---|
875 | this.easterMonth = sum1/31;
|
---|
876 | this.easterDay = (sum1%31) + 1;
|
---|
877 | this.dayHold = this.easterDay;
|
---|
878 | this.monthHold = this.easterMonth;
|
---|
879 | this.yearHold = year;
|
---|
880 | this.dayNameHold = "Sunday";
|
---|
881 |
|
---|
882 | this.easterDayName = this.getDayOfDate(this.easterDay, this.easterMonth, year);
|
---|
883 |
|
---|
884 | return this.easterDayName + ", " + this.easterDay + " " + months[this.easterMonth-1] + " " + year;
|
---|
885 |
|
---|
886 | }
|
---|
887 |
|
---|
888 | // Returns date of next Good Friday
|
---|
889 | // See easterDay() for limitations of the method
|
---|
890 | public String goodFriday(){
|
---|
891 | int year = this.getYear();
|
---|
892 | int month = this.getMonthAsInteger();
|
---|
893 | int day = this.getDayOfTheMonth();
|
---|
894 | this.easterSunday(year);
|
---|
895 | int monthGF = this.easterMonth;
|
---|
896 | int dayGF = this.easterDay - 2;
|
---|
897 | if(dayGF<1){
|
---|
898 | int dayCheck = monthDays[monthGF-2];
|
---|
899 | if(this.leapYear(year) && monthGF==3)dayCheck++;
|
---|
900 | dayGF = dayCheck + dayGF;
|
---|
901 | monthGF--;
|
---|
902 | }
|
---|
903 | boolean direction = this.direction(day, month, year, dayGF, monthGF, year);
|
---|
904 | if(!direction)year++;
|
---|
905 | return goodFriday(year);
|
---|
906 | }
|
---|
907 |
|
---|
908 | // Returns date of Good Friday for the entered year
|
---|
909 | // See easterDay() for limitations of the method
|
---|
910 | public String goodFriday(int year){
|
---|
911 | this.easterSunday(year);
|
---|
912 | int monthGF = this.easterMonth;
|
---|
913 | int dayGF = this.easterDay - 2;
|
---|
914 | if(dayGF<1){
|
---|
915 | int dayCheck = monthDays[monthGF-2];
|
---|
916 | if(this.leapYear(year) && monthGF==3)dayCheck++;
|
---|
917 | dayGF = dayCheck + dayGF;
|
---|
918 | monthGF--;
|
---|
919 | }
|
---|
920 | this.dayHold = dayGF;
|
---|
921 | this.monthHold = monthGF;
|
---|
922 | this.yearHold = year;
|
---|
923 | this.dayNameHold = "Friday";
|
---|
924 | return "Friday, " + dayGF + " " + months[monthGF-1] + " " + year;
|
---|
925 | }
|
---|
926 |
|
---|
927 | // Returns date of next Maundy Thursday
|
---|
928 | // See easterDay() for limitations of the method
|
---|
929 | public String maundyThursday(){
|
---|
930 | int year = this.getYear();
|
---|
931 | int month = this.getMonthAsInteger();
|
---|
932 | int day = this.getDayOfTheMonth();
|
---|
933 | this.maundyThursday(year);
|
---|
934 | int monthMT = this.monthHold;
|
---|
935 | int dayMT = this.dayHold;
|
---|
936 | boolean direction = this.direction(day, month, year, dayMT, monthMT, year);
|
---|
937 | if(!direction)year++;
|
---|
938 | return maundyThursday(year);
|
---|
939 | }
|
---|
940 |
|
---|
941 | // Returns date of Maundy Thursday for the entered year
|
---|
942 | // See easterDay() for limitations of the method
|
---|
943 | public String maundyThursday(int year){
|
---|
944 | this.goodFriday(year);
|
---|
945 | int monthMT = this.monthHold;
|
---|
946 | int dayMT = this.dayHold - 1;
|
---|
947 | if(dayMT<1){
|
---|
948 | int dayCheck = monthDays[monthMT-2];
|
---|
949 | if(this.leapYear(year) && monthMT==3)dayCheck++;
|
---|
950 | dayMT = dayCheck + dayMT;
|
---|
951 | monthMT--;
|
---|
952 | }
|
---|
953 | this.dayHold = dayMT;
|
---|
954 | this.monthHold = monthMT;
|
---|
955 | this.yearHold = year;
|
---|
956 | this.dayNameHold = "Friday";
|
---|
957 | return "Thursday, " + dayMT + " " + months[monthMT-1] + " " + year;
|
---|
958 | }
|
---|
959 |
|
---|
960 | // Returns date of next Ash Wednesday
|
---|
961 | // See easterDay() for limitations of the method
|
---|
962 | public String ashWednesday(){
|
---|
963 | int year = this.getYear();
|
---|
964 | int month = this.getMonthAsInteger();
|
---|
965 | int day = this.getDayOfTheMonth();
|
---|
966 | this.ashWednesday(year);
|
---|
967 | int monthAW = this.monthHold;
|
---|
968 | int dayAW = this.dayHold;
|
---|
969 | boolean direction = this.direction(day, month, year, dayAW, monthAW, year);
|
---|
970 | if(!direction)year++;
|
---|
971 | return ashWednesday(year);
|
---|
972 | }
|
---|
973 |
|
---|
974 | // Returns date of Ash Wednesday for the entered year
|
---|
975 | // See easterDay() for limitations of the method
|
---|
976 | public String ashWednesday(int year){
|
---|
977 | this.easterSunday(year);
|
---|
978 | int monthAW = this.easterMonth;
|
---|
979 | int dayAW = this.easterDay;
|
---|
980 | int counter = 1;
|
---|
981 | while(counter<=40){
|
---|
982 | dayAW --;
|
---|
983 | if(dayAW<1){
|
---|
984 | int dayCheck = monthDays[monthAW-2];
|
---|
985 | if(this.leapYear(year) && monthAW==3)dayCheck++;
|
---|
986 | dayAW = dayCheck + dayAW;
|
---|
987 | monthAW--;
|
---|
988 | }
|
---|
989 | if(this.getDayOfDate(dayAW, monthAW, year).equals("Sunday")){
|
---|
990 | // Sunday - day does not counts
|
---|
991 | }
|
---|
992 | else{
|
---|
993 | // Not a Sunday - day counts
|
---|
994 | counter++;
|
---|
995 | }
|
---|
996 | }
|
---|
997 | this.dayHold = dayAW;
|
---|
998 | this.monthHold = monthAW;
|
---|
999 | this.yearHold = year;
|
---|
1000 | this.dayNameHold = "Wednesday";
|
---|
1001 |
|
---|
1002 | return "Wednesday, " + dayAW + " " + months[monthAW-1] + " " + year;
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | // Returns date of next Shrove Tuesday
|
---|
1006 | // See easterDay() for limitations of the method
|
---|
1007 | public String shroveTuesday(){
|
---|
1008 | int year = this.getYear();
|
---|
1009 | int month = this.getMonthAsInteger();
|
---|
1010 | int day = this.getDayOfTheMonth();
|
---|
1011 | this.shroveTuesday(year);
|
---|
1012 | int monthST = this.monthHold;
|
---|
1013 | int dayST = this.dayHold;
|
---|
1014 | boolean direction = this.direction(day, month, year, dayST, monthST, year);
|
---|
1015 | if(!direction)year++;
|
---|
1016 | return shroveTuesday(year);
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | // Returns date of Shrove Tuesday for the entered year
|
---|
1020 | // See easterDay() for limitations of the method
|
---|
1021 | public String shroveTuesday(int year){
|
---|
1022 | this.ashWednesday(year);
|
---|
1023 | int monthST = this.monthHold;
|
---|
1024 | int dayST = this.dayHold - 1;
|
---|
1025 | if(dayST<1){
|
---|
1026 | int dayCheck = monthDays[monthST-2];
|
---|
1027 | if(this.leapYear(year) && monthST==3)dayCheck++;
|
---|
1028 | dayST = dayCheck + dayST;
|
---|
1029 | monthST--;
|
---|
1030 | }
|
---|
1031 | this.dayHold = dayST;
|
---|
1032 | this.monthHold = monthST;
|
---|
1033 | this.yearHold = year;
|
---|
1034 | this.dayNameHold = "Tuesday";
|
---|
1035 |
|
---|
1036 | return "Tuesday, " + dayST + " " + months[monthST-1] + " " + year;
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | // Returns date of next Palm Sunday
|
---|
1040 | // See easterDay() for limitations of the method
|
---|
1041 | public String palmSunday(){
|
---|
1042 | int year = this.getYear();
|
---|
1043 | int month = this.getMonthAsInteger();
|
---|
1044 | int day = this.getDayOfTheMonth();
|
---|
1045 | this.palmSunday(year);
|
---|
1046 | int monthPS = this.monthHold;
|
---|
1047 | int dayPS = this.dayHold;
|
---|
1048 | boolean direction = this.direction(day, month, year, dayPS, monthPS, year);
|
---|
1049 | if(!direction)year++;
|
---|
1050 | return palmSunday(year);
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | // Returns date of Palm Sunday for the entered year
|
---|
1054 | // See easterDay() for limitations of the method
|
---|
1055 | public String palmSunday(int year){
|
---|
1056 | this.easterSunday(year);
|
---|
1057 | int monthPS = this.easterMonth;
|
---|
1058 | int dayPS = this.easterDay - 7;
|
---|
1059 | if(dayPS<1){
|
---|
1060 | int dayCheck = monthDays[monthPS-2];
|
---|
1061 | if(this.leapYear(year) && monthPS==3)dayCheck++;
|
---|
1062 | dayPS = dayCheck + dayPS;
|
---|
1063 | monthPS--;
|
---|
1064 | }
|
---|
1065 | this.dayHold = dayPS;
|
---|
1066 | this.monthHold = monthPS;
|
---|
1067 | this.yearHold = year;
|
---|
1068 | this.dayNameHold = "Sunday";
|
---|
1069 |
|
---|
1070 | return "Sunday, " + dayPS + " " + months[monthPS-1] + " " + year;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | // Returns date of next Advent Sunday
|
---|
1074 | // See easterDay() for limitations of the method
|
---|
1075 | public String adventSunday(){
|
---|
1076 | int year = this.getYear();
|
---|
1077 | int month = this.getMonthAsInteger();
|
---|
1078 | int day = this.getDayOfTheMonth();
|
---|
1079 | this.adventSunday(year);
|
---|
1080 | int monthPS = this.monthHold;
|
---|
1081 | int dayPS = this.dayHold;
|
---|
1082 | boolean direction = this.direction(day, month, year, dayPS, monthPS, year);
|
---|
1083 | if(!direction)year++;
|
---|
1084 | return adventSunday(year);
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | // Returns date of Advent Sunday for the entered year
|
---|
1088 | // See easterDay() for limitations of the method
|
---|
1089 | public String adventSunday(int year){
|
---|
1090 | this.saintAndrewsDay(year);
|
---|
1091 | int monthAS = this.monthHold;
|
---|
1092 | int dayAS = this.dayHold;
|
---|
1093 | String dayNameAS = this.dayNameHold;
|
---|
1094 | int dayASI = this.getDayOfTheWeekAsInteger(dayNameAS);
|
---|
1095 | if(dayASI<4){
|
---|
1096 | dayAS -= dayASI;
|
---|
1097 | if(dayAS<1){
|
---|
1098 | int dayCheck = monthDays[monthAS-2];
|
---|
1099 | if(this.leapYear(year) && monthAS==3)dayCheck++;
|
---|
1100 | dayAS = dayCheck + dayAS;
|
---|
1101 | monthAS--;
|
---|
1102 | }
|
---|
1103 | }
|
---|
1104 | else{
|
---|
1105 | dayAS += (7 - dayASI);
|
---|
1106 | int dayCheck = monthDays[monthAS-1];
|
---|
1107 | if(this.leapYear(year) && monthAS==2)dayCheck++;
|
---|
1108 | if(dayAS>dayCheck){
|
---|
1109 | dayAS = dayAS - dayCheck;
|
---|
1110 | monthAS++;
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | this.dayHold = dayAS;
|
---|
1115 | this.monthHold = monthAS;
|
---|
1116 | this.yearHold = year;
|
---|
1117 | this.dayNameHold = "Sunday";
|
---|
1118 |
|
---|
1119 | return "Sunday, " + dayAS + " " + months[monthAS-1] + " " + year;
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 |
|
---|
1123 | // Returns date of next Trinity Sunday
|
---|
1124 | // See easterDay() for limitations of the method
|
---|
1125 | public String trinitySunday(){
|
---|
1126 | int year = this.getYear();
|
---|
1127 | int month = this.getMonthAsInteger();
|
---|
1128 | int day = this.getDayOfTheMonth();
|
---|
1129 | this.trinitySunday(year);
|
---|
1130 | int monthTS = this.monthHold;
|
---|
1131 | int dayTS = this.dayHold;
|
---|
1132 | boolean direction = this.direction(day, month, year, dayTS, monthTS, year);
|
---|
1133 | if(!direction)year++;
|
---|
1134 | return trinitySunday(year);
|
---|
1135 | }
|
---|
1136 |
|
---|
1137 | // Returns date of Trinity Sunday for the entered year
|
---|
1138 | // See easterDay() for limitations of the method
|
---|
1139 | public String trinitySunday(int year){
|
---|
1140 | this.whitSunday(year);
|
---|
1141 | int monthTS = this.monthHold;
|
---|
1142 | int dayTS = this.dayHold + 7;
|
---|
1143 | int dayCheck = monthDays[monthTS-1];
|
---|
1144 | if(this.leapYear(year) && monthTS==2)dayCheck++;
|
---|
1145 | if(dayTS>dayCheck){
|
---|
1146 | dayTS = dayTS - dayCheck;
|
---|
1147 | monthTS++;
|
---|
1148 | }
|
---|
1149 | this.dayHold = dayTS;
|
---|
1150 | this.monthHold = monthTS;
|
---|
1151 | this.yearHold = year;
|
---|
1152 | this.dayNameHold = "Sunday";
|
---|
1153 |
|
---|
1154 | return "Sunday, " + dayTS + " " + months[monthTS-1] + " " + year;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | // Returns date of next Corpus Christi
|
---|
1158 | // See easterDay() for limitations of the method
|
---|
1159 | public String corpusChristi(){
|
---|
1160 | int year = this.getYear();
|
---|
1161 | int month = this.getMonthAsInteger();
|
---|
1162 | int day = this.getDayOfTheMonth();
|
---|
1163 | this.corpusChristi(year);
|
---|
1164 | int monthTS = this.monthHold;
|
---|
1165 | int dayTS = this.dayHold;
|
---|
1166 | boolean direction = this.direction(day, month, year, dayTS, monthTS, year);
|
---|
1167 | if(!direction)year++;
|
---|
1168 | return corpusChristi(year);
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | // Returns date of Corpus Christi for the entered year
|
---|
1172 | // See easterDay() for limitations of the method
|
---|
1173 | public String corpusChristi(int year){
|
---|
1174 | this.trinitySunday(year);
|
---|
1175 | int monthTS = this.monthHold;
|
---|
1176 | int dayTS = this.dayHold + 4;
|
---|
1177 | int dayCheck = monthDays[monthTS-1];
|
---|
1178 | if(this.leapYear(year) && monthTS==2)dayCheck++;
|
---|
1179 | if(dayTS>dayCheck){
|
---|
1180 | dayTS = dayTS - dayCheck;
|
---|
1181 | monthTS++;
|
---|
1182 | }
|
---|
1183 | this.dayHold = dayTS;
|
---|
1184 | this.monthHold = monthTS;
|
---|
1185 | this.yearHold = year;
|
---|
1186 | this.dayNameHold = "Thursday";
|
---|
1187 |
|
---|
1188 | return "Thursday, " + dayTS + " " + months[monthTS-1] + " " + year;
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | // Returns date of next Sunday after Corpus Christi
|
---|
1192 | // See easterDay() for limitations of the method
|
---|
1193 | public String sundayAfterCorpusChristi(){
|
---|
1194 | int year = this.getYear();
|
---|
1195 | int month = this.getMonthAsInteger();
|
---|
1196 | int day = this.getDayOfTheMonth();
|
---|
1197 | this.sundayAfterCorpusChristi(year);
|
---|
1198 | int monthTS = this.monthHold;
|
---|
1199 | int dayTS = this.dayHold;
|
---|
1200 | boolean direction = this.direction(day, month, year, dayTS, monthTS, year);
|
---|
1201 | if(!direction)year++;
|
---|
1202 | return sundayAfterCorpusChristi(year);
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | // Returns date of Sunday after Corpus Christi for the entered year
|
---|
1206 | // See easterDay() for limitations of the method
|
---|
1207 | public String sundayAfterCorpusChristi(int year){
|
---|
1208 | this.corpusChristi(year);
|
---|
1209 | int monthTS = this.monthHold;
|
---|
1210 | int dayTS = this.dayHold + 3;
|
---|
1211 | int dayCheck = monthDays[monthTS-1];
|
---|
1212 | if(this.leapYear(year) && monthTS==2)dayCheck++;
|
---|
1213 | if(dayTS>dayCheck){
|
---|
1214 | dayTS = dayTS - dayCheck;
|
---|
1215 | monthTS++;
|
---|
1216 | }
|
---|
1217 | this.dayHold = dayTS;
|
---|
1218 | this.monthHold = monthTS;
|
---|
1219 | this.yearHold = year;
|
---|
1220 | this.dayNameHold = "Sunday";
|
---|
1221 |
|
---|
1222 | return "Sunday, " + dayTS + " " + months[monthTS-1] + " " + year;
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | // Returns date of next Ascension Thursday
|
---|
1226 | // See easterDay() for limitations of the method
|
---|
1227 | public String ascensionThursday(){
|
---|
1228 | int year = this.getYear();
|
---|
1229 | int month = this.getMonthAsInteger();
|
---|
1230 | int day = this.getDayOfTheMonth();
|
---|
1231 | this.ascensionThursday(year);
|
---|
1232 | int monthAT = this.monthHold;
|
---|
1233 | int dayAT = this.dayHold;
|
---|
1234 | boolean direction = this.direction(day, month, year, dayAT, monthAT, year);
|
---|
1235 | if(!direction)year++;
|
---|
1236 | return ascensionThursday(year);
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | // Returns date of Ascension Thursday for the entered year
|
---|
1240 | // See easterDay() for limitations of the method
|
---|
1241 | public String ascensionThursday(int year){
|
---|
1242 | this.easterSunday(year);
|
---|
1243 | int monthAT = this.easterMonth;
|
---|
1244 | int dayAT = this.easterDay + 39;
|
---|
1245 | int dayCheck1 = monthDays[monthAT-1];
|
---|
1246 | if(this.leapYear(year) && monthAT==2)dayCheck1++;
|
---|
1247 | int dayCheck2 = monthDays[monthAT];
|
---|
1248 | if(this.leapYear(year) && monthAT==1)dayCheck2++;
|
---|
1249 | if(dayAT>(dayCheck1 + dayCheck2)){
|
---|
1250 | dayAT = dayAT - (dayCheck1 + dayCheck2);
|
---|
1251 | monthAT += 2;
|
---|
1252 | }
|
---|
1253 | else{
|
---|
1254 | if(dayAT>dayCheck1){
|
---|
1255 | dayAT = dayAT - dayCheck1;
|
---|
1256 | monthAT += 1;
|
---|
1257 | }
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | this.dayHold = dayAT;
|
---|
1261 | this.monthHold = monthAT;
|
---|
1262 | this.yearHold = year;
|
---|
1263 | this.dayNameHold = "Thursday";
|
---|
1264 |
|
---|
1265 | return "Thursday, " + dayAT + " " + months[monthAT-1] + " " + year;
|
---|
1266 | }
|
---|
1267 |
|
---|
1268 | // Returns date of next Sunday after Ascension Thursday
|
---|
1269 | // See easterDay() for limitations of the method
|
---|
1270 | public String sundayAfterAscension(){
|
---|
1271 | int year = this.getYear();
|
---|
1272 | int month = this.getMonthAsInteger();
|
---|
1273 | int day = this.getDayOfTheMonth();
|
---|
1274 | this.sundayAfterAscension(year);
|
---|
1275 | int monthAT = this.monthHold;
|
---|
1276 | int dayAT = this.dayHold;
|
---|
1277 | boolean direction = this.direction(day, month, year, dayAT, monthAT, year);
|
---|
1278 | if(!direction)year++;
|
---|
1279 | return sundayAfterAscension(year);
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | // Returns date of Sunday after Ascension Thursday for the entered year
|
---|
1283 | // See easterDay() for limitations of the method
|
---|
1284 | public String sundayAfterAscension(int year){
|
---|
1285 | this.ascensionThursday(year);
|
---|
1286 | int monthAT = this.monthHold;
|
---|
1287 | int dayAT = this.dayHold + 3;
|
---|
1288 | int dayCheck1 = monthDays[monthAT-1];
|
---|
1289 | if(this.leapYear(year) && monthAT==2)dayCheck1++;
|
---|
1290 | if(dayAT>dayCheck1){
|
---|
1291 | dayAT = dayAT - dayCheck1;
|
---|
1292 | monthAT += 1;
|
---|
1293 | }
|
---|
1294 |
|
---|
1295 | this.dayHold = dayAT;
|
---|
1296 | this.monthHold = monthAT;
|
---|
1297 | this.yearHold = year;
|
---|
1298 | this.dayNameHold = "Sunday";
|
---|
1299 |
|
---|
1300 | return "Sunday, " + dayAT + " " + months[monthAT-1] + " " + year;
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | // Returns date of next Whit Sunday (Pentecost)
|
---|
1304 | // See easterDay() for limitations of the method
|
---|
1305 | public String whitSunday(){
|
---|
1306 | int year = this.getYear();
|
---|
1307 | int month = this.getMonthAsInteger();
|
---|
1308 | int day = this.getDayOfTheMonth();
|
---|
1309 | this.whitSunday(year);
|
---|
1310 | int monthWS = this.monthHold;
|
---|
1311 | int dayWS = this.dayHold;
|
---|
1312 | boolean direction = this.direction(day, month, year, dayWS, monthWS, year);
|
---|
1313 | if(!direction)year++;
|
---|
1314 | return whitSunday(year);
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | // Returns date of Whit Sunday (Pentecost)for the entered year
|
---|
1318 | // See easterDay() for limitations of the method
|
---|
1319 | public String whitSunday(int year){
|
---|
1320 | this.easterSunday(year);
|
---|
1321 | int dayWS = this.easterDay + 49;
|
---|
1322 | int monthWS = this.easterMonth;
|
---|
1323 | int dayCheck1 = monthDays[monthWS-1];
|
---|
1324 | if(this.leapYear(year) && monthWS==2)dayCheck1++;
|
---|
1325 | int dayCheck2 = monthDays[monthWS];
|
---|
1326 | if(this.leapYear(year) && monthWS==1)dayCheck2++;
|
---|
1327 |
|
---|
1328 | if(dayWS>(dayCheck1+dayCheck2)){
|
---|
1329 | dayWS -= (dayCheck1 + dayCheck2) ;
|
---|
1330 | monthWS += 2;
|
---|
1331 | }
|
---|
1332 | else{
|
---|
1333 | if(dayWS>dayCheck1){
|
---|
1334 | dayWS -= dayCheck1 ;
|
---|
1335 | monthWS += 1;
|
---|
1336 | }
|
---|
1337 | }
|
---|
1338 | this.dayHold = dayWS;
|
---|
1339 | this.monthHold = monthWS;
|
---|
1340 | this.yearHold = year;
|
---|
1341 | this.dayNameHold = "Sunday";
|
---|
1342 |
|
---|
1343 | return "Sunday, " + dayWS + " " + months[this.monthHold-1] + " " + year;
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | // Returns date of next Mother's Day (Mothering Sunday) in the UK
|
---|
1347 | // See easterDay() for limitations of the method
|
---|
1348 | public String mothersDayUK(){
|
---|
1349 | int year = this.getYear();
|
---|
1350 | int month = this.getMonthAsInteger();
|
---|
1351 | int day = this.getDayOfTheMonth();
|
---|
1352 | this.mothersDayUK(year);
|
---|
1353 | int monthMS = this.monthHold;
|
---|
1354 | int dayMS = this.dayHold;
|
---|
1355 | boolean direction = this.direction(day, month, year, dayMS, monthMS, year);
|
---|
1356 | if(!direction)year++;
|
---|
1357 | return mothersDayUK(year);
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | // Returns date of Mother's Day (Mothering Sunday) in the UK for the entered year
|
---|
1361 | // See easterDay() for limitations of the method
|
---|
1362 | public String mothersDayUK(int year){
|
---|
1363 | this.ashWednesday(year);
|
---|
1364 | int dayMS = this.dayHold + 25;
|
---|
1365 | int monthMS = this.monthHold;
|
---|
1366 | int dayCheck = monthDays[monthMS-1];
|
---|
1367 | if(this.leapYear(year) && monthMS==2)dayCheck++;
|
---|
1368 | if(dayMS>dayCheck){
|
---|
1369 | dayMS -= dayCheck;
|
---|
1370 | monthMS++;
|
---|
1371 | }
|
---|
1372 | this.dayHold = dayMS;
|
---|
1373 | this.monthHold = monthMS;
|
---|
1374 | this.yearHold = year;
|
---|
1375 | this.dayNameHold = "Sunday";
|
---|
1376 |
|
---|
1377 | return "Sunday, " + dayMS + " " + months[this.monthHold-1] + " " + year;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | // Returns date of next Mothers Day in the US
|
---|
1381 | public String mothersDayUS(){
|
---|
1382 | int year = this.getYear();
|
---|
1383 | int month = this.getMonthAsInteger();
|
---|
1384 | int day = this.getDayOfTheMonth();
|
---|
1385 | this.mothersDayUS(year);
|
---|
1386 | boolean direction = this.direction(day, month, year, this.dayHold, this.monthHold, year);
|
---|
1387 | if(!direction)year++;
|
---|
1388 | return mothersDayUS(year);
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | // Returns date of Mother's Day (Mothering Sunday) in the US for the entered year
|
---|
1392 | public String mothersDayUS(int year){
|
---|
1393 | String dayMSN = this.getDayOfDate(1, "May", year);
|
---|
1394 | int monthMS = 5;
|
---|
1395 | int dayOwI = this.getDayOfTheWeekAsInteger(dayMSN) + 1;
|
---|
1396 | int dayMS = 0;
|
---|
1397 | if(dayOwI==1){
|
---|
1398 | dayMS = dayOwI + 7;
|
---|
1399 | }
|
---|
1400 | else{
|
---|
1401 | dayMS = 16 - dayOwI;
|
---|
1402 | }
|
---|
1403 | this.dayHold = dayMS;
|
---|
1404 | this.monthHold = monthMS;
|
---|
1405 | this.yearHold = year;
|
---|
1406 | this.dayNameHold = "Sunday";
|
---|
1407 |
|
---|
1408 | return "Sunday, " + dayMS + " May " + year;
|
---|
1409 | }
|
---|
1410 |
|
---|
1411 | // Returns date of next Father's Day
|
---|
1412 | public String fathersDay(){
|
---|
1413 | int year = this.getYear();
|
---|
1414 | int month = this.getMonthAsInteger();
|
---|
1415 | int day = this.getDayOfTheMonth();
|
---|
1416 | this.fathersDay(year);
|
---|
1417 | boolean direction = this.direction(day, month, year, this.dayHold, this.monthHold, year);
|
---|
1418 | if(!direction)year++;
|
---|
1419 | return fathersDay(year);
|
---|
1420 | }
|
---|
1421 |
|
---|
1422 | // Returns date of Father's Day for the entered year
|
---|
1423 | public String fathersDay(int year){
|
---|
1424 | String dayMSN = this.getDayOfDate(1, "June", year);
|
---|
1425 | int monthFD = 6;
|
---|
1426 | int dayOwI = this.getDayOfTheWeekAsInteger(dayMSN) + 1;
|
---|
1427 | int dayFD = 0;
|
---|
1428 | if(dayOwI==1){
|
---|
1429 | dayFD = dayOwI + 14;
|
---|
1430 | }
|
---|
1431 | else{
|
---|
1432 | dayFD = 23 - dayOwI;
|
---|
1433 | }
|
---|
1434 | this.dayHold = dayFD;
|
---|
1435 | this.monthHold = monthFD;
|
---|
1436 | this.yearHold = year;
|
---|
1437 | this.dayNameHold = "Sunday";
|
---|
1438 |
|
---|
1439 | return "Sunday, " + dayFD + " June " + year;
|
---|
1440 | }
|
---|
1441 |
|
---|
1442 | // Returns date of next Christmas Day
|
---|
1443 | public String christmasDay(){
|
---|
1444 | int year = this.getYear();
|
---|
1445 | int month = this.getMonthAsInteger();
|
---|
1446 | int day = this.getDayOfTheMonth();
|
---|
1447 | boolean direction = this.direction(day, month, year, 25, 12, year);
|
---|
1448 | if(!direction)year++;
|
---|
1449 | return christmasDay(year);
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | // Returns date of Christmas Day for the entered year
|
---|
1453 | public String christmasDay(int year){
|
---|
1454 | String day = this.getDayOfDate(25, 12, year);
|
---|
1455 | this.dayHold = 25;
|
---|
1456 | this.monthHold = 12;
|
---|
1457 | this.yearHold = year;
|
---|
1458 | this.dayNameHold = day;
|
---|
1459 | return day + ", 25 December " + year;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | // Returns date of next New Year's Day
|
---|
1463 | public String newYearsDay(){
|
---|
1464 | int year = this.getYear();
|
---|
1465 | int month = this.getMonthAsInteger();
|
---|
1466 | int day = this.getDayOfTheMonth();
|
---|
1467 | boolean direction = this.direction(day, month, year, 1, 1, year);
|
---|
1468 | if(!direction)year++;
|
---|
1469 | return newYearsDay(year);
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | // Returns date of New Year's Day for the entered year
|
---|
1473 | public String newYearsDay(int year){
|
---|
1474 | String day = this.getDayOfDate(1, 1, year);
|
---|
1475 | this.dayHold = 1;
|
---|
1476 | this.monthHold = 1;
|
---|
1477 | this.yearHold = year;
|
---|
1478 | this.dayNameHold = day;
|
---|
1479 | return day + ", 1 January " + year;
|
---|
1480 | }
|
---|
1481 |
|
---|
1482 | // Returns date of next Epiphany day
|
---|
1483 | public String epiphany(){
|
---|
1484 | int year = this.getYear();
|
---|
1485 | int month = this.getMonthAsInteger();
|
---|
1486 | int day = this.getDayOfTheMonth();
|
---|
1487 | boolean direction = this.direction(day, month, year, 6, 1, year);
|
---|
1488 | if(!direction)year++;
|
---|
1489 | return epiphany(year);
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | // Returns date of Epiphany day for the entered year
|
---|
1493 | public String epiphany(int year){
|
---|
1494 | String day = this.getDayOfDate(6, 1, year);
|
---|
1495 | this.dayHold = 6;
|
---|
1496 | this.monthHold = 1;
|
---|
1497 | this.yearHold = year;
|
---|
1498 | this.dayNameHold = day;
|
---|
1499 | return day + ", 6 January " + year;
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | // Returns date of next Sunday after Epiphany day
|
---|
1503 | public String sundayAfterEpiphany(){
|
---|
1504 | int year = this.getYear();
|
---|
1505 | int month = this.getMonthAsInteger();
|
---|
1506 | int day = this.getDayOfTheMonth();
|
---|
1507 | String dayName = this.getDayOfDate(6, 1, year);
|
---|
1508 | int dayI = this.getDayOfTheWeekAsInteger(dayName);
|
---|
1509 | int day6plus = 6;
|
---|
1510 | if(dayI>0)day6plus += (7 - dayI);
|
---|
1511 | boolean direction = this.direction(day, month, year, day6plus, 1, year);
|
---|
1512 | if(!direction)year++;
|
---|
1513 | return sundayAfterEpiphany(year);
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | // Returns date of Sunday after Epiphany day for the entered year
|
---|
1517 | public String sundayAfterEpiphany(int year){
|
---|
1518 | String dayName = this.getDayOfDate(6, 1, year);
|
---|
1519 | int dayI = this.getDayOfTheWeekAsInteger(dayName);
|
---|
1520 | int day6plus = 6;
|
---|
1521 | if(dayI>0)day6plus += (7 - dayI);
|
---|
1522 | this.dayHold = day6plus;
|
---|
1523 | this.monthHold = 1;
|
---|
1524 | this.yearHold = year;
|
---|
1525 | this.dayNameHold = "Sunday";
|
---|
1526 |
|
---|
1527 | return "Sunday, " + day6plus + " January " + year;
|
---|
1528 | }
|
---|
1529 |
|
---|
1530 | // Returns date of the next Feast of the Annunciation
|
---|
1531 | public String annunciation(){
|
---|
1532 | int year = this.getYear();
|
---|
1533 | int month = this.getMonthAsInteger();
|
---|
1534 | int day = this.getDayOfTheMonth();
|
---|
1535 | boolean direction = this.direction(day, month, year, 25, 3, year);
|
---|
1536 | if(!direction)year++;
|
---|
1537 | return annunciation(year);
|
---|
1538 | }
|
---|
1539 | // Returns date of the Feast of the Annunciation for the entered year
|
---|
1540 | public String annunciation(int year){
|
---|
1541 | String day = this.getDayOfDate(25, 3, year);
|
---|
1542 | this.dayHold = 25;
|
---|
1543 | this.monthHold = 3;
|
---|
1544 | this.yearHold = year;
|
---|
1545 | this.dayNameHold = day;
|
---|
1546 | return day + ", 25 March " + year;
|
---|
1547 | }
|
---|
1548 |
|
---|
1549 | // Returns date of the next Feast of the Assumption
|
---|
1550 | public String assumption(){
|
---|
1551 | int year = this.getYear();
|
---|
1552 | int month = this.getMonthAsInteger();
|
---|
1553 | int day = this.getDayOfTheMonth();
|
---|
1554 | boolean direction = this.direction(day, month, year, 15, 8, year);
|
---|
1555 | if(!direction)year++;
|
---|
1556 | return assumption(year);
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | // Returns date of the Feast of the Assumption for the entered year
|
---|
1560 | public String assumption(int year){
|
---|
1561 | String day = this.getDayOfDate(15, 8, year);
|
---|
1562 | this.dayHold = 15;
|
---|
1563 | this.monthHold = 8;
|
---|
1564 | this.yearHold = year;
|
---|
1565 | this.dayNameHold = day;
|
---|
1566 | return day + ", 15 August " + year;
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | // Returns date of the next Feast of the Nativity of the Blessed Virgin
|
---|
1570 | public String nativityBlessedVirgin(){
|
---|
1571 | int year = this.getYear();
|
---|
1572 | int month = this.getMonthAsInteger();
|
---|
1573 | int day = this.getDayOfTheMonth();
|
---|
1574 | boolean direction = this.direction(day, month, year, 8, 9, year);
|
---|
1575 | if(!direction)year++;
|
---|
1576 | return nativityBlessedVirgin(year);
|
---|
1577 | }
|
---|
1578 |
|
---|
1579 | // Returns date of the Feast of the Nativity of the Blessed Virgin for the entered year
|
---|
1580 | public String nativityBlessedVirgin(int year){
|
---|
1581 | String day = this.getDayOfDate(8, 9, year);
|
---|
1582 | this.dayHold = 8;
|
---|
1583 | this.monthHold = 9;
|
---|
1584 | this.yearHold = year;
|
---|
1585 | this.dayNameHold = day;
|
---|
1586 | return day + ", 8 September " + year;
|
---|
1587 | }
|
---|
1588 |
|
---|
1589 | // Returns date of the next Feast of the Immaculate Conception
|
---|
1590 | public String immaculateConception(){
|
---|
1591 | int year = this.getYear();
|
---|
1592 | int month = this.getMonthAsInteger();
|
---|
1593 | int day = this.getDayOfTheMonth();
|
---|
1594 | boolean direction = this.direction(day, month, year, 8, 12, year);
|
---|
1595 | if(!direction)year++;
|
---|
1596 | return immaculateConception(year);
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | // Returns date of the Feast of the Immaculate Conception for the entered year
|
---|
1600 | public String immaculateConception(int year){
|
---|
1601 | String day = this.getDayOfDate(8, 12, year);
|
---|
1602 | this.dayHold = 8;
|
---|
1603 | this.monthHold = 12;
|
---|
1604 | this.yearHold = year;
|
---|
1605 | this.dayNameHold = day;
|
---|
1606 | return day + ", 8 December " + year;
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | // Returns date of the next Feast of the Purification of the Virgin
|
---|
1610 | // [Candlemas, Feast of the Presentation of Jesus at the Temple]
|
---|
1611 | public String purification(){
|
---|
1612 | int year = this.getYear();
|
---|
1613 | int month = this.getMonthAsInteger();
|
---|
1614 | int day = this.getDayOfTheMonth();
|
---|
1615 | boolean direction = this.direction(day, month, year, 2, 2, year);
|
---|
1616 | if(!direction)year++;
|
---|
1617 | return purification(year);
|
---|
1618 | }
|
---|
1619 |
|
---|
1620 | public String presentation(){
|
---|
1621 | return this.purification();
|
---|
1622 | }
|
---|
1623 |
|
---|
1624 | public String candlemas(){
|
---|
1625 | return this.purification();
|
---|
1626 | }
|
---|
1627 |
|
---|
1628 | // Returns date of the next Feast of the Purification of the Virgin
|
---|
1629 | // [Candlemas, Feast of the Presentation of Jesus at the temple]
|
---|
1630 | public String purification(int year){
|
---|
1631 | String day = this.getDayOfDate(2, 2, year);
|
---|
1632 | this.dayHold = 2;
|
---|
1633 | this.monthHold = 2;
|
---|
1634 | this.yearHold = year;
|
---|
1635 | this.dayNameHold = day;
|
---|
1636 | return day + ", 2 February " + year;
|
---|
1637 | }
|
---|
1638 |
|
---|
1639 | public String presentation(int year){
|
---|
1640 | return this.purification(year);
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | public String candlemas(int year){
|
---|
1644 | return this.purification(year);
|
---|
1645 | }
|
---|
1646 |
|
---|
1647 | // Returns date of the next Feast of the Transfiguration of Christ
|
---|
1648 | public String transfiguration(){
|
---|
1649 | int year = this.getYear();
|
---|
1650 | int month = this.getMonthAsInteger();
|
---|
1651 | int day = this.getDayOfTheMonth();
|
---|
1652 | boolean direction = this.direction(day, month, year, 6, 8, year);
|
---|
1653 | if(!direction)year++;
|
---|
1654 | return transfiguration(year);
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | // Returns date of the Feast of the Transfiguration of Christ for the entered year
|
---|
1658 | public String transfiguration(int year){
|
---|
1659 | String day = this.getDayOfDate(6, 8, year);
|
---|
1660 | this.dayHold = 6;
|
---|
1661 | this.monthHold = 8;
|
---|
1662 | this.yearHold = year;
|
---|
1663 | this.dayNameHold = day;
|
---|
1664 | return day + ", 6 August " + year;
|
---|
1665 | }
|
---|
1666 |
|
---|
1667 | // Returns date of next Remembrance Sunday
|
---|
1668 | public String remembranceSunday(){
|
---|
1669 | int year = this.getYear();
|
---|
1670 | int month = this.getMonthAsInteger();
|
---|
1671 | int day = this.getDayOfTheMonth();
|
---|
1672 | this.remembranceSunday(year);
|
---|
1673 | int monthRS = this.monthHold;
|
---|
1674 | int dayRS = this.dayHold;
|
---|
1675 | boolean direction = this.direction(day, month, year, dayRS, monthRS, year);
|
---|
1676 | if(!direction)year++;
|
---|
1677 | return remembranceSunday(year);
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | // Returns date of Remembrance Sunday for the entered year
|
---|
1681 | public String remembranceSunday(int year){
|
---|
1682 | int monthRS = 11;
|
---|
1683 | int dayRS = 11;
|
---|
1684 | String dayNameRS = this.getDayOfDate(11, 11, year);
|
---|
1685 | int dayRSI = this.getDayOfTheWeekAsInteger(dayNameRS);
|
---|
1686 | if(dayRSI<4){
|
---|
1687 | dayRS -= dayRSI;
|
---|
1688 | if(dayRS<1){
|
---|
1689 | int dayCheck = monthDays[monthRS-2];
|
---|
1690 | if(this.leapYear(year) && monthRS==3)dayCheck++;
|
---|
1691 | dayRS = dayCheck + dayRS;
|
---|
1692 | monthRS--;
|
---|
1693 | }
|
---|
1694 | }
|
---|
1695 | else{
|
---|
1696 | dayRS += (7 - dayRSI);
|
---|
1697 | int dayCheck = monthDays[monthRS-1];
|
---|
1698 | if(this.leapYear(year) && monthRS==2)dayCheck++;
|
---|
1699 | if(dayRS>dayCheck){
|
---|
1700 | dayRS = dayRS - dayCheck;
|
---|
1701 | monthRS++;
|
---|
1702 | }
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | this.dayHold = dayRS;
|
---|
1706 | this.monthHold = monthRS;
|
---|
1707 | this.yearHold = year;
|
---|
1708 | this.dayNameHold = "Sunday";
|
---|
1709 |
|
---|
1710 | return "Sunday, " + dayRS + " " + months[monthRS-1] + " " + year;
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 |
|
---|
1714 | // Returns date of next Holocaust Memorial Day
|
---|
1715 | public String holocaustMemorialDay(){
|
---|
1716 | int year = this.getYear();
|
---|
1717 | int month = this.getMonthAsInteger();
|
---|
1718 | int day = this.getDayOfTheMonth();
|
---|
1719 | boolean direction = this.direction(day, month, year, 27, 1, year);
|
---|
1720 | if(!direction)year++;
|
---|
1721 | return holocaustMemorialDay(year);
|
---|
1722 | }
|
---|
1723 |
|
---|
1724 | // Returns date of Holocaust Memorial Day for the entered year
|
---|
1725 | public String holocaustMemorialDay(int year){
|
---|
1726 | String day = this.getDayOfDate(27, 1, year);
|
---|
1727 | this.dayHold = 25;
|
---|
1728 | this.monthHold = 12;
|
---|
1729 | this.yearHold = year;
|
---|
1730 | this.dayNameHold = day;
|
---|
1731 | return day + ", 27 January " + year;
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | // Returns date of next St Patrick's Day
|
---|
1735 | public String saintPatricksDay(){
|
---|
1736 | int year = this.getYear();
|
---|
1737 | int month = this.getMonthAsInteger();
|
---|
1738 | int day = this.getDayOfTheMonth();
|
---|
1739 | boolean direction = this.direction(day, month, year, 17, 3, year);
|
---|
1740 | if(!direction)year++;
|
---|
1741 | return saintPatricksDay(year);
|
---|
1742 | }
|
---|
1743 |
|
---|
1744 | // Returns date of St Patrick's Day for the entered year
|
---|
1745 | public String saintPatricksDay(int year){
|
---|
1746 | String day = this.getDayOfDate(17, 3, year);
|
---|
1747 | this.dayHold = 17;
|
---|
1748 | this.monthHold = 3;
|
---|
1749 | this.yearHold = year;
|
---|
1750 | this.dayNameHold = day;
|
---|
1751 | return day + ", 17 March " + year;
|
---|
1752 | }
|
---|
1753 |
|
---|
1754 | // Returns date of next St Brigid's Day
|
---|
1755 | public String saintBrigidsDay(){
|
---|
1756 | int year = this.getYear();
|
---|
1757 | int month = this.getMonthAsInteger();
|
---|
1758 | int day = this.getDayOfTheMonth();
|
---|
1759 | boolean direction = this.direction(day, month, year, 1, 2, year);
|
---|
1760 | if(!direction)year++;
|
---|
1761 | return saintBrigidsDay(year);
|
---|
1762 | }
|
---|
1763 |
|
---|
1764 | // Returns date of St Brigid's Day for the entered year
|
---|
1765 | public String saintBrigidsDay(int year){
|
---|
1766 | String day = this.getDayOfDate(1, 2, year);
|
---|
1767 | this.dayHold = 1;
|
---|
1768 | this.monthHold = 2;
|
---|
1769 | this.yearHold = year;
|
---|
1770 | this.dayNameHold = day;
|
---|
1771 | return day + ", 1 February " + year;
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | // Returns date of next St Colm Cille's (St Columba's)Day
|
---|
1775 | public String saintColmCillesDay(){
|
---|
1776 | int year = this.getYear();
|
---|
1777 | int month = this.getMonthAsInteger();
|
---|
1778 | int day = this.getDayOfTheMonth();
|
---|
1779 | boolean direction = this.direction(day, month, year, 9, 6, year);
|
---|
1780 | if(!direction)year++;
|
---|
1781 | return saintColmCillesDay(year);
|
---|
1782 | }
|
---|
1783 |
|
---|
1784 | public String saintColumbasDay(){
|
---|
1785 | return this.saintColmCillesDay();
|
---|
1786 | }
|
---|
1787 |
|
---|
1788 | public String saintColmcillesDay(){
|
---|
1789 | return this.saintColmCillesDay();
|
---|
1790 | }
|
---|
1791 |
|
---|
1792 | // Returns date of St Colm Cille's (St Columba's) Day for the entered year
|
---|
1793 | public String saintColmCillesDay(int year){
|
---|
1794 | String day = this.getDayOfDate(9, 6, year);
|
---|
1795 | this.dayHold = 9;
|
---|
1796 | this.monthHold = 6;
|
---|
1797 | this.yearHold = year;
|
---|
1798 | this.dayNameHold = day;
|
---|
1799 | return day + ", 9 June " + year;
|
---|
1800 | }
|
---|
1801 |
|
---|
1802 | public String saintColumbasDay(int year){
|
---|
1803 | return this.saintColmCillesDay(year);
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | public String saintColmcillesDay(int year){
|
---|
1807 | return this.saintColmCillesDay(year);
|
---|
1808 | }
|
---|
1809 |
|
---|
1810 | // Returns date of next St Georges's day
|
---|
1811 | public String saintGeorgesDay(){
|
---|
1812 | int year = this.getYear();
|
---|
1813 | int month = this.getMonthAsInteger();
|
---|
1814 | int day = this.getDayOfTheMonth();
|
---|
1815 | boolean direction = this.direction(day, month, year, 23, 4, year);
|
---|
1816 | if(!direction)year++;
|
---|
1817 | return saintGeorgesDay(year);
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | // Returns date of St George's day for the entered year
|
---|
1821 | public String saintGeorgesDay(int year){
|
---|
1822 | String day = this.getDayOfDate(23, 4, year);
|
---|
1823 | this.dayHold = 23;
|
---|
1824 | this.monthHold = 4;
|
---|
1825 | this.yearHold = year;
|
---|
1826 | this.dayNameHold = day;
|
---|
1827 | return day + ", 23 April " + year;
|
---|
1828 | }
|
---|
1829 |
|
---|
1830 | // Returns date of next St Andrew's day
|
---|
1831 | public String saintAndrewsDay(){int year = this.getYear();
|
---|
1832 | int month = this.getMonthAsInteger();
|
---|
1833 | int day = this.getDayOfTheMonth();
|
---|
1834 | boolean direction = this.direction(day, month, year, 30, 11, year);
|
---|
1835 | if(!direction)year++;
|
---|
1836 | return saintAndrewsDay(year);
|
---|
1837 | }
|
---|
1838 |
|
---|
1839 | // Returns date of St Andrew's day for the entered year
|
---|
1840 | public String saintAndrewsDay(int year){
|
---|
1841 | String day = this.getDayOfDate(30, 11, year);
|
---|
1842 | this.dayHold = 30;
|
---|
1843 | this.monthHold = 11;
|
---|
1844 | this.yearHold = year;
|
---|
1845 | this.dayNameHold = day;
|
---|
1846 | return day + ", 30 November " + year;
|
---|
1847 | }
|
---|
1848 |
|
---|
1849 | // Returns date of next St David's day
|
---|
1850 | public String saintDavidsDay(){
|
---|
1851 | int year = this.getYear();
|
---|
1852 | int month = this.getMonthAsInteger();
|
---|
1853 | int day = this.getDayOfTheMonth();
|
---|
1854 | boolean direction = this.direction(day, month, year, 1, 3, year);
|
---|
1855 | if(!direction)year++;
|
---|
1856 | return saintDavidsDay(year);
|
---|
1857 | }
|
---|
1858 |
|
---|
1859 | // Returns date of St David's day for the entered year
|
---|
1860 | public String saintDavidsDay(int year){
|
---|
1861 | String day = this.getDayOfDate(1, 3, year);
|
---|
1862 | this.dayHold = 1;
|
---|
1863 | this.monthHold = 3;
|
---|
1864 | this.yearHold = year;
|
---|
1865 | this.dayNameHold = day;
|
---|
1866 | return day + ", 1 March " + year;
|
---|
1867 | }
|
---|
1868 |
|
---|
1869 | // Returns date of next St Stephen's day
|
---|
1870 | public String saintStephensDay(){
|
---|
1871 | int year = this.getYear();
|
---|
1872 | int month = this.getMonthAsInteger();
|
---|
1873 | int day = this.getDayOfTheMonth();
|
---|
1874 | boolean direction = this.direction(day, month, year, 26, 12, year);
|
---|
1875 | if(!direction)year++;
|
---|
1876 | return saintStephensDay(year);
|
---|
1877 | }
|
---|
1878 |
|
---|
1879 | // Returns date of St Stephen's day for the entered year
|
---|
1880 | public String saintStephensDay(int year){
|
---|
1881 | String day = this.getDayOfDate(26, 12, year);
|
---|
1882 | this.dayHold = 26;
|
---|
1883 | this.monthHold = 12;
|
---|
1884 | this.yearHold = year;
|
---|
1885 | this.dayNameHold = day;
|
---|
1886 | return day + ", 26 December " + year;
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | // Returns date of next St Valentine's day
|
---|
1890 | public String saintValentinesDay(){
|
---|
1891 | int year = this.getYear();
|
---|
1892 | int month = this.getMonthAsInteger();
|
---|
1893 | int day = this.getDayOfTheMonth();
|
---|
1894 | boolean direction = this.direction(day, month, year, 14, 2, year);
|
---|
1895 | if(!direction)year++;
|
---|
1896 | return saintValentinesDay(year);
|
---|
1897 | }
|
---|
1898 |
|
---|
1899 | // Returns date of St Valentines's day for the entered year
|
---|
1900 | public String saintValentinesDay(int year){
|
---|
1901 | String day = this.getDayOfDate(14, 2, year);
|
---|
1902 | this.dayHold = 14;
|
---|
1903 | this.monthHold = 2;
|
---|
1904 | this.yearHold = year;
|
---|
1905 | this.dayNameHold = day;
|
---|
1906 | return day + ", 14 February " + year;
|
---|
1907 | }
|
---|
1908 |
|
---|
1909 |
|
---|
1910 | // Returns date of next Burns' night
|
---|
1911 | public String burnsNight(){
|
---|
1912 | int year = this.getYear();
|
---|
1913 | int month = this.getMonthAsInteger();
|
---|
1914 | int day = this.getDayOfTheMonth();
|
---|
1915 | boolean direction = this.direction(day, month, year, 25, 1, year);
|
---|
1916 | if(!direction)year++;
|
---|
1917 | return burnsNight(year);
|
---|
1918 | }
|
---|
1919 |
|
---|
1920 | // Returns date of Burns night for the entered year
|
---|
1921 | public String burnsNight(int year){
|
---|
1922 | String day = this.getDayOfDate(25, 1, year);
|
---|
1923 | this.dayHold = 25;
|
---|
1924 | this.monthHold = 1;
|
---|
1925 | this.yearHold = year;
|
---|
1926 | this.dayNameHold = day;
|
---|
1927 | return day + ", 25 January " + year;
|
---|
1928 | }
|
---|
1929 |
|
---|
1930 | // Returns date of next Twelfth of July
|
---|
1931 | public String twelfthJuly(){
|
---|
1932 | int year = this.getYear();
|
---|
1933 | int month = this.getMonthAsInteger();
|
---|
1934 | int day = this.getDayOfTheMonth();
|
---|
1935 | boolean direction = this.direction(day, month, year, 12, 7, year);
|
---|
1936 | if(!direction)year++;
|
---|
1937 | return twelfthJuly(year);
|
---|
1938 | }
|
---|
1939 |
|
---|
1940 | // Returns date of the Twelfth of July for the entered year
|
---|
1941 | public String twelfthJuly(int year){
|
---|
1942 | String day = this.getDayOfDate(12, 7, year);
|
---|
1943 | this.dayHold = 12;
|
---|
1944 | this.monthHold = 7;
|
---|
1945 | this.yearHold = year;
|
---|
1946 | this.dayNameHold = day;
|
---|
1947 | return day + ", 12 July " + year;
|
---|
1948 | }
|
---|
1949 |
|
---|
1950 | // Returns date of next Fourth of July (US Independence Day)
|
---|
1951 | public String fourthJuly(){
|
---|
1952 | int year = this.getYear();
|
---|
1953 | int month = this.getMonthAsInteger();
|
---|
1954 | int day = this.getDayOfTheMonth();
|
---|
1955 | boolean direction = this.direction(day, month, year, 12, 7, year);
|
---|
1956 | if(!direction)year++;
|
---|
1957 | return fourthJuly(year);
|
---|
1958 | }
|
---|
1959 |
|
---|
1960 | // Returns date of the Fourth of July (US Independence Day)for the entered year
|
---|
1961 | public String fourthJuly(int year){
|
---|
1962 | String day = this.getDayOfDate(4, 7, year);
|
---|
1963 | this.dayHold = 4;
|
---|
1964 | this.monthHold = 7;
|
---|
1965 | this.yearHold = year;
|
---|
1966 | this.dayNameHold = day;
|
---|
1967 | return day + ", 4 July " + year;
|
---|
1968 | }
|
---|
1969 |
|
---|
1970 | // Returns date of next US Thanksgiving Day
|
---|
1971 | public String thanksgivingDay(){
|
---|
1972 | int year = this.getYear();
|
---|
1973 | int month = this.getMonthAsInteger();
|
---|
1974 | int day = this.getDayOfTheMonth();
|
---|
1975 |
|
---|
1976 | String day1 = this.getDayOfDate(1, "November", year);
|
---|
1977 | int day1I = this.getDayOfTheWeekAsInteger(day1) + 1;
|
---|
1978 | int day2I = 6 - day1I;
|
---|
1979 | if(day2I<=0)day2I += 7;
|
---|
1980 | day2I += 14;
|
---|
1981 | boolean direction = this.direction(day, month, year, day2I, 11, year);
|
---|
1982 | if(direction){
|
---|
1983 | return "Thursday, " + day2I + " November " + year;
|
---|
1984 | }
|
---|
1985 | else{
|
---|
1986 | return thanksgivingDay(++year);
|
---|
1987 | }
|
---|
1988 | }
|
---|
1989 |
|
---|
1990 | // Returns date of the US Thanksgiving Day
|
---|
1991 | public String thanksgivingDay(int year){
|
---|
1992 | String day1 = this.getDayOfDate(1, "November", year);
|
---|
1993 | int day1I = this.getDayOfTheWeekAsInteger(day1) + 1;
|
---|
1994 | int day2I = 6 - day1I;
|
---|
1995 | if(day2I<=0)day2I += 7;
|
---|
1996 | day2I += 14;
|
---|
1997 | this.dayHold = day2I;
|
---|
1998 | this.monthHold = 11;
|
---|
1999 | this.yearHold = year;
|
---|
2000 | this.dayNameHold = "Thursday";
|
---|
2001 | return "Thursday, " + day2I + " November " + year;
|
---|
2002 | }
|
---|
2003 |
|
---|
2004 | // Returns date of next Commonwealth Day
|
---|
2005 | public String commonwealthDay(){
|
---|
2006 | int year = this.getYear();
|
---|
2007 | int month = this.getMonthAsInteger();
|
---|
2008 | int day = this.getDayOfTheMonth();
|
---|
2009 |
|
---|
2010 | String day1 = this.getDayOfDate(1, "March", year);
|
---|
2011 | int day1I = this.getDayOfTheWeekAsInteger(day1);
|
---|
2012 |
|
---|
2013 | int day2I = 0;
|
---|
2014 | if(day1I>1){
|
---|
2015 | day2I = 15 - day1I;
|
---|
2016 | }
|
---|
2017 | else{
|
---|
2018 | if(day1I==0){
|
---|
2019 | day2I = 8;
|
---|
2020 | }
|
---|
2021 | else{
|
---|
2022 | day2I = 9;
|
---|
2023 | }
|
---|
2024 | }
|
---|
2025 | boolean direction = this.direction(day, month, year, day2I, 3, year);
|
---|
2026 | if(direction){
|
---|
2027 | this.dayHold = day2I;
|
---|
2028 | this.monthHold = 3;
|
---|
2029 | this.yearHold = year;
|
---|
2030 | this.dayNameHold = "Monday";
|
---|
2031 | return "Monday, " + day2I + " November " + year;
|
---|
2032 | }
|
---|
2033 | else{
|
---|
2034 | return commonwealthDay(++year);
|
---|
2035 | }
|
---|
2036 | }
|
---|
2037 |
|
---|
2038 | // Returns date of the Commonwealth Day
|
---|
2039 | public String commonwealthDay(int year){
|
---|
2040 | String day1 = this.getDayOfDate(1, "March", year);
|
---|
2041 | int day1I = this.getDayOfTheWeekAsInteger(day1);
|
---|
2042 |
|
---|
2043 | int day2I = 0;
|
---|
2044 | if(day1I>1){
|
---|
2045 | day2I = 16 - day1I;
|
---|
2046 | }
|
---|
2047 | else{
|
---|
2048 | if(day1I==0){
|
---|
2049 | day2I = 9;
|
---|
2050 | }
|
---|
2051 | else{
|
---|
2052 | day2I = 8;
|
---|
2053 | }
|
---|
2054 | }
|
---|
2055 | this.dayHold = day2I;
|
---|
2056 | this.monthHold = 3;
|
---|
2057 | this.yearHold = year;
|
---|
2058 | this.dayNameHold = "Monday";
|
---|
2059 | return "Monday, " + day2I + " March " + year;
|
---|
2060 | }
|
---|
2061 |
|
---|
2062 | // Returns date of next Armed Forces Day (UK Veterans' Day)
|
---|
2063 | public String armedForcesDay(){
|
---|
2064 | int year = this.getYear();
|
---|
2065 | int month = this.getMonthAsInteger();
|
---|
2066 | int day = this.getDayOfTheMonth();
|
---|
2067 | boolean direction = this.direction(day, month, year, 27, 6, year);
|
---|
2068 | if(!direction)year++;
|
---|
2069 | return armedForcesDay(year);
|
---|
2070 | }
|
---|
2071 |
|
---|
2072 | public String veteransDayUK(){
|
---|
2073 | return this.armedForcesDay();
|
---|
2074 | }
|
---|
2075 |
|
---|
2076 | // Returns date of the Armed Forces Day (UK Veterans' Day)for the entered year
|
---|
2077 | public String armedForcesDay(int year){
|
---|
2078 | String day = this.getDayOfDate(27, 6, year);
|
---|
2079 | this.dayHold = 27;
|
---|
2080 | this.monthHold = 6;
|
---|
2081 | this.yearHold = year;
|
---|
2082 | this.dayNameHold = day;
|
---|
2083 | return day + ", 27 June " + year;
|
---|
2084 | }
|
---|
2085 |
|
---|
2086 | public String veteransDayUK(int year){
|
---|
2087 | return this.armedForcesDay(year);
|
---|
2088 | }
|
---|
2089 |
|
---|
2090 | // Returns true if year (argument) is a leap year
|
---|
2091 | public boolean leapYear(int year){
|
---|
2092 | boolean test = false;
|
---|
2093 |
|
---|
2094 | if(year%4 != 0){
|
---|
2095 | test = false;
|
---|
2096 | }
|
---|
2097 | else{
|
---|
2098 | if(year%400 == 0){
|
---|
2099 | test=true;
|
---|
2100 | }
|
---|
2101 | else{
|
---|
2102 | if(year%100 == 0){
|
---|
2103 | test=false;
|
---|
2104 | }
|
---|
2105 | else{
|
---|
2106 | test=true;
|
---|
2107 | }
|
---|
2108 | }
|
---|
2109 | }
|
---|
2110 | return test;
|
---|
2111 | }
|
---|
2112 | }
|
---|
2113 |
|
---|