Source Code Cross Referenced for TestCopticChronology.java in  » Development » Joda-Time » org » joda » time » chrono » 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 » Development » Joda Time » org.joda.time.chrono 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2005 Stephen Colebourne
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.joda.time.chrono;
017:
018:        import java.util.Locale;
019:        import java.util.TimeZone;
020:
021:        import junit.framework.TestCase;
022:        import junit.framework.TestSuite;
023:
024:        import org.joda.time.Chronology;
025:        import org.joda.time.DateTime;
026:        import org.joda.time.DateTimeConstants;
027:        import org.joda.time.DateTimeField;
028:        import org.joda.time.DateTimeUtils;
029:        import org.joda.time.DateTimeZone;
030:        import org.joda.time.DurationField;
031:        import org.joda.time.DurationFieldType;
032:        import org.joda.time.DateTime.Property;
033:
034:        /**
035:         * This class is a Junit unit test for CopticChronology.
036:         *
037:         * @author Stephen Colebourne
038:         */
039:        public class TestCopticChronology extends TestCase {
040:
041:            private static final int MILLIS_PER_DAY = DateTimeConstants.MILLIS_PER_DAY;
042:
043:            private static long SKIP = 1 * MILLIS_PER_DAY;
044:
045:            private static final DateTimeZone PARIS = DateTimeZone
046:                    .forID("Europe/Paris");
047:            private static final DateTimeZone LONDON = DateTimeZone
048:                    .forID("Europe/London");
049:            private static final DateTimeZone TOKYO = DateTimeZone
050:                    .forID("Asia/Tokyo");
051:            private static final Chronology COPTIC_UTC = CopticChronology
052:                    .getInstanceUTC();
053:            private static final Chronology JULIAN_UTC = JulianChronology
054:                    .getInstanceUTC();
055:            private static final Chronology ISO_UTC = ISOChronology
056:                    .getInstanceUTC();
057:
058:            long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
059:                    + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
060:                    + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
061:                    + 365 + 365 + 366 + 365;
062:            // 2002-06-09
063:            private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L
064:                    + 31L + 9L - 1L)
065:                    * MILLIS_PER_DAY;
066:
067:            private DateTimeZone originalDateTimeZone = null;
068:            private TimeZone originalTimeZone = null;
069:            private Locale originalLocale = null;
070:
071:            public static void main(String[] args) {
072:                junit.textui.TestRunner.run(suite());
073:            }
074:
075:            public static TestSuite suite() {
076:                SKIP = 1 * MILLIS_PER_DAY;
077:                return new TestSuite(TestCopticChronology.class);
078:            }
079:
080:            public TestCopticChronology(String name) {
081:                super (name);
082:            }
083:
084:            protected void setUp() throws Exception {
085:                DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
086:                originalDateTimeZone = DateTimeZone.getDefault();
087:                originalTimeZone = TimeZone.getDefault();
088:                originalLocale = Locale.getDefault();
089:                DateTimeZone.setDefault(LONDON);
090:                TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
091:                Locale.setDefault(Locale.UK);
092:            }
093:
094:            protected void tearDown() throws Exception {
095:                DateTimeUtils.setCurrentMillisSystem();
096:                DateTimeZone.setDefault(originalDateTimeZone);
097:                TimeZone.setDefault(originalTimeZone);
098:                Locale.setDefault(originalLocale);
099:                originalDateTimeZone = null;
100:                originalTimeZone = null;
101:                originalLocale = null;
102:            }
103:
104:            //-----------------------------------------------------------------------
105:            public void testFactoryUTC() {
106:                assertEquals(DateTimeZone.UTC, CopticChronology
107:                        .getInstanceUTC().getZone());
108:                assertSame(CopticChronology.class, CopticChronology
109:                        .getInstanceUTC().getClass());
110:            }
111:
112:            public void testFactory() {
113:                assertEquals(LONDON, CopticChronology.getInstance().getZone());
114:                assertSame(CopticChronology.class, CopticChronology
115:                        .getInstance().getClass());
116:            }
117:
118:            public void testFactory_Zone() {
119:                assertEquals(TOKYO, CopticChronology.getInstance(TOKYO)
120:                        .getZone());
121:                assertEquals(PARIS, CopticChronology.getInstance(PARIS)
122:                        .getZone());
123:                assertEquals(LONDON, CopticChronology.getInstance(null)
124:                        .getZone());
125:                assertSame(CopticChronology.class, CopticChronology
126:                        .getInstance(TOKYO).getClass());
127:            }
128:
129:            //-----------------------------------------------------------------------
130:            public void testEquality() {
131:                assertSame(CopticChronology.getInstance(TOKYO),
132:                        CopticChronology.getInstance(TOKYO));
133:                assertSame(CopticChronology.getInstance(LONDON),
134:                        CopticChronology.getInstance(LONDON));
135:                assertSame(CopticChronology.getInstance(PARIS),
136:                        CopticChronology.getInstance(PARIS));
137:                assertSame(CopticChronology.getInstanceUTC(), CopticChronology
138:                        .getInstanceUTC());
139:                assertSame(CopticChronology.getInstance(), CopticChronology
140:                        .getInstance(LONDON));
141:            }
142:
143:            public void testWithUTC() {
144:                assertSame(CopticChronology.getInstanceUTC(), CopticChronology
145:                        .getInstance(LONDON).withUTC());
146:                assertSame(CopticChronology.getInstanceUTC(), CopticChronology
147:                        .getInstance(TOKYO).withUTC());
148:                assertSame(CopticChronology.getInstanceUTC(), CopticChronology
149:                        .getInstanceUTC().withUTC());
150:                assertSame(CopticChronology.getInstanceUTC(), CopticChronology
151:                        .getInstance().withUTC());
152:            }
153:
154:            public void testWithZone() {
155:                assertSame(CopticChronology.getInstance(TOKYO),
156:                        CopticChronology.getInstance(TOKYO).withZone(TOKYO));
157:                assertSame(CopticChronology.getInstance(LONDON),
158:                        CopticChronology.getInstance(TOKYO).withZone(LONDON));
159:                assertSame(CopticChronology.getInstance(PARIS),
160:                        CopticChronology.getInstance(TOKYO).withZone(PARIS));
161:                assertSame(CopticChronology.getInstance(LONDON),
162:                        CopticChronology.getInstance(TOKYO).withZone(null));
163:                assertSame(CopticChronology.getInstance(PARIS),
164:                        CopticChronology.getInstance().withZone(PARIS));
165:                assertSame(CopticChronology.getInstance(PARIS),
166:                        CopticChronology.getInstanceUTC().withZone(PARIS));
167:            }
168:
169:            public void testToString() {
170:                assertEquals("CopticChronology[Europe/London]",
171:                        CopticChronology.getInstance(LONDON).toString());
172:                assertEquals("CopticChronology[Asia/Tokyo]", CopticChronology
173:                        .getInstance(TOKYO).toString());
174:                assertEquals("CopticChronology[Europe/London]",
175:                        CopticChronology.getInstance().toString());
176:                assertEquals("CopticChronology[UTC]", CopticChronology
177:                        .getInstanceUTC().toString());
178:            }
179:
180:            //-----------------------------------------------------------------------
181:            public void testDurationFields() {
182:                assertEquals("eras", CopticChronology.getInstance().eras()
183:                        .getName());
184:                assertEquals("centuries", CopticChronology.getInstance()
185:                        .centuries().getName());
186:                assertEquals("years", CopticChronology.getInstance().years()
187:                        .getName());
188:                assertEquals("weekyears", CopticChronology.getInstance()
189:                        .weekyears().getName());
190:                assertEquals("months", CopticChronology.getInstance().months()
191:                        .getName());
192:                assertEquals("weeks", CopticChronology.getInstance().weeks()
193:                        .getName());
194:                assertEquals("days", CopticChronology.getInstance().days()
195:                        .getName());
196:                assertEquals("halfdays", CopticChronology.getInstance()
197:                        .halfdays().getName());
198:                assertEquals("hours", CopticChronology.getInstance().hours()
199:                        .getName());
200:                assertEquals("minutes", CopticChronology.getInstance()
201:                        .minutes().getName());
202:                assertEquals("seconds", CopticChronology.getInstance()
203:                        .seconds().getName());
204:                assertEquals("millis", CopticChronology.getInstance().millis()
205:                        .getName());
206:
207:                assertEquals(false, CopticChronology.getInstance().eras()
208:                        .isSupported());
209:                assertEquals(true, CopticChronology.getInstance().centuries()
210:                        .isSupported());
211:                assertEquals(true, CopticChronology.getInstance().years()
212:                        .isSupported());
213:                assertEquals(true, CopticChronology.getInstance().weekyears()
214:                        .isSupported());
215:                assertEquals(true, CopticChronology.getInstance().months()
216:                        .isSupported());
217:                assertEquals(true, CopticChronology.getInstance().weeks()
218:                        .isSupported());
219:                assertEquals(true, CopticChronology.getInstance().days()
220:                        .isSupported());
221:                assertEquals(true, CopticChronology.getInstance().halfdays()
222:                        .isSupported());
223:                assertEquals(true, CopticChronology.getInstance().hours()
224:                        .isSupported());
225:                assertEquals(true, CopticChronology.getInstance().minutes()
226:                        .isSupported());
227:                assertEquals(true, CopticChronology.getInstance().seconds()
228:                        .isSupported());
229:                assertEquals(true, CopticChronology.getInstance().millis()
230:                        .isSupported());
231:
232:                assertEquals(false, CopticChronology.getInstance().centuries()
233:                        .isPrecise());
234:                assertEquals(false, CopticChronology.getInstance().years()
235:                        .isPrecise());
236:                assertEquals(false, CopticChronology.getInstance().weekyears()
237:                        .isPrecise());
238:                assertEquals(false, CopticChronology.getInstance().months()
239:                        .isPrecise());
240:                assertEquals(false, CopticChronology.getInstance().weeks()
241:                        .isPrecise());
242:                assertEquals(false, CopticChronology.getInstance().days()
243:                        .isPrecise());
244:                assertEquals(false, CopticChronology.getInstance().halfdays()
245:                        .isPrecise());
246:                assertEquals(true, CopticChronology.getInstance().hours()
247:                        .isPrecise());
248:                assertEquals(true, CopticChronology.getInstance().minutes()
249:                        .isPrecise());
250:                assertEquals(true, CopticChronology.getInstance().seconds()
251:                        .isPrecise());
252:                assertEquals(true, CopticChronology.getInstance().millis()
253:                        .isPrecise());
254:
255:                assertEquals(false, CopticChronology.getInstanceUTC()
256:                        .centuries().isPrecise());
257:                assertEquals(false, CopticChronology.getInstanceUTC().years()
258:                        .isPrecise());
259:                assertEquals(false, CopticChronology.getInstanceUTC()
260:                        .weekyears().isPrecise());
261:                assertEquals(false, CopticChronology.getInstanceUTC().months()
262:                        .isPrecise());
263:                assertEquals(true, CopticChronology.getInstanceUTC().weeks()
264:                        .isPrecise());
265:                assertEquals(true, CopticChronology.getInstanceUTC().days()
266:                        .isPrecise());
267:                assertEquals(true, CopticChronology.getInstanceUTC().halfdays()
268:                        .isPrecise());
269:                assertEquals(true, CopticChronology.getInstanceUTC().hours()
270:                        .isPrecise());
271:                assertEquals(true, CopticChronology.getInstanceUTC().minutes()
272:                        .isPrecise());
273:                assertEquals(true, CopticChronology.getInstanceUTC().seconds()
274:                        .isPrecise());
275:                assertEquals(true, CopticChronology.getInstanceUTC().millis()
276:                        .isPrecise());
277:            }
278:
279:            public void testDateFields() {
280:                assertEquals("era", CopticChronology.getInstance().era()
281:                        .getName());
282:                assertEquals("centuryOfEra", CopticChronology.getInstance()
283:                        .centuryOfEra().getName());
284:                assertEquals("yearOfCentury", CopticChronology.getInstance()
285:                        .yearOfCentury().getName());
286:                assertEquals("yearOfEra", CopticChronology.getInstance()
287:                        .yearOfEra().getName());
288:                assertEquals("year", CopticChronology.getInstance().year()
289:                        .getName());
290:                assertEquals("monthOfYear", CopticChronology.getInstance()
291:                        .monthOfYear().getName());
292:                assertEquals("weekyearOfCentury", CopticChronology
293:                        .getInstance().weekyearOfCentury().getName());
294:                assertEquals("weekyear", CopticChronology.getInstance()
295:                        .weekyear().getName());
296:                assertEquals("weekOfWeekyear", CopticChronology.getInstance()
297:                        .weekOfWeekyear().getName());
298:                assertEquals("dayOfYear", CopticChronology.getInstance()
299:                        .dayOfYear().getName());
300:                assertEquals("dayOfMonth", CopticChronology.getInstance()
301:                        .dayOfMonth().getName());
302:                assertEquals("dayOfWeek", CopticChronology.getInstance()
303:                        .dayOfWeek().getName());
304:
305:                assertEquals(true, CopticChronology.getInstance().era()
306:                        .isSupported());
307:                assertEquals(true, CopticChronology.getInstance()
308:                        .centuryOfEra().isSupported());
309:                assertEquals(true, CopticChronology.getInstance()
310:                        .yearOfCentury().isSupported());
311:                assertEquals(true, CopticChronology.getInstance().yearOfEra()
312:                        .isSupported());
313:                assertEquals(true, CopticChronology.getInstance().year()
314:                        .isSupported());
315:                assertEquals(true, CopticChronology.getInstance().monthOfYear()
316:                        .isSupported());
317:                assertEquals(true, CopticChronology.getInstance()
318:                        .weekyearOfCentury().isSupported());
319:                assertEquals(true, CopticChronology.getInstance().weekyear()
320:                        .isSupported());
321:                assertEquals(true, CopticChronology.getInstance()
322:                        .weekOfWeekyear().isSupported());
323:                assertEquals(true, CopticChronology.getInstance().dayOfYear()
324:                        .isSupported());
325:                assertEquals(true, CopticChronology.getInstance().dayOfMonth()
326:                        .isSupported());
327:                assertEquals(true, CopticChronology.getInstance().dayOfWeek()
328:                        .isSupported());
329:            }
330:
331:            public void testTimeFields() {
332:                assertEquals("halfdayOfDay", CopticChronology.getInstance()
333:                        .halfdayOfDay().getName());
334:                assertEquals("clockhourOfHalfday", CopticChronology
335:                        .getInstance().clockhourOfHalfday().getName());
336:                assertEquals("hourOfHalfday", CopticChronology.getInstance()
337:                        .hourOfHalfday().getName());
338:                assertEquals("clockhourOfDay", CopticChronology.getInstance()
339:                        .clockhourOfDay().getName());
340:                assertEquals("hourOfDay", CopticChronology.getInstance()
341:                        .hourOfDay().getName());
342:                assertEquals("minuteOfDay", CopticChronology.getInstance()
343:                        .minuteOfDay().getName());
344:                assertEquals("minuteOfHour", CopticChronology.getInstance()
345:                        .minuteOfHour().getName());
346:                assertEquals("secondOfDay", CopticChronology.getInstance()
347:                        .secondOfDay().getName());
348:                assertEquals("secondOfMinute", CopticChronology.getInstance()
349:                        .secondOfMinute().getName());
350:                assertEquals("millisOfDay", CopticChronology.getInstance()
351:                        .millisOfDay().getName());
352:                assertEquals("millisOfSecond", CopticChronology.getInstance()
353:                        .millisOfSecond().getName());
354:
355:                assertEquals(true, CopticChronology.getInstance()
356:                        .halfdayOfDay().isSupported());
357:                assertEquals(true, CopticChronology.getInstance()
358:                        .clockhourOfHalfday().isSupported());
359:                assertEquals(true, CopticChronology.getInstance()
360:                        .hourOfHalfday().isSupported());
361:                assertEquals(true, CopticChronology.getInstance()
362:                        .clockhourOfDay().isSupported());
363:                assertEquals(true, CopticChronology.getInstance().hourOfDay()
364:                        .isSupported());
365:                assertEquals(true, CopticChronology.getInstance().minuteOfDay()
366:                        .isSupported());
367:                assertEquals(true, CopticChronology.getInstance()
368:                        .minuteOfHour().isSupported());
369:                assertEquals(true, CopticChronology.getInstance().secondOfDay()
370:                        .isSupported());
371:                assertEquals(true, CopticChronology.getInstance()
372:                        .secondOfMinute().isSupported());
373:                assertEquals(true, CopticChronology.getInstance().millisOfDay()
374:                        .isSupported());
375:                assertEquals(true, CopticChronology.getInstance()
376:                        .millisOfSecond().isSupported());
377:            }
378:
379:            //-----------------------------------------------------------------------
380:            public void testEpoch() {
381:                DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, COPTIC_UTC);
382:                assertEquals(new DateTime(284, 8, 29, 0, 0, 0, 0, JULIAN_UTC),
383:                        epoch.withChronology(JULIAN_UTC));
384:            }
385:
386:            public void testEra() {
387:                assertEquals(1, CopticChronology.AM);
388:                try {
389:                    new DateTime(-1, 13, 5, 0, 0, 0, 0, COPTIC_UTC);
390:                    fail();
391:                } catch (IllegalArgumentException ex) {
392:                }
393:            }
394:
395:            //-----------------------------------------------------------------------
396:            /**
397:             * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek.
398:             */
399:            public void testCalendar() {
400:                if (TestAll.FAST) {
401:                    return;
402:                }
403:                System.out.println("\nTestCopticChronology.testCalendar");
404:                DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, COPTIC_UTC);
405:                long millis = epoch.getMillis();
406:                long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC)
407:                        .getMillis();
408:                DateTimeField dayOfWeek = COPTIC_UTC.dayOfWeek();
409:                DateTimeField dayOfYear = COPTIC_UTC.dayOfYear();
410:                DateTimeField dayOfMonth = COPTIC_UTC.dayOfMonth();
411:                DateTimeField monthOfYear = COPTIC_UTC.monthOfYear();
412:                DateTimeField year = COPTIC_UTC.year();
413:                DateTimeField yearOfEra = COPTIC_UTC.yearOfEra();
414:                DateTimeField era = COPTIC_UTC.era();
415:                int expectedDOW = new DateTime(284, 8, 29, 0, 0, 0, 0,
416:                        JULIAN_UTC).getDayOfWeek();
417:                int expectedDOY = 1;
418:                int expectedDay = 1;
419:                int expectedMonth = 1;
420:                int expectedYear = 1;
421:                while (millis < end) {
422:                    int dowValue = dayOfWeek.get(millis);
423:                    int doyValue = dayOfYear.get(millis);
424:                    int dayValue = dayOfMonth.get(millis);
425:                    int monthValue = monthOfYear.get(millis);
426:                    int yearValue = year.get(millis);
427:                    int yearOfEraValue = yearOfEra.get(millis);
428:                    int monthLen = dayOfMonth.getMaximumValue(millis);
429:                    if (monthValue < 1 || monthValue > 13) {
430:                        fail("Bad month: " + millis);
431:                    }
432:
433:                    // test era
434:                    assertEquals(1, era.get(millis));
435:                    assertEquals("AM", era.getAsText(millis));
436:                    assertEquals("AM", era.getAsShortText(millis));
437:
438:                    // test date
439:                    assertEquals(expectedYear, yearValue);
440:                    assertEquals(expectedYear, yearOfEraValue);
441:                    assertEquals(expectedMonth, monthValue);
442:                    assertEquals(expectedDay, dayValue);
443:                    assertEquals(expectedDOW, dowValue);
444:                    assertEquals(expectedDOY, doyValue);
445:
446:                    // test leap year
447:                    assertEquals(yearValue % 4 == 3, year.isLeap(millis));
448:
449:                    // test month length
450:                    if (monthValue == 13) {
451:                        assertEquals(yearValue % 4 == 3, monthOfYear
452:                                .isLeap(millis));
453:                        if (yearValue % 4 == 3) {
454:                            assertEquals(6, monthLen);
455:                        } else {
456:                            assertEquals(5, monthLen);
457:                        }
458:                    } else {
459:                        assertEquals(30, monthLen);
460:                    }
461:
462:                    // recalculate date
463:                    expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1;
464:                    expectedDay++;
465:                    expectedDOY++;
466:                    if (expectedDay == 31 && expectedMonth < 13) {
467:                        expectedDay = 1;
468:                        expectedMonth++;
469:                    } else if (expectedMonth == 13) {
470:                        if (expectedYear % 4 == 3 && expectedDay == 7) {
471:                            expectedDay = 1;
472:                            expectedMonth = 1;
473:                            expectedYear++;
474:                            expectedDOY = 1;
475:                        } else if (expectedYear % 4 != 3 && expectedDay == 6) {
476:                            expectedDay = 1;
477:                            expectedMonth = 1;
478:                            expectedYear++;
479:                            expectedDOY = 1;
480:                        }
481:                    }
482:                    millis += SKIP;
483:                }
484:            }
485:
486:            public void testSampleDate() {
487:                DateTime dt = new DateTime(2004, 6, 9, 0, 0, 0, 0, ISO_UTC)
488:                        .withChronology(COPTIC_UTC);
489:                assertEquals(CopticChronology.AM, dt.getEra());
490:                assertEquals(18, dt.getCenturyOfEra()); // TODO confirm
491:                assertEquals(20, dt.getYearOfCentury());
492:                assertEquals(1720, dt.getYearOfEra());
493:
494:                assertEquals(1720, dt.getYear());
495:                Property fld = dt.year();
496:                assertEquals(false, fld.isLeap());
497:                assertEquals(0, fld.getLeapAmount());
498:                assertEquals(DurationFieldType.days(), fld
499:                        .getLeapDurationField().getType());
500:                assertEquals(new DateTime(1721, 10, 2, 0, 0, 0, 0, COPTIC_UTC),
501:                        fld.addToCopy(1));
502:
503:                assertEquals(10, dt.getMonthOfYear());
504:                fld = dt.monthOfYear();
505:                assertEquals(false, fld.isLeap());
506:                assertEquals(0, fld.getLeapAmount());
507:                assertEquals(DurationFieldType.days(), fld
508:                        .getLeapDurationField().getType());
509:                assertEquals(1, fld.getMinimumValue());
510:                assertEquals(1, fld.getMinimumValueOverall());
511:                assertEquals(13, fld.getMaximumValue());
512:                assertEquals(13, fld.getMaximumValueOverall());
513:                assertEquals(new DateTime(1721, 1, 2, 0, 0, 0, 0, COPTIC_UTC),
514:                        fld.addToCopy(4));
515:                assertEquals(new DateTime(1720, 1, 2, 0, 0, 0, 0, COPTIC_UTC),
516:                        fld.addWrapFieldToCopy(4));
517:
518:                assertEquals(2, dt.getDayOfMonth());
519:                fld = dt.dayOfMonth();
520:                assertEquals(false, fld.isLeap());
521:                assertEquals(0, fld.getLeapAmount());
522:                assertEquals(null, fld.getLeapDurationField());
523:                assertEquals(1, fld.getMinimumValue());
524:                assertEquals(1, fld.getMinimumValueOverall());
525:                assertEquals(30, fld.getMaximumValue());
526:                assertEquals(30, fld.getMaximumValueOverall());
527:                assertEquals(new DateTime(1720, 10, 3, 0, 0, 0, 0, COPTIC_UTC),
528:                        fld.addToCopy(1));
529:
530:                assertEquals(DateTimeConstants.WEDNESDAY, dt.getDayOfWeek());
531:                fld = dt.dayOfWeek();
532:                assertEquals(false, fld.isLeap());
533:                assertEquals(0, fld.getLeapAmount());
534:                assertEquals(null, fld.getLeapDurationField());
535:                assertEquals(1, fld.getMinimumValue());
536:                assertEquals(1, fld.getMinimumValueOverall());
537:                assertEquals(7, fld.getMaximumValue());
538:                assertEquals(7, fld.getMaximumValueOverall());
539:                assertEquals(new DateTime(1720, 10, 3, 0, 0, 0, 0, COPTIC_UTC),
540:                        fld.addToCopy(1));
541:
542:                assertEquals(9 * 30 + 2, dt.getDayOfYear());
543:                fld = dt.dayOfYear();
544:                assertEquals(false, fld.isLeap());
545:                assertEquals(0, fld.getLeapAmount());
546:                assertEquals(null, fld.getLeapDurationField());
547:                assertEquals(1, fld.getMinimumValue());
548:                assertEquals(1, fld.getMinimumValueOverall());
549:                assertEquals(365, fld.getMaximumValue());
550:                assertEquals(366, fld.getMaximumValueOverall());
551:                assertEquals(new DateTime(1720, 10, 3, 0, 0, 0, 0, COPTIC_UTC),
552:                        fld.addToCopy(1));
553:
554:                assertEquals(0, dt.getHourOfDay());
555:                assertEquals(0, dt.getMinuteOfHour());
556:                assertEquals(0, dt.getSecondOfMinute());
557:                assertEquals(0, dt.getMillisOfSecond());
558:            }
559:
560:            public void testSampleDateWithZone() {
561:                DateTime dt = new DateTime(2004, 6, 9, 12, 0, 0, 0, PARIS)
562:                        .withChronology(COPTIC_UTC);
563:                assertEquals(CopticChronology.AM, dt.getEra());
564:                assertEquals(1720, dt.getYear());
565:                assertEquals(1720, dt.getYearOfEra());
566:                assertEquals(10, dt.getMonthOfYear());
567:                assertEquals(2, dt.getDayOfMonth());
568:                assertEquals(10, dt.getHourOfDay()); // PARIS is UTC+2 in summer (12-2=10)
569:                assertEquals(0, dt.getMinuteOfHour());
570:                assertEquals(0, dt.getSecondOfMinute());
571:                assertEquals(0, dt.getMillisOfSecond());
572:            }
573:
574:            public void testDurationYear() {
575:                // Leap 1723
576:                DateTime dt20 = new DateTime(1720, 10, 2, 0, 0, 0, 0,
577:                        COPTIC_UTC);
578:                DateTime dt21 = new DateTime(1721, 10, 2, 0, 0, 0, 0,
579:                        COPTIC_UTC);
580:                DateTime dt22 = new DateTime(1722, 10, 2, 0, 0, 0, 0,
581:                        COPTIC_UTC);
582:                DateTime dt23 = new DateTime(1723, 10, 2, 0, 0, 0, 0,
583:                        COPTIC_UTC);
584:                DateTime dt24 = new DateTime(1724, 10, 2, 0, 0, 0, 0,
585:                        COPTIC_UTC);
586:
587:                DurationField fld = dt20.year().getDurationField();
588:                assertEquals(COPTIC_UTC.years(), fld);
589:                assertEquals(1L * 365L * MILLIS_PER_DAY, fld.getMillis(1, dt20
590:                        .getMillis()));
591:                assertEquals(2L * 365L * MILLIS_PER_DAY, fld.getMillis(2, dt20
592:                        .getMillis()));
593:                assertEquals(3L * 365L * MILLIS_PER_DAY, fld.getMillis(3, dt20
594:                        .getMillis()));
595:                assertEquals((4L * 365L + 1L) * MILLIS_PER_DAY, fld.getMillis(
596:                        4, dt20.getMillis()));
597:
598:                assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 4, fld
599:                        .getMillis(1));
600:                assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 2, fld
601:                        .getMillis(2));
602:
603:                assertEquals(1L * 365L * MILLIS_PER_DAY, fld.getMillis(1L, dt20
604:                        .getMillis()));
605:                assertEquals(2L * 365L * MILLIS_PER_DAY, fld.getMillis(2L, dt20
606:                        .getMillis()));
607:                assertEquals(3L * 365L * MILLIS_PER_DAY, fld.getMillis(3L, dt20
608:                        .getMillis()));
609:                assertEquals((4L * 365L + 1L) * MILLIS_PER_DAY, fld.getMillis(
610:                        4L, dt20.getMillis()));
611:
612:                assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 4, fld
613:                        .getMillis(1L));
614:                assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 2, fld
615:                        .getMillis(2L));
616:
617:                assertEquals(((4L * 365L + 1L) * MILLIS_PER_DAY) / 4, fld
618:                        .getUnitMillis());
619:
620:                assertEquals(0, fld.getValue(1L * 365L * MILLIS_PER_DAY - 1L,
621:                        dt20.getMillis()));
622:                assertEquals(1, fld.getValue(1L * 365L * MILLIS_PER_DAY, dt20
623:                        .getMillis()));
624:                assertEquals(1, fld.getValue(1L * 365L * MILLIS_PER_DAY + 1L,
625:                        dt20.getMillis()));
626:                assertEquals(1, fld.getValue(2L * 365L * MILLIS_PER_DAY - 1L,
627:                        dt20.getMillis()));
628:                assertEquals(2, fld.getValue(2L * 365L * MILLIS_PER_DAY, dt20
629:                        .getMillis()));
630:                assertEquals(2, fld.getValue(2L * 365L * MILLIS_PER_DAY + 1L,
631:                        dt20.getMillis()));
632:                assertEquals(2, fld.getValue(3L * 365L * MILLIS_PER_DAY - 1L,
633:                        dt20.getMillis()));
634:                assertEquals(3, fld.getValue(3L * 365L * MILLIS_PER_DAY, dt20
635:                        .getMillis()));
636:                assertEquals(3, fld.getValue(3L * 365L * MILLIS_PER_DAY + 1L,
637:                        dt20.getMillis()));
638:                assertEquals(3, fld.getValue((4L * 365L + 1L) * MILLIS_PER_DAY
639:                        - 1L, dt20.getMillis()));
640:                assertEquals(4, fld.getValue((4L * 365L + 1L) * MILLIS_PER_DAY,
641:                        dt20.getMillis()));
642:                assertEquals(4, fld.getValue((4L * 365L + 1L) * MILLIS_PER_DAY
643:                        + 1L, dt20.getMillis()));
644:
645:                assertEquals(dt21.getMillis(), fld.add(dt20.getMillis(), 1));
646:                assertEquals(dt22.getMillis(), fld.add(dt20.getMillis(), 2));
647:                assertEquals(dt23.getMillis(), fld.add(dt20.getMillis(), 3));
648:                assertEquals(dt24.getMillis(), fld.add(dt20.getMillis(), 4));
649:
650:                assertEquals(dt21.getMillis(), fld.add(dt20.getMillis(), 1L));
651:                assertEquals(dt22.getMillis(), fld.add(dt20.getMillis(), 2L));
652:                assertEquals(dt23.getMillis(), fld.add(dt20.getMillis(), 3L));
653:                assertEquals(dt24.getMillis(), fld.add(dt20.getMillis(), 4L));
654:            }
655:
656:            public void testDurationMonth() {
657:                // Leap 1723
658:                DateTime dt11 = new DateTime(1723, 11, 2, 0, 0, 0, 0,
659:                        COPTIC_UTC);
660:                DateTime dt12 = new DateTime(1723, 12, 2, 0, 0, 0, 0,
661:                        COPTIC_UTC);
662:                DateTime dt13 = new DateTime(1723, 13, 2, 0, 0, 0, 0,
663:                        COPTIC_UTC);
664:                DateTime dt01 = new DateTime(1724, 1, 2, 0, 0, 0, 0, COPTIC_UTC);
665:
666:                DurationField fld = dt11.monthOfYear().getDurationField();
667:                assertEquals(COPTIC_UTC.months(), fld);
668:                assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1, dt11
669:                        .getMillis()));
670:                assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2, dt11
671:                        .getMillis()));
672:                assertEquals((2L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(3,
673:                        dt11.getMillis()));
674:                assertEquals((3L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(4,
675:                        dt11.getMillis()));
676:
677:                assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1));
678:                assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2));
679:                assertEquals(13L * 30L * MILLIS_PER_DAY, fld.getMillis(13));
680:
681:                assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1L, dt11
682:                        .getMillis()));
683:                assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2L, dt11
684:                        .getMillis()));
685:                assertEquals((2L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(
686:                        3L, dt11.getMillis()));
687:                assertEquals((3L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(
688:                        4L, dt11.getMillis()));
689:
690:                assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1L));
691:                assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2L));
692:                assertEquals(13L * 30L * MILLIS_PER_DAY, fld.getMillis(13L));
693:
694:                assertEquals(0, fld.getValue(1L * 30L * MILLIS_PER_DAY - 1L,
695:                        dt11.getMillis()));
696:                assertEquals(1, fld.getValue(1L * 30L * MILLIS_PER_DAY, dt11
697:                        .getMillis()));
698:                assertEquals(1, fld.getValue(1L * 30L * MILLIS_PER_DAY + 1L,
699:                        dt11.getMillis()));
700:                assertEquals(1, fld.getValue(2L * 30L * MILLIS_PER_DAY - 1L,
701:                        dt11.getMillis()));
702:                assertEquals(2, fld.getValue(2L * 30L * MILLIS_PER_DAY, dt11
703:                        .getMillis()));
704:                assertEquals(2, fld.getValue(2L * 30L * MILLIS_PER_DAY + 1L,
705:                        dt11.getMillis()));
706:                assertEquals(2, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY
707:                        - 1L, dt11.getMillis()));
708:                assertEquals(3, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY,
709:                        dt11.getMillis()));
710:                assertEquals(3, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY
711:                        + 1L, dt11.getMillis()));
712:                assertEquals(3, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY
713:                        - 1L, dt11.getMillis()));
714:                assertEquals(4, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY,
715:                        dt11.getMillis()));
716:                assertEquals(4, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY
717:                        + 1L, dt11.getMillis()));
718:
719:                assertEquals(dt12.getMillis(), fld.add(dt11.getMillis(), 1));
720:                assertEquals(dt13.getMillis(), fld.add(dt11.getMillis(), 2));
721:                assertEquals(dt01.getMillis(), fld.add(dt11.getMillis(), 3));
722:
723:                assertEquals(dt12.getMillis(), fld.add(dt11.getMillis(), 1L));
724:                assertEquals(dt13.getMillis(), fld.add(dt11.getMillis(), 2L));
725:                assertEquals(dt01.getMillis(), fld.add(dt11.getMillis(), 3L));
726:            }
727:
728:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.