Source Code Cross Referenced for CopticTest.java in  » Internationalization-Localization » icu4j » com » ibm » icu » dev » test » calendar » 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 » Internationalization Localization » icu4j » com.ibm.icu.dev.test.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *******************************************************************************
003:         * Copyright (C) 2005, International Business Machines Corporation and         *
004:         * others. All Rights Reserved.                                                *
005:         *******************************************************************************
006:         */
007:        package com.ibm.icu.dev.test.calendar;
008:
009:        import java.util.Date;
010:        import java.util.Locale;
011:
012:        import com.ibm.icu.impl.LocaleUtility;
013:        import com.ibm.icu.text.DateFormat;
014:        import com.ibm.icu.text.SimpleDateFormat;
015:        import com.ibm.icu.util.Calendar;
016:        import com.ibm.icu.util.CopticCalendar;
017:        import com.ibm.icu.util.EthiopicCalendar;
018:        import com.ibm.icu.util.GregorianCalendar;
019:        import com.ibm.icu.util.TimeZone;
020:        import com.ibm.icu.util.ULocale;
021:
022:        /**
023:         * Tests for the <code>CopticCalendar</code> class.
024:         */
025:        public class CopticTest extends CalendarTest {
026:            public static void main(String args[]) throws Exception {
027:                new CopticTest().run(args);
028:            }
029:
030:            /** Constants to save typing. */
031:            public static final int TOUT = CopticCalendar.TOUT;
032:            public static final int BABA = CopticCalendar.BABA;
033:            public static final int HATOR = CopticCalendar.HATOR;
034:            public static final int KIAHK = CopticCalendar.KIAHK;
035:            public static final int TOBA = CopticCalendar.TOBA;
036:            public static final int AMSHIR = CopticCalendar.AMSHIR;
037:            public static final int BARAMHAT = CopticCalendar.BARAMHAT;
038:            public static final int BARAMOUDA = CopticCalendar.BARAMOUDA;
039:            public static final int BASHANS = CopticCalendar.BASHANS;
040:            public static final int PAONA = CopticCalendar.PAONA;
041:            public static final int EPEP = CopticCalendar.EPEP;
042:            public static final int MESRA = CopticCalendar.MESRA;
043:            public static final int NASIE = CopticCalendar.NASIE;
044:
045:            /* Test dates from:
046:             * "The Amharic Letters of Emperor Theodore of Ethiopia to Queen Victoria and
047:             * Her Special Envoy", David Appleyard, Girma Selasse Asfaw, Oxford University Press, 
048:             * June 1 1979, ISBN: 0856726605, Longwood Pr Ltd
049:             *  
050:             * Coptic         Gregorian    JD
051:             * 20/02/1579     29/10/1862  2401443 
052:             * 29/10/1581     05/07/1865  2402423
053:             * 22/05/1582     29/01/1866  2402631
054:             * 10/08/1582     17/04/1866  2402709
055:             * 28/04/1583     05/01/1867  2402972
056:             * 05/05/1584     13/01/1868  2403345
057:             * 
058:             * --------------------------------------------------
059:             * 
060:             * From the Calendrica applet:  http://emr.cs.iit.edu/home/reingold/calendar-book/Calendrica.html
061:             * 
062:             * Coptic         Gregorian    JD
063:             * 07/05/-284     01/01/0000  1721060
064:             * 08/05/-283     01/01/0001  1721426
065:             * 06/13/-1       29/08/0283  1824664
066:             * 
067:             * 01/01/0000     30/08/0283  1824665
068:             * 01/01/0001     29/08/0284  1825030
069:             * 01/01/0002     29/08/0285  1825395
070:             * 01/01/0003     29/08/0286  1825760
071:             * 01/01/0004     30/08/0287  1826126
072:             * 05/13/0000     28/08/0284  1825029 
073:             * 05/13/0001     28/08/0285  1825394
074:             * 05/13/0002     28/08/0286  1825759
075:             * 05/13/0003     28/08/0287  1826124
076:             * 06/13/0003     29/08/0287  1826125  first coptic leap year
077:             * 05/13/0004     28/08/0288  1826490
078:             * 
079:             * 06/02/1299     13/10/1582  2299159
080:             * 07/02/1299     14/10/1582  2299160  Julian 04/10/1582
081:             * 08/02/1299     15/10/1582  2299161
082:             * 09/02/1299     16/10/1582  2299162
083:             * 
084:             * 23/04/1616     01/01/1900  2415021
085:             * 23/04/1721     01/01/2005  2453372 
086:             * 05/13/2000     12/09/2284  2555529
087:             */
088:
089:            /** A huge list of test cases to make sure that computeTime and computeFields
090:             * work properly for a wide range of data in the civil calendar.
091:             */
092:            public void TestCases() {
093:                final TestCase[] tests = {
094:                //
095:                        // The months in this table are 1-based rather than 0-based,
096:                        // because it's easier to edit that way.
097:                        //                      Coptic
098:                        //          Julian Day  Era  Year  Month Day  WkDay Hour Min Sec
099:                        //
100:                        // Dates from "Emporer Theodore..."
101:
102:                        new TestCase(2401442.5, 1, 1579, 2, 20, WED, 0, 0, 0), // Gregorian: 20/10/1862
103:                        new TestCase(2402422.5, 1, 1581, 10, 29, WED, 0, 0, 0), // Gregorian: 05/07/1865
104:                        new TestCase(2402630.5, 1, 1582, 5, 22, MON, 0, 0, 0), // Gregorian: 29/01/1866
105:                        new TestCase(2402708.5, 1, 1582, 8, 10, TUE, 0, 0, 0), // Gregorian: 17/04/1866
106:                        new TestCase(2402971.5, 1, 1583, 4, 28, SAT, 0, 0, 0), // Gregorian: 05/01/1867
107:                        new TestCase(2403344.5, 1, 1584, 5, 5, MON, 0, 0, 0), // Gregorian: 13/01/1868
108:                        new TestCase(1721059.5, 0, -284, 5, 7, SAT, 0, 0, 0), // Gregorian: 01/01/0000
109:                        new TestCase(1721425.5, 0, -283, 5, 8, MON, 0, 0, 0), // Gregorian: 01/01/0001
110:                        new TestCase(1824663.5, 0, -1, 13, 6, WED, 0, 0, 0), // Gregorian: 29/08/0283
111:                        new TestCase(1824664.5, 1, 0, 1, 1, THU, 0, 0, 0), // Gregorian: 30/08/0283
112:                        new TestCase(1825029.5, 1, 1, 1, 1, FRI, 0, 0, 0), // Gregorian: 29/08/0284
113:                        new TestCase(1825394.5, 1, 2, 1, 1, SAT, 0, 0, 0), // Gregorian: 29/08/0285
114:                        new TestCase(1825759.5, 1, 3, 1, 1, SUN, 0, 0, 0), // Gregorian: 29/08/0286
115:                        new TestCase(1826125.5, 1, 4, 1, 1, TUE, 0, 0, 0), // Gregorian: 30/08/0287
116:                        new TestCase(1825028.5, 1, 0, 13, 5, THU, 0, 0, 0), // Gregorian: 28/08/0284
117:                        new TestCase(1825393.5, 1, 1, 13, 5, FRI, 0, 0, 0), // Gregorian: 28/08/0285
118:                        new TestCase(1825758.5, 1, 2, 13, 5, SAT, 0, 0, 0), // Gregorian: 28/08/0286
119:                        new TestCase(1826123.5, 1, 3, 13, 5, SUN, 0, 0, 0), // Gregorian: 28/08/0287
120:                        new TestCase(1826124.5, 1, 3, 13, 6, MON, 0, 0, 0), // Gregorian: 29/08/0287
121:                        // above is first coptic leap year
122:                        new TestCase(1826489.5, 1, 4, 13, 5, TUE, 0, 0, 0), // Gregorian: 28/08/0288
123:                        new TestCase(2299158.5, 1, 1299, 2, 6, WED, 0, 0, 0), // Gregorian: 13/10/1582
124:                        new TestCase(2299159.5, 1, 1299, 2, 7, THU, 0, 0, 0), // Gregorian: 14/10/1582
125:
126:                        new TestCase(2299160.5, 1, 1299, 2, 8, FRI, 0, 0, 0), // Gregorian: 15/10/1582
127:                        new TestCase(2299161.5, 1, 1299, 2, 9, SAT, 0, 0, 0), // Gregorian: 16/10/1582
128:
129:                        new TestCase(2415020.5, 1, 1616, 4, 23, MON, 0, 0, 0), // Gregorian: 01/01/1900
130:                        new TestCase(2453371.5, 1, 1721, 4, 23, SAT, 0, 0, 0), // Gregorian: 01/01/2005
131:                        new TestCase(2555528.5, 1, 2000, 13, 5, FRI, 0, 0, 0), // Gregorian: 12/09/2284
132:                };
133:
134:                CopticCalendar testCalendar = new CopticCalendar();
135:                testCalendar.setLenient(true);
136:                doTestCases(tests, testCalendar);
137:            }
138:
139:            // basic sanity check that the conversion algorithm round-trips
140:            public void TestCopticToJD() {
141:                for (int y = -2; y < 3; ++y) {
142:                    for (int m = 0; m < 12; ++m) { // don't understand rules for 13th month
143:                        for (int d = 1; d < 25; d += 3) { // play it safe on days per month
144:                            int jd = CopticCalendar.copticToJD(y, m, d);
145:                            Integer[] res = CopticCalendar.getDateFromJD(jd);
146:                            if (!(y == res[0].intValue()
147:                                    && m == res[1].intValue() && d == res[2]
148:                                    .intValue())) {
149:                                errln("y: " + y + " m: " + m + " d: " + d
150:                                        + " --> jd: " + jd + " --> y: "
151:                                        + res[0].intValue() + " m: "
152:                                        + res[1].intValue() + " d: "
153:                                        + res[2].intValue());
154:                            }
155:                        }
156:                    }
157:                }
158:            }
159:
160:            // basic check to see that we print out eras ok
161:            // eventually should modify to use locale strings and formatter appropriate to coptic calendar
162:            public void TestEraStart() {
163:                CopticCalendar cal = new CopticCalendar(0, 0, 1);
164:                SimpleDateFormat fmt = new SimpleDateFormat(
165:                        "EEE MMM dd, yyyy GG");
166:                assertEquals("Coptic Date", "Thu Jan 01, 0000 AD", fmt
167:                        .format(cal));
168:                assertEquals("Gregorian Date", "Thu Aug 30, 0283 AD", fmt
169:                        .format(cal.getTime()));
170:            }
171:
172:            public void TestBasic() {
173:                CopticCalendar cal = new CopticCalendar();
174:                cal.clear();
175:                cal.set(1000, 0, 30);
176:                logln("1000/0/30-> " + cal.get(YEAR) + "/" + cal.get(MONTH)
177:                        + "/" + cal.get(DATE));
178:                cal.clear();
179:                cal.set(1, 0, 30);
180:                logln("1/0/30 -> " + cal.get(YEAR) + "/" + cal.get(MONTH) + "/"
181:                        + cal.get(DATE));
182:            }
183:
184:            public void TestCoverage() {
185:
186:                {
187:                    // new CopticCalendar(TimeZone)
188:                    CopticCalendar cal = new CopticCalendar(TimeZone
189:                            .getDefault());
190:                    if (cal == null) {
191:                        errln("could not create CopticCalendar with TimeZone");
192:                    }
193:                }
194:
195:                {
196:                    // new CopticCalendar(ULocale)
197:                    CopticCalendar cal = new CopticCalendar(ULocale
198:                            .getDefault());
199:                    if (cal == null) {
200:                        errln("could not create CopticCalendar with ULocale");
201:                    }
202:                }
203:
204:                {
205:                    // new CopticCalendar(Locale)
206:                    CopticCalendar cal = new CopticCalendar(Locale.getDefault());
207:                    if (cal == null) {
208:                        errln("could not create CopticCalendar with Locale");
209:                    }
210:                }
211:
212:                {
213:                    // new CopticCalendar(TimeZone, Locale)                                             
214:                    CopticCalendar cal = new CopticCalendar(TimeZone
215:                            .getDefault(), Locale.getDefault());
216:                    if (cal == null) {
217:                        errln("could not create CopticCalendar with TimeZone, Locale");
218:                    }
219:                }
220:
221:                {
222:                    // new CopticCalendar(TimeZone, ULocale)                                            
223:                    CopticCalendar cal = new CopticCalendar(TimeZone
224:                            .getDefault(), ULocale.getDefault());
225:                    if (cal == null) {
226:                        errln("could not create CopticCalendar with TimeZone, ULocale");
227:                    }
228:                }
229:
230:                {
231:                    // new CopticCalendar(Date)
232:                    CopticCalendar cal = new CopticCalendar(new Date());
233:                    if (cal == null) {
234:                        errln("could not create CopticCalendar with Date");
235:                    }
236:                }
237:
238:                {
239:                    // new CopticCalendar(int year, int month, int date)
240:                    CopticCalendar cal = new CopticCalendar(1997,
241:                            CopticCalendar.TOUT, 1);
242:                    if (cal == null) {
243:                        errln("could not create CopticCalendar with year,month,date");
244:                    }
245:                }
246:
247:                {
248:                    // new CopticCalendar(int year, int month, int date, int hour, int minute, int second)
249:                    CopticCalendar cal = new CopticCalendar(1997,
250:                            CopticCalendar.TOUT, 1, 1, 1, 1);
251:                    if (cal == null) {
252:                        errln("could not create CopticCalendar with year,month,date,hour,minute,second");
253:                    }
254:                }
255:
256:                {
257:                    // data
258:                    CopticCalendar cal = new CopticCalendar(1997,
259:                            CopticCalendar.TOUT, 1);
260:                    Date time = cal.getTime();
261:
262:                    String[] calendarLocales = { "am_ET", "gez_ET", "ti_ET" };
263:
264:                    String[] formatLocales = { "en", "am", "am_ET", "gez", "ti" };
265:                    for (int i = 0; i < calendarLocales.length; ++i) {
266:                        String calLocName = calendarLocales[i];
267:                        Locale calLocale = LocaleUtility
268:                                .getLocaleFromName(calLocName);
269:                        cal = new CopticCalendar(calLocale);
270:
271:                        for (int j = 0; j < formatLocales.length; ++j) {
272:                            String locName = formatLocales[j];
273:                            Locale formatLocale = LocaleUtility
274:                                    .getLocaleFromName(locName);
275:                            DateFormat format = DateFormat.getDateTimeInstance(
276:                                    cal, DateFormat.FULL, DateFormat.FULL,
277:                                    formatLocale);
278:                            logln(calLocName + "/" + locName + " --> "
279:                                    + format.format(time));
280:                        }
281:                    }
282:                }
283:            }
284:
285:            public void TestYear() {
286:                // Gregorian Calendar
287:                Calendar gCal = new GregorianCalendar();
288:                Date gToday = gCal.getTime();
289:                gCal.add(GregorianCalendar.MONTH, 2);
290:                Date gFuture = gCal.getTime();
291:                DateFormat gDF = DateFormat.getDateInstance(gCal,
292:                        DateFormat.FULL);
293:                logln("gregorian calendar: " + gDF.format(gToday)
294:                        + " + 2 months = " + gDF.format(gFuture));
295:
296:                // Coptic Calendar
297:                CopticCalendar cCal = new CopticCalendar();
298:                Date cToday = cCal.getTime();
299:                cCal.add(CopticCalendar.MONTH, 2);
300:                Date cFuture = cCal.getTime();
301:                DateFormat cDF = DateFormat.getDateInstance(cCal,
302:                        DateFormat.FULL);
303:                logln("coptic calendar: " + cDF.format(cToday)
304:                        + " + 2 months = " + cDF.format(cFuture));
305:
306:                // EthiopicCalendar
307:                EthiopicCalendar eCal = new EthiopicCalendar();
308:                Date eToday = eCal.getTime();
309:                eCal.add(EthiopicCalendar.MONTH, 2); // add 2 months
310:                eCal.setAmeteAlemEra(false);
311:                Date eFuture = eCal.getTime();
312:                DateFormat eDF = DateFormat.getDateInstance(eCal,
313:                        DateFormat.FULL);
314:                logln("ethiopic calendar: " + eDF.format(eToday)
315:                        + " + 2 months = " + eDF.format(eFuture));
316:            }
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.