Source Code Cross Referenced for Holidays.java in  » J2EE » Sofia » com » salmonllc » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //** Copyright Statement ***************************************************
002:        //The Salmon Open Framework for Internet Applications (SOFIA)
003:        // Copyright (C) 1999 - 2002, Salmon LLC
004:        //
005:        // This program is free software; you can redistribute it and/or
006:        // modify it under the terms of the GNU General Public License version 2
007:        // as published by the Free Software Foundation;
008:        // 
009:        // This program is distributed in the hope that it will be useful,
010:        // but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        // GNU General Public License for more details.
013:        // 
014:        // You should have received a copy of the GNU General Public License
015:        // along with this program; if not, write to the Free Software
016:        // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:        // 
018:        // For more information please visit http://www.salmonllc.com
019:        //** End Copyright Statement ***************************************************
020:
021:        //
022:        //
023:        //		Author: Gregory N. Mirsky
024:        //		Updated: John D. Mitchell
025:        //		Version 1.02
026:        //
027:
028:        package com.salmonllc.util;
029:
030:        import java.util.Calendar;
031:
032:        public class Holidays {
033:
034:            //*********************************
035:            // Miscellaneous other holidays are left as an exercise for the reader.
036:            //
037:            // public static Date QuebecCivicHoliday (int nYear)
038:            // {
039:            //  // 03 January YYYY
040:            // }
041:            //
042:            // public static Date AshWednesday (int nYear)
043:            // {
044:            //  // 42 days before easter...
045:            // }
046:            //
047:            // public static Date PalmSunday (int nYear)
048:            // {
049:            //  // Sunday before Easter Sunday...
050:            // }
051:            //
052:            // public static Date MaundayThursday (int nYear)
053:            // {
054:            //  // Thursday before Easter...
055:            // }
056:            //
057:            //  public static Date RoshHashanah(int nYear)
058:            // {
059:            //  Source: William H. Jefferys, Department of Astronomy, University of
060:            //  Texas Austin, TX 78712 
061:            //
062:            //         http://quasar.as.utexas.edu
063:            //
064:            //  First, calculate the Golden Number G. This is fundamental to the
065:            //  calculation of both the date of Easter and the Date of Rosh Hashanah. 
066:            //  It is intimately connected with the Metonic Cycle. For any year Y, the
067:            //  Golden Number is defined as 
068:            //
069:            //  G = Remainder(Y|19) + 1. Don't forget to add the 1!!!
070:            //
071:            //  The following rules are also due to John Horton Conway, of Princeton
072:            //  University. In the Gregorian year Y of the Common Era, Rosh Hashanah
073:            //  normally falls on September N, where
074:            //
075:            //  N + fraction = {[Y/100] - [Y/400] - 2} +
076:            //  765433/492480*Remainder(12G|19) + Remainder(Y|4)/4 - (313Y+89081)/98496
077:            //
078:            //  Here, G is the Golden Number, and * means multiply. However, if certain
079:            //  conditions are satisfied, Rosh Hashanah is postponed by one or even two
080:            //  days, as follows: 
081:            //
082:            //      ***Postponement rules***
083:            //
084:            //  1.If the day calculated above is a Sunday, Wednesday, or Friday, Rosh
085:            //  Hashanah falls on the next day (Monday, Thursday or Saturday,
086:            //  respectively).
087:            //
088:            //  2.If the calculated day is a Monday, and if the fraction is greater
089:            //  than or equal to 23269/25920, and if Remainder(12G|19) is greater than
090:            //  11, Rosh Hashanah falls on the next day, a Tuesday.
091:            //
092:            //  3.If it is a Tuesday, and if the fraction is greater than or equal to
093:            //  1367/2160, and if Remainder(12G|19) is greater than 6, Rosh Hashanah
094:            //  falls two days later, on Thursday (NOT WEDNESDAY!!).
095:            // }
096:            //
097:            //  public static Date Passover(int nYear)
098:            // {
099:            //  Source: William H. Jefferys, Department of Astronomy, University of
100:            //  Texas Austin, TX 78712
101:            //
102:            //         http://quasar.as.utexas.edu
103:            //
104:            //  Once you have determined the date of Rosh Hashanah, it is easy to
105:            //  calculate the date of Passover in the same (Gregorian or Julian)
106:            //  year. Let M = the number of days from September 6 to Rosh Hashanah.
107:            //  In the example for 1996, M=September 14-September 6 = 8 days.
108:            //
109:            //  Count M days from March 27. That is the date of Passover. It actually
110:            //  begins at sundown on the previous evening. In the example for 1996, 8
111:            //  days after March 27 is April 4 (there are 31 days in March), so
112:            //  Passover begins at sundown on April 3.
113:            // }
114:            //
115:            // public static Date DominionDay (int nYear)
116:            // {
117:            //  // 01 July YYYY
118:            // }
119:            //
120:            // public static Date BoxingDay (int nYear)
121:            //  {
122:            //  // Day after Christmas, December 26th...
123:            //  }
124:            //
125:            //*********************************************
126:
127:            public static java.util.Calendar AbrahamLincolnsBirthday(int nYear) {
128:                int nMonth = 1; // February
129:                // February 12th
130:
131:                java.util.Calendar cal = java.util.Calendar.getInstance();
132:                cal.set(nYear, nMonth, 12);
133:                return cal;
134:            }
135:
136:            public static java.util.Calendar ChristmasDay(int nYear) {
137:                int nMonth = 11; // Decmeber
138:                // December 25th
139:                java.util.Calendar cal = java.util.Calendar.getInstance();
140:                cal.set(nYear, nMonth, 25);
141:                return cal;
142:            }
143:
144:            public static java.util.Calendar ChristmasDayObserved(int nYear) {
145:                int nX;
146:                int nMonth = 11; // December
147:                java.util.Calendar cal;
148:
149:                cal = java.util.Calendar.getInstance();
150:                cal.set(nYear, nMonth, 25);
151:                nX = cal.get(Calendar.DAY_OF_WEEK);
152:                switch (nX) {
153:                case 0: {// Sunday
154:                    cal = java.util.Calendar.getInstance();
155:                    cal.set(nYear, nMonth, 26);
156:                    return cal;
157:                }
158:                case 1: // Monday
159:                case 2: // Tuesday
160:                case 3: // Wednesday
161:                case 4: // Thrusday
162:                case 5: { // Friday
163:                    cal = java.util.Calendar.getInstance();
164:                    cal.set(nYear, nMonth, 25);
165:                    return cal;
166:                }
167:                default: {
168:                    // Saturday
169:                    cal = java.util.Calendar.getInstance();
170:                    cal.set(nYear, nMonth, 24);
171:                    return cal;
172:                }
173:                }
174:            }
175:
176:            public static java.util.Calendar ColumbusDayObserved(int nYear) {
177:                // Second Monday in October
178:                int nX;
179:                int nMonth = 9; // October 
180:                java.util.Calendar cal;
181:
182:                cal = java.util.Calendar.getInstance();
183:                cal.set(nYear, nMonth, 1);
184:                nX = cal.get(Calendar.DAY_OF_WEEK);
185:                switch (nX) {
186:                case 0: {// Sunday
187:                    cal = java.util.Calendar.getInstance();
188:                    cal.set(nYear, nMonth, 9);
189:                    return cal;
190:                }
191:                case 1: {// Monday
192:                    cal = java.util.Calendar.getInstance();
193:                    cal.set(nYear, nMonth, 15);
194:                    return cal;
195:                }
196:                case 2: // Tuesday
197:                {
198:                    cal = java.util.Calendar.getInstance();
199:                    cal.set(nYear, nMonth, 14);
200:                    return cal;
201:                }
202:                case 3: // Wednesday
203:                {
204:                    cal = java.util.Calendar.getInstance();
205:                    cal.set(nYear, nMonth, 13);
206:                    return cal;
207:                }
208:                case 4: // Thrusday
209:                {
210:                    cal = java.util.Calendar.getInstance();
211:                    cal.set(nYear, nMonth, 12);
212:                    return cal;
213:                }
214:                case 5: // Friday
215:                {
216:                    cal = java.util.Calendar.getInstance();
217:                    cal.set(nYear, nMonth, 11);
218:                    return cal;
219:                }
220:                default: // Saturday
221:                {
222:                    cal = java.util.Calendar.getInstance();
223:                    cal.set(nYear, nMonth, 10);
224:                    return cal;
225:                }
226:                }
227:
228:            }
229:
230:            public static java.util.Calendar EasterMonday(int nYear) {
231:                int nEasterMonth = 0;
232:                int nEasterDay = 0;
233:                int nMonthMarch = 2; // March
234:                int nMonthApril = 3; // April
235:                java.util.Calendar cEasterSunday = EasterSunday(nYear);
236:                nEasterMonth = cEasterSunday.get(Calendar.MONTH);
237:                nEasterDay = cEasterSunday.get(Calendar.DAY_OF_MONTH);
238:                if (nEasterMonth == nMonthMarch || nEasterDay == 31) {
239:                    java.util.Calendar cal = java.util.Calendar.getInstance();
240:                    cal.set(nYear, nMonthApril, 1);
241:                    return cal;
242:                } else {
243:                    java.util.Calendar cal = java.util.Calendar.getInstance();
244:                    cal.set(nYear, nEasterMonth, ++nEasterDay);
245:                    return cal;
246:                }
247:            }
248:
249:            public static java.util.Calendar EasterSunday(int nYear) {
250:                /*	Calculate Easter Sunday
251:
252:                 Written by Gregory N. Mirsky
253:
254:                 Source: 2nd Edition by Peter Duffett-Smith. It was originally from
255:                 Butcher's Ecclesiastical Calendar, published in 1876. This
256:                 algorithm has also been published in the 1922 book General
257:                 Astronomy by Spencer Jones; in The Journal of the British
258:                 Astronomical Association (Vol.88, page 91, December 1977); and in
259:                 Astronomical Algorithms (1991) by Jean Meeus.
260:
261:                 This algorithm holds for any year in the Gregorian Calendar, which
262:                 (of course) means years including and after 1583.
263:
264:                 a=year%19
265:                 b=year/100
266:                 c=year%100
267:                 d=b/4
268:                 e=b%4
269:                 f=(b+8)/25
270:                 g=(b-f+1)/3
271:                 h=(19*a+b-d-g+15)%30
272:                 i=c/4
273:                 k=c%4
274:                 l=(32+2*e+2*i-h-k)%7
275:                 m=(a+11*h+22*l)/451
276:                 Easter Month =(h+l-7*m+114)/31  [3=March, 4=April]
277:                 p=(h+l-7*m+114)%31
278:                 Easter Date=p+1     (date in Easter Month)
279:
280:                 Note: Integer truncation is already factored into the
281:                 calculations. Using higher percision variables will cause
282:                 inaccurate calculations. 
283:                 */
284:
285:                int nA = 0;
286:                int nB = 0;
287:                int nC = 0;
288:                int nD = 0;
289:                int nE = 0;
290:                int nF = 0;
291:                int nG = 0;
292:                int nH = 0;
293:                int nI = 0;
294:                int nK = 0;
295:                int nL = 0;
296:                int nM = 0;
297:                int nP = 0;
298:                int nEasterMonth = 0;
299:                int nEasterDay = 0;
300:
301:                // Calculate Easter
302:                if (nYear < 1900) {
303:                    // if year is in java format put it into standard
304:                    // format for the calculation
305:                    nYear += 1900;
306:                }
307:                nA = nYear % 19;
308:                nB = nYear / 100;
309:                nC = nYear % 100;
310:                nD = nB / 4;
311:                nE = nB % 4;
312:                nF = (nB + 8) / 25;
313:                nG = (nB - nF + 1) / 3;
314:                nH = (19 * nA + nB - nD - nG + 15) % 30;
315:                nI = nC / 4;
316:                nK = nC % 4;
317:                nL = (32 + 2 * nE + 2 * nI - nH - nK) % 7;
318:                nM = (nA + 11 * nH + 22 * nL) / 451;
319:
320:                //  [3=March, 4=April]
321:                nEasterMonth = (nH + nL - 7 * nM + 114) / 31;
322:                --nEasterMonth;
323:                nP = (nH + nL - 7 * nM + 114) % 31;
324:
325:                // Date in Easter Month.
326:                nEasterDay = nP + 1;
327:
328:                // Uncorrect for our earlier correction.
329:                nYear -= 1900;
330:
331:                // Populate the date object...
332:                java.util.Calendar cal = java.util.Calendar.getInstance();
333:                cal.set(nYear, nEasterMonth, nEasterDay);
334:                return cal;
335:            }
336:
337:            public static java.util.Calendar GoodFridayObserved(int nYear) {
338:                // Get Easter Sunday and subtract two days
339:                int nEasterMonth = 0;
340:                int nEasterDay = 0;
341:                int nGoodFridayMonth = 0;
342:                int nGoodFridayDay = 0;
343:                java.util.Calendar cEasterSunday;
344:
345:                cEasterSunday = EasterSunday(nYear);
346:                nEasterMonth = cEasterSunday.get(Calendar.MONTH);
347:                nEasterDay = cEasterSunday.get(Calendar.DAY_OF_MONTH);
348:                if (nEasterDay <= 3 && nEasterMonth == 3) { // Check if <= April 3rd
349:
350:                    switch (nEasterDay) {
351:                    case 3:
352:                        nGoodFridayMonth = nEasterMonth - 1;
353:                        nGoodFridayDay = nEasterDay - 2;
354:                        break;
355:                    case 2:
356:                        nGoodFridayMonth = nEasterMonth - 1;
357:                        nGoodFridayDay = 31;
358:                        break;
359:                    case 1:
360:                        nGoodFridayMonth = nEasterMonth - 1;
361:                        nGoodFridayDay = 31;
362:                        break;
363:                    default:
364:                        nGoodFridayMonth = nEasterMonth;
365:                        nGoodFridayDay = nEasterDay - 2;
366:                    }
367:                } else {
368:                    nGoodFridayMonth = nEasterMonth;
369:                    nGoodFridayDay = nEasterDay - 2;
370:                }
371:
372:                java.util.Calendar cal = java.util.Calendar.getInstance();
373:                cal.set(nYear, nGoodFridayMonth, nGoodFridayDay);
374:                return cal;
375:            }
376:
377:            public static java.util.Calendar Halloween(int nYear) {
378:                int nMonth = 9;
379:                // October 31st
380:
381:                java.util.Calendar cal = java.util.Calendar.getInstance();
382:                cal.set(nYear, nMonth, 31);
383:                return cal;
384:            }
385:
386:            public static java.util.Calendar IndependenceDay(int nYear) {
387:                int nMonth = 6; // July
388:                // July 4th
389:
390:                java.util.Calendar cal = java.util.Calendar.getInstance();
391:                cal.set(nYear, nMonth, 4);
392:                return cal;
393:            }
394:
395:            public static java.util.Calendar IndependenceDayObserved(int nYear) {
396:                int nX;
397:                int nMonth = 6; // July
398:
399:                java.util.Calendar cal = java.util.Calendar.getInstance();
400:                cal.set(nYear, nMonth, 4);
401:
402:                nX = cal.get(Calendar.DAY_OF_WEEK);
403:                switch (nX) {
404:                case 0: // Sunday
405:                    cal = java.util.Calendar.getInstance();
406:                    cal.set(nYear, nMonth, 5);
407:                    return cal;
408:                case 1: // Monday
409:                case 2: // Tuesday
410:                case 3: // Wednesday
411:                case 4: // Thrusday
412:                case 5: // Friday
413:                    cal = java.util.Calendar.getInstance();
414:                    cal.set(nYear, nMonth, 4);
415:                    return cal;
416:                default:
417:                    // Saturday
418:                    cal = java.util.Calendar.getInstance();
419:                    cal.set(nYear, nMonth, 3);
420:                    return cal;
421:                }
422:            }
423:
424:            public static java.util.Calendar LaborDayObserved(int nYear) {
425:                // The first Monday in September
426:                int nX;
427:                int nMonth = 8; // September
428:                java.util.Calendar cal = java.util.Calendar.getInstance();
429:                cal.set(nYear, 9, 1);
430:
431:                nX = cal.get(Calendar.DAY_OF_WEEK);
432:
433:                switch (nX) {
434:                case 0: // Sunday
435:                    cal = java.util.Calendar.getInstance();
436:                    cal.set(nYear, nMonth, 2);
437:                    return cal;
438:                case 1: // Monday
439:                    cal = java.util.Calendar.getInstance();
440:                    cal.set(nYear, nMonth, 7);
441:                    return cal;
442:                case 2: // Tuesday
443:                    cal = java.util.Calendar.getInstance();
444:                    cal.set(nYear, nMonth, 6);
445:                    return cal;
446:                case 3: // Wednesday
447:                    cal = java.util.Calendar.getInstance();
448:                    cal.set(nYear, nMonth, 5);
449:                    return cal;
450:                case 4: // Thrusday
451:                    cal = java.util.Calendar.getInstance();
452:                    cal.set(nYear, nMonth, 4);
453:                    return cal;
454:                case 5: // Friday
455:                    cal = java.util.Calendar.getInstance();
456:                    cal.set(nYear, nMonth, 3);
457:                    return cal;
458:                default: // Saturday
459:                    cal = java.util.Calendar.getInstance();
460:                    cal.set(nYear, nMonth, 2);
461:                    return cal;
462:                }
463:            }
464:
465:            public java.util.Calendar MartinLutherKingObserved(int nYear) {
466:                // Third Monday in January
467:                int nX;
468:                int nMonth = 0; // January
469:                java.util.Calendar cal;
470:
471:                cal = java.util.Calendar.getInstance();
472:                cal.set(nYear, nMonth, 1);
473:                nX = cal.get(Calendar.DAY_OF_WEEK);
474:
475:                switch (nX) {
476:                case 0: {// Sunday
477:                    cal = java.util.Calendar.getInstance();
478:                    cal.set(nYear, nMonth, 16);
479:                    return cal;
480:                }
481:                case 1: {// Monday
482:                    cal = java.util.Calendar.getInstance();
483:                    cal.set(nYear, nMonth, 15);
484:                    return cal;
485:                }
486:                case 2: // Tuesday
487:                {
488:                    cal = java.util.Calendar.getInstance();
489:                    cal.set(nYear, nMonth, 21);
490:                    return cal;
491:                }
492:                case 3: // Wednesday
493:                {
494:                    cal = java.util.Calendar.getInstance();
495:                    cal.set(nYear, nMonth, 20);
496:                    return cal;
497:                }
498:                case 4: // Thrusday
499:                {
500:                    cal = java.util.Calendar.getInstance();
501:                    cal.set(nYear, nMonth, 19);
502:                    return cal;
503:                }
504:                case 5: // Friday
505:                {
506:                    cal = java.util.Calendar.getInstance();
507:                    cal.set(nYear, nMonth, 18);
508:                    return cal;
509:                }
510:                default: // Saturday
511:                {
512:                    cal = java.util.Calendar.getInstance();
513:                    cal.set(nYear, nMonth, 17);
514:                    return cal;
515:                }
516:
517:                }
518:            }
519:
520:            public static java.util.Calendar MemorialDayObserved(int nYear) {
521:                // Last Monday in May
522:                int nX;
523:                int nMonth = 4; //May
524:                java.util.Calendar cal = java.util.Calendar.getInstance();
525:                cal.set(nYear, nMonth, 31);
526:
527:                nX = cal.get(Calendar.DAY_OF_WEEK);
528:
529:                switch (nX) {
530:                case 0: // Sunday
531:                    cal = java.util.Calendar.getInstance();
532:                    cal.set(nYear, nMonth, 25);
533:                    return cal;
534:                case 1: // Monday
535:                    cal = java.util.Calendar.getInstance();
536:                    cal.set(nYear, nMonth, 31);
537:                    return cal;
538:                case 2: // Tuesday
539:                    cal = java.util.Calendar.getInstance();
540:                    cal.set(nYear, nMonth, 30);
541:                    return cal;
542:                case 3: // Wednesday
543:                    cal = java.util.Calendar.getInstance();
544:                    cal.set(nYear, nMonth, 29);
545:                    return cal;
546:                case 4: // Thrusday
547:                    cal = java.util.Calendar.getInstance();
548:                    cal.set(nYear, nMonth, 28);
549:                    return cal;
550:                case 5: // Friday
551:                    cal = java.util.Calendar.getInstance();
552:                    cal.set(nYear, nMonth, 27);
553:                    return cal;
554:                default: // Saturday
555:                    cal = java.util.Calendar.getInstance();
556:                    cal.set(nYear, nMonth, 26);
557:                    return cal;
558:
559:                }
560:            }
561:
562:            public static java.util.Calendar NewYearsDay(int nYear) {
563:                // January 1st
564:                int nMonth = 0; // January
565:
566:                java.util.Calendar cal = java.util.Calendar.getInstance();
567:                cal.set(nYear, nMonth, 1);
568:
569:                return cal;
570:            }
571:
572:            public static java.util.Calendar NewYearsDayObserved(int nYear) {
573:                int nX;
574:                int nMonth = 0; // January
575:                int nMonthDecember = 11; // December
576:
577:                java.util.Calendar cal = java.util.Calendar.getInstance();
578:                cal.set(nYear, nMonth, 1);
579:
580:                nX = cal.get(Calendar.DAY_OF_WEEK);
581:
582:                if (nYear > 1900)
583:                    nYear -= 1900;
584:
585:                switch (nX) {
586:                case 0: // Sunday
587:                    cal = java.util.Calendar.getInstance();
588:                    cal.set(nYear, nMonth, 2);
589:                    return cal;
590:                case 1: // Monday
591:                case 2: // Tuesday
592:                case 3: // Wednesday
593:                case 4: // Thrusday
594:                case 5: // Friday
595:                    cal = java.util.Calendar.getInstance();
596:                    cal.set(nYear, nMonth, 1);
597:                    return cal;
598:                default:
599:                    // Saturday, then observe on friday of previous year
600:                    cal = java.util.Calendar.getInstance();
601:                    cal.set(--nYear, nMonthDecember, 31);
602:                    return cal;
603:                }
604:            }
605:
606:            public static java.util.Calendar PresidentsDayObserved(int nYear) {
607:                // Third Monday in February
608:                int nX;
609:                int nMonth = 1; // February
610:
611:                java.util.Calendar cal = java.util.Calendar.getInstance();
612:                cal.set(nYear, nMonth, 1);
613:
614:                nX = cal.get(Calendar.DAY_OF_WEEK);
615:
616:                switch (nX) {
617:                case 0: {// Sunday
618:                    cal = java.util.Calendar.getInstance();
619:                    cal.set(nYear, nMonth, 16);
620:                    return cal;
621:                }
622:                case 1: {// Monday
623:                    cal = java.util.Calendar.getInstance();
624:                    cal.set(nYear, nMonth, 15);
625:                    return cal;
626:                }
627:                case 2: // Tuesday
628:                {
629:                    cal = java.util.Calendar.getInstance();
630:                    cal.set(nYear, nMonth, 21);
631:                    return cal;
632:                }
633:                case 3: // Wednesday
634:                {
635:                    cal = java.util.Calendar.getInstance();
636:                    cal.set(nYear, nMonth, 20);
637:                    return cal;
638:                }
639:                case 4: // Thrusday
640:                {
641:                    cal = java.util.Calendar.getInstance();
642:                    cal.set(nYear, nMonth, 19);
643:                    return cal;
644:                }
645:                case 5: // Friday
646:                {
647:                    cal = java.util.Calendar.getInstance();
648:                    cal.set(nYear, nMonth, 18);
649:                    return cal;
650:                }
651:                default: // Saturday
652:                {
653:                    cal = java.util.Calendar.getInstance();
654:                    cal.set(nYear, nMonth, 17);
655:                    return cal;
656:                }
657:                }
658:            }
659:
660:            public static java.util.Calendar ThanksgivingObserved(int nYear) {
661:                int nX;
662:                int nMonth = 10; // November
663:                java.util.Calendar cal = java.util.Calendar.getInstance();
664:                cal.set(nYear, nMonth, 1);
665:
666:                nX = cal.get(Calendar.DAY_OF_WEEK);
667:                switch (nX) {
668:
669:                case 0: {// Sunday
670:                    cal = java.util.Calendar.getInstance();
671:                    cal.set(nYear, nMonth, 26);
672:                    return cal;
673:                }
674:                case 1: {// Monday
675:                    cal = java.util.Calendar.getInstance();
676:                    cal.set(nYear, nMonth, 25);
677:                    return cal;
678:                }
679:                case 2: // Tuesday
680:                {
681:                    cal = java.util.Calendar.getInstance();
682:                    cal.set(nYear, nMonth, 24);
683:                    return cal;
684:                }
685:                case 3: // Wednesday
686:                {
687:                    cal = java.util.Calendar.getInstance();
688:                    cal.set(nYear, nMonth, 23);
689:                    return cal;
690:                }
691:                case 4: // Thrusday
692:                {
693:                    cal = java.util.Calendar.getInstance();
694:                    cal.set(nYear, nMonth, 22);
695:                    return cal;
696:                }
697:                case 5: // Friday
698:                {
699:                    cal = java.util.Calendar.getInstance();
700:                    cal.set(nYear, nMonth, 28);
701:                    return cal;
702:                }
703:                default: // Saturday
704:                {
705:                    cal = java.util.Calendar.getInstance();
706:                    cal.set(nYear, nMonth, 27);
707:                    return cal;
708:                }
709:                }
710:            }
711:
712:            public static java.util.Calendar USElectionDay(int nYear) {
713:                // First Tuesday in November
714:                int nX;
715:                int nMonth = 10; // November
716:                java.util.Calendar cal = java.util.Calendar.getInstance();
717:                cal.set(nYear, nMonth, 1);
718:                nX = cal.get(Calendar.DAY_OF_WEEK);
719:                switch (nX) {
720:                case 0: {// Sunday
721:                    cal = java.util.Calendar.getInstance();
722:                    cal.set(nYear, nMonth, 3);
723:                    return cal;
724:                }
725:                case 1: {// Monday
726:                    cal = java.util.Calendar.getInstance();
727:                    cal.set(nYear, nMonth, 2);
728:                    return cal;
729:                }
730:                case 2: // Tuesday
731:                {
732:                    cal = java.util.Calendar.getInstance();
733:                    cal.set(nYear, nMonth, 1);
734:                    return cal;
735:                }
736:                case 3: // Wednesday
737:                {
738:                    cal = java.util.Calendar.getInstance();
739:                    cal.set(nYear, nMonth, 7);
740:                    return cal;
741:                }
742:                case 4: // Thrusday
743:                {
744:                    cal = java.util.Calendar.getInstance();
745:                    cal.set(nYear, nMonth, 6);
746:                    return cal;
747:                }
748:                case 5: // Friday
749:                {
750:                    cal = java.util.Calendar.getInstance();
751:                    cal.set(nYear, nMonth, 5);
752:                    return cal;
753:                }
754:                default: // Saturday
755:                {
756:                    cal = java.util.Calendar.getInstance();
757:                    cal.set(nYear, nMonth, 4);
758:                    return cal;
759:                }
760:                }
761:            }
762:
763:            public static java.util.Calendar ValentinesDay(int nYear) {
764:                int nMonth = 1; // February
765:                // February 14th
766:
767:                java.util.Calendar cal = java.util.Calendar.getInstance();
768:                cal.set(nYear, nMonth, 14);
769:                return cal;
770:            }
771:
772:            public static java.util.Calendar VeteransDayObserved(int nYear) {
773:                //November 11th
774:                int nMonth = 10; // November
775:                java.util.Calendar cal = java.util.Calendar.getInstance();
776:                cal.set(nYear, nMonth, 11);
777:                return cal;
778:            }
779:
780:            public static String getClassInfo() {
781:                return ("Name: Holidays\r\n" + "Author: Gregory N. Mirsky\r\n"
782:                        + "Updated: John D. Mitchell\r\n" + "Version 1.02\r\n"
783:                        + "Copyright 1997, All rights reserved.");
784:            }
785:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.