0001: /*
0002: * Copyright 2001-2007 Stephen Colebourne
0003: *
0004: * Licensed under the Apache License, Version 2.0 (the "License");
0005: * you may not use this file except in compliance with the License.
0006: * You may obtain a copy of the License at
0007: *
0008: * http://www.apache.org/licenses/LICENSE-2.0
0009: *
0010: * Unless required by applicable law or agreed to in writing, software
0011: * distributed under the License is distributed on an "AS IS" BASIS,
0012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013: * See the License for the specific language governing permissions and
0014: * limitations under the License.
0015: */
0016: package org.joda.time;
0017:
0018: import java.util.Locale;
0019: import java.util.TimeZone;
0020:
0021: import junit.framework.TestCase;
0022: import junit.framework.TestSuite;
0023:
0024: import org.joda.time.chrono.CopticChronology;
0025: import org.joda.time.chrono.ISOChronology;
0026:
0027: /**
0028: * This class is a JUnit test for Duration.
0029: *
0030: * @author Stephen Colebourne
0031: */
0032: public class TestPeriod_Constructors extends TestCase {
0033: // Test in 2002/03 as time zones are more well known
0034: // (before the late 90's they were all over the place)
0035:
0036: private static final DateTimeZone LONDON = DateTimeZone
0037: .forID("Europe/London");
0038:
0039: long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
0040: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
0041: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
0042: + 365 + 365 + 366 + 365;
0043: long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
0044: + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365
0045: + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365
0046: + 365 + 365 + 366 + 365 + 365;
0047:
0048: // 2002-06-09
0049: private long TEST_TIME_NOW = (y2002days + 31L + 28L + 31L + 30L
0050: + 31L + 9L - 1L)
0051: * DateTimeConstants.MILLIS_PER_DAY;
0052:
0053: private DateTimeZone originalDateTimeZone = null;
0054: private TimeZone originalTimeZone = null;
0055: private Locale originalLocale = null;
0056:
0057: public static void main(String[] args) {
0058: junit.textui.TestRunner.run(suite());
0059: }
0060:
0061: public static TestSuite suite() {
0062: return new TestSuite(TestPeriod_Constructors.class);
0063: }
0064:
0065: public TestPeriod_Constructors(String name) {
0066: super (name);
0067: }
0068:
0069: protected void setUp() throws Exception {
0070: DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
0071: originalDateTimeZone = DateTimeZone.getDefault();
0072: originalTimeZone = TimeZone.getDefault();
0073: originalLocale = Locale.getDefault();
0074: DateTimeZone.setDefault(LONDON);
0075: TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
0076: Locale.setDefault(Locale.UK);
0077: }
0078:
0079: protected void tearDown() throws Exception {
0080: DateTimeUtils.setCurrentMillisSystem();
0081: DateTimeZone.setDefault(originalDateTimeZone);
0082: TimeZone.setDefault(originalTimeZone);
0083: Locale.setDefault(originalLocale);
0084: originalDateTimeZone = null;
0085: originalTimeZone = null;
0086: originalLocale = null;
0087: }
0088:
0089: //-----------------------------------------------------------------------
0090: public void testConstants() throws Throwable {
0091: Period test = Period.ZERO;
0092: assertEquals(PeriodType.standard(), test.getPeriodType());
0093: assertEquals(0, test.getYears());
0094: assertEquals(0, test.getMonths());
0095: assertEquals(0, test.getWeeks());
0096: assertEquals(0, test.getDays());
0097: assertEquals(0, test.getHours());
0098: assertEquals(0, test.getMinutes());
0099: assertEquals(0, test.getSeconds());
0100: assertEquals(0, test.getMillis());
0101: }
0102:
0103: //-----------------------------------------------------------------------
0104: public void testConstructor1() throws Throwable {
0105: Period test = new Period();
0106: assertEquals(PeriodType.standard(), test.getPeriodType());
0107: assertEquals(0, test.getYears());
0108: assertEquals(0, test.getMonths());
0109: assertEquals(0, test.getWeeks());
0110: assertEquals(0, test.getDays());
0111: assertEquals(0, test.getHours());
0112: assertEquals(0, test.getMinutes());
0113: assertEquals(0, test.getSeconds());
0114: assertEquals(0, test.getMillis());
0115: }
0116:
0117: //-----------------------------------------------------------------------
0118: public void testConstructor_long1() throws Throwable {
0119: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0120: * DateTimeConstants.MILLIS_PER_HOUR + 6
0121: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0122: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0123: Period test = new Period(length);
0124: assertEquals(PeriodType.standard(), test.getPeriodType());
0125: assertEquals(0, test.getYears());
0126: assertEquals(0, test.getMonths());
0127: assertEquals(0, test.getWeeks());
0128: assertEquals(0, test.getDays());
0129: assertEquals((4 * 24) + 5, test.getHours());
0130: assertEquals(6, test.getMinutes());
0131: assertEquals(7, test.getSeconds());
0132: assertEquals(8, test.getMillis());
0133: }
0134:
0135: public void testConstructor_long2() throws Throwable {
0136: long length = 5 * DateTimeConstants.MILLIS_PER_HOUR + 6
0137: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0138: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0139: Period test = new Period(length);
0140: assertEquals(PeriodType.standard(), test.getPeriodType());
0141: assertEquals(0, test.getYears());
0142: assertEquals(0, test.getMonths());
0143: assertEquals(0, test.getWeeks());
0144: assertEquals(0, test.getDays());
0145: assertEquals(5, test.getHours());
0146: assertEquals(6, test.getMinutes());
0147: assertEquals(7, test.getSeconds());
0148: assertEquals(8, test.getMillis());
0149: }
0150:
0151: public void testConstructor_long3() throws Throwable {
0152: long length = (4L + (3L * 7L) + (2L * 30L) + 365L)
0153: * DateTimeConstants.MILLIS_PER_DAY + 5L
0154: * DateTimeConstants.MILLIS_PER_HOUR + 6L
0155: * DateTimeConstants.MILLIS_PER_MINUTE + 7L
0156: * DateTimeConstants.MILLIS_PER_SECOND + 8L;
0157: Period test = new Period(length);
0158: assertEquals(PeriodType.standard(), test.getPeriodType());
0159: // only time fields are precise in AllType
0160: assertEquals(0, test.getYears()); // (4 + (3 * 7) + (2 * 30) + 365) == 450
0161: assertEquals(0, test.getMonths());
0162: assertEquals(0, test.getWeeks());
0163: assertEquals(0, test.getDays());
0164: assertEquals((450 * 24) + 5, test.getHours());
0165: assertEquals(6, test.getMinutes());
0166: assertEquals(7, test.getSeconds());
0167: assertEquals(8, test.getMillis());
0168: }
0169:
0170: //-----------------------------------------------------------------------
0171: public void testConstructor_long_PeriodType1() throws Throwable {
0172: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0173: * DateTimeConstants.MILLIS_PER_HOUR + 6
0174: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0175: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0176: Period test = new Period(length, (PeriodType) null);
0177: assertEquals(PeriodType.standard(), test.getPeriodType());
0178: assertEquals(0, test.getYears());
0179: assertEquals(0, test.getMonths());
0180: assertEquals(0, test.getWeeks());
0181: assertEquals(0, test.getDays());
0182: assertEquals((4 * 24) + 5, test.getHours());
0183: assertEquals(6, test.getMinutes());
0184: assertEquals(7, test.getSeconds());
0185: assertEquals(8, test.getMillis());
0186: }
0187:
0188: public void testConstructor_long_PeriodType2() throws Throwable {
0189: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0190: * DateTimeConstants.MILLIS_PER_HOUR + 6
0191: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0192: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0193: Period test = new Period(length, PeriodType.millis());
0194: assertEquals(PeriodType.millis(), test.getPeriodType());
0195: assertEquals(0, test.getYears());
0196: assertEquals(0, test.getMonths());
0197: assertEquals(0, test.getWeeks());
0198: assertEquals(0, test.getDays());
0199: assertEquals(0, test.getHours());
0200: assertEquals(0, test.getMinutes());
0201: assertEquals(0, test.getSeconds());
0202: assertEquals(length, test.getMillis());
0203: }
0204:
0205: public void testConstructor_long_PeriodType3() throws Throwable {
0206: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0207: * DateTimeConstants.MILLIS_PER_HOUR + 6
0208: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0209: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0210: Period test = new Period(length, PeriodType.dayTime());
0211: assertEquals(PeriodType.dayTime(), test.getPeriodType());
0212: assertEquals(0, test.getYears());
0213: assertEquals(0, test.getMonths());
0214: assertEquals(0, test.getWeeks());
0215: assertEquals(0, test.getDays());
0216: assertEquals((4 * 24) + 5, test.getHours());
0217: assertEquals(6, test.getMinutes());
0218: assertEquals(7, test.getSeconds());
0219: assertEquals(8, test.getMillis());
0220: }
0221:
0222: public void testConstructor_long_PeriodType4() throws Throwable {
0223: long length = 5 * DateTimeConstants.MILLIS_PER_HOUR + 6
0224: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0225: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0226: Period test = new Period(length, PeriodType.standard()
0227: .withMillisRemoved());
0228: assertEquals(PeriodType.standard().withMillisRemoved(), test
0229: .getPeriodType());
0230: assertEquals(0, test.getYears());
0231: assertEquals(0, test.getMonths());
0232: assertEquals(0, test.getWeeks());
0233: assertEquals(0, test.getDays());
0234: assertEquals(5, test.getHours());
0235: assertEquals(6, test.getMinutes());
0236: assertEquals(7, test.getSeconds());
0237: assertEquals(0, test.getMillis());
0238: }
0239:
0240: //-----------------------------------------------------------------------
0241: public void testConstructor_long_Chronology1() throws Throwable {
0242: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0243: * DateTimeConstants.MILLIS_PER_HOUR + 6
0244: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0245: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0246: Period test = new Period(length, ISOChronology.getInstance());
0247: assertEquals(PeriodType.standard(), test.getPeriodType());
0248: assertEquals(0, test.getYears());
0249: assertEquals(0, test.getMonths());
0250: assertEquals(0, test.getWeeks());
0251: assertEquals(0, test.getDays());
0252: assertEquals((4 * 24) + 5, test.getHours());
0253: assertEquals(6, test.getMinutes());
0254: assertEquals(7, test.getSeconds());
0255: assertEquals(8, test.getMillis());
0256: }
0257:
0258: public void testConstructor_long_Chronology2() throws Throwable {
0259: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0260: * DateTimeConstants.MILLIS_PER_HOUR + 6
0261: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0262: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0263: Period test = new Period(length, ISOChronology.getInstanceUTC());
0264: assertEquals(PeriodType.standard(), test.getPeriodType());
0265: assertEquals(0, test.getYears());
0266: assertEquals(0, test.getMonths());
0267: assertEquals(0, test.getWeeks());
0268: assertEquals(4, test.getDays());
0269: assertEquals(5, test.getHours());
0270: assertEquals(6, test.getMinutes());
0271: assertEquals(7, test.getSeconds());
0272: assertEquals(8, test.getMillis());
0273: }
0274:
0275: public void testConstructor_long_Chronology3() throws Throwable {
0276: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0277: * DateTimeConstants.MILLIS_PER_HOUR + 6
0278: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0279: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0280: Period test = new Period(length, (Chronology) null);
0281: assertEquals(PeriodType.standard(), test.getPeriodType());
0282: assertEquals(0, test.getYears());
0283: assertEquals(0, test.getMonths());
0284: assertEquals(0, test.getWeeks());
0285: assertEquals(0, test.getDays());
0286: assertEquals((4 * 24) + 5, test.getHours());
0287: assertEquals(6, test.getMinutes());
0288: assertEquals(7, test.getSeconds());
0289: assertEquals(8, test.getMillis());
0290: }
0291:
0292: //-----------------------------------------------------------------------
0293: public void testConstructor_long_PeriodType_Chronology1()
0294: throws Throwable {
0295: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0296: * DateTimeConstants.MILLIS_PER_HOUR + 6
0297: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0298: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0299: Period test = new Period(length, PeriodType.time()
0300: .withMillisRemoved(), ISOChronology.getInstance());
0301: assertEquals(PeriodType.time().withMillisRemoved(), test
0302: .getPeriodType());
0303: assertEquals(0, test.getYears());
0304: assertEquals(0, test.getMonths());
0305: assertEquals(0, test.getWeeks());
0306: assertEquals(0, test.getDays());
0307: assertEquals((4 * 24) + 5, test.getHours());
0308: assertEquals(6, test.getMinutes());
0309: assertEquals(7, test.getSeconds());
0310: assertEquals(0, test.getMillis());
0311: }
0312:
0313: public void testConstructor_long_PeriodType_Chronology2()
0314: throws Throwable {
0315: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0316: * DateTimeConstants.MILLIS_PER_HOUR + 6
0317: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0318: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0319: Period test = new Period(length, PeriodType.standard(),
0320: ISOChronology.getInstanceUTC());
0321: assertEquals(PeriodType.standard(), test.getPeriodType());
0322: assertEquals(0, test.getYears());
0323: assertEquals(0, test.getMonths());
0324: assertEquals(0, test.getWeeks());
0325: assertEquals(4, test.getDays());
0326: assertEquals(5, test.getHours());
0327: assertEquals(6, test.getMinutes());
0328: assertEquals(7, test.getSeconds());
0329: assertEquals(8, test.getMillis());
0330: }
0331:
0332: public void testConstructor_long_PeriodType_Chronology3()
0333: throws Throwable {
0334: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0335: * DateTimeConstants.MILLIS_PER_HOUR + 6
0336: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0337: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0338: Period test = new Period(length, PeriodType.standard(),
0339: (Chronology) null);
0340: assertEquals(PeriodType.standard(), test.getPeriodType());
0341: assertEquals(0, test.getYears());
0342: assertEquals(0, test.getMonths());
0343: assertEquals(0, test.getWeeks());
0344: assertEquals(0, test.getDays());
0345: assertEquals((4 * 24) + 5, test.getHours());
0346: assertEquals(6, test.getMinutes());
0347: assertEquals(7, test.getSeconds());
0348: assertEquals(8, test.getMillis());
0349: }
0350:
0351: public void testConstructor_long_PeriodType_Chronology4()
0352: throws Throwable {
0353: long length = 4 * DateTimeConstants.MILLIS_PER_DAY + 5
0354: * DateTimeConstants.MILLIS_PER_HOUR + 6
0355: * DateTimeConstants.MILLIS_PER_MINUTE + 7
0356: * DateTimeConstants.MILLIS_PER_SECOND + 8;
0357: Period test = new Period(length, (PeriodType) null,
0358: (Chronology) null);
0359: assertEquals(PeriodType.standard(), test.getPeriodType());
0360: assertEquals(0, test.getYears());
0361: assertEquals(0, test.getMonths());
0362: assertEquals(0, test.getWeeks());
0363: assertEquals(0, test.getDays());
0364: assertEquals((4 * 24) + 5, test.getHours());
0365: assertEquals(6, test.getMinutes());
0366: assertEquals(7, test.getSeconds());
0367: assertEquals(8, test.getMillis());
0368: }
0369:
0370: //-----------------------------------------------------------------------
0371: /**
0372: * Test constructor (4ints)
0373: */
0374: public void testConstructor_4int1() throws Throwable {
0375: Period test = new Period(5, 6, 7, 8);
0376: assertEquals(PeriodType.standard(), test.getPeriodType());
0377: assertEquals(0, test.getYears());
0378: assertEquals(0, test.getMonths());
0379: assertEquals(0, test.getWeeks());
0380: assertEquals(0, test.getDays());
0381: assertEquals(5, test.getHours());
0382: assertEquals(6, test.getMinutes());
0383: assertEquals(7, test.getSeconds());
0384: assertEquals(8, test.getMillis());
0385: }
0386:
0387: //-----------------------------------------------------------------------
0388: /**
0389: * Test constructor (8ints)
0390: */
0391: public void testConstructor_8int1() throws Throwable {
0392: Period test = new Period(1, 2, 3, 4, 5, 6, 7, 8);
0393: assertEquals(PeriodType.standard(), test.getPeriodType());
0394: assertEquals(1, test.getYears());
0395: assertEquals(2, test.getMonths());
0396: assertEquals(3, test.getWeeks());
0397: assertEquals(4, test.getDays());
0398: assertEquals(5, test.getHours());
0399: assertEquals(6, test.getMinutes());
0400: assertEquals(7, test.getSeconds());
0401: assertEquals(8, test.getMillis());
0402: }
0403:
0404: //-----------------------------------------------------------------------
0405: /**
0406: * Test constructor (8ints)
0407: */
0408: public void testConstructor_8int__PeriodType1() throws Throwable {
0409: Period test = new Period(1, 2, 3, 4, 5, 6, 7, 8, null);
0410: assertEquals(PeriodType.standard(), test.getPeriodType());
0411: assertEquals(1, test.getYears());
0412: assertEquals(2, test.getMonths());
0413: assertEquals(3, test.getWeeks());
0414: assertEquals(4, test.getDays());
0415: assertEquals(5, test.getHours());
0416: assertEquals(6, test.getMinutes());
0417: assertEquals(7, test.getSeconds());
0418: assertEquals(8, test.getMillis());
0419: }
0420:
0421: public void testConstructor_8int__PeriodType2() throws Throwable {
0422: Period test = new Period(0, 0, 0, 0, 5, 6, 7, 8, PeriodType
0423: .dayTime());
0424: assertEquals(PeriodType.dayTime(), test.getPeriodType());
0425: assertEquals(0, test.getYears());
0426: assertEquals(0, test.getMonths());
0427: assertEquals(0, test.getWeeks());
0428: assertEquals(0, test.getDays());
0429: assertEquals(5, test.getHours());
0430: assertEquals(6, test.getMinutes());
0431: assertEquals(7, test.getSeconds());
0432: assertEquals(8, test.getMillis());
0433: }
0434:
0435: public void testConstructor_8int__PeriodType3() throws Throwable {
0436: try {
0437: new Period(1, 2, 3, 4, 5, 6, 7, 8, PeriodType.dayTime());
0438: fail();
0439: } catch (IllegalArgumentException ex) {
0440: }
0441: }
0442:
0443: //-----------------------------------------------------------------------
0444: public void testConstructor_long_long1() throws Throwable {
0445: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0446: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
0447: Period test = new Period(dt1.getMillis(), dt2.getMillis());
0448: assertEquals(PeriodType.standard(), test.getPeriodType());
0449: assertEquals(1, test.getYears());
0450: assertEquals(1, test.getMonths());
0451: assertEquals(0, test.getWeeks());
0452: assertEquals(1, test.getDays());
0453: assertEquals(1, test.getHours());
0454: assertEquals(1, test.getMinutes());
0455: assertEquals(1, test.getSeconds());
0456: assertEquals(1, test.getMillis());
0457: }
0458:
0459: public void testConstructor_long_long2() throws Throwable {
0460: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0461: DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
0462: Period test = new Period(dt1.getMillis(), dt2.getMillis());
0463: assertEquals(PeriodType.standard(), test.getPeriodType());
0464: assertEquals(1, test.getYears());
0465: assertEquals(1, test.getMonths());
0466: assertEquals(1, test.getWeeks());
0467: assertEquals(1, test.getDays());
0468: assertEquals(1, test.getHours());
0469: assertEquals(1, test.getMinutes());
0470: assertEquals(1, test.getSeconds());
0471: assertEquals(1, test.getMillis());
0472: }
0473:
0474: //-----------------------------------------------------------------------
0475: public void testConstructor_long_long_PeriodType1()
0476: throws Throwable {
0477: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0478: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
0479: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0480: (PeriodType) null);
0481: assertEquals(PeriodType.standard(), test.getPeriodType());
0482: assertEquals(1, test.getYears());
0483: assertEquals(1, test.getMonths());
0484: assertEquals(0, test.getWeeks());
0485: assertEquals(1, test.getDays());
0486: assertEquals(1, test.getHours());
0487: assertEquals(1, test.getMinutes());
0488: assertEquals(1, test.getSeconds());
0489: assertEquals(1, test.getMillis());
0490: }
0491:
0492: public void testConstructor_long_long_PeriodType2()
0493: throws Throwable {
0494: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0495: DateTime dt2 = new DateTime(2004, 7, 10, 1, 1, 1, 1);
0496: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0497: PeriodType.dayTime());
0498: assertEquals(PeriodType.dayTime(), test.getPeriodType());
0499: assertEquals(0, test.getYears());
0500: assertEquals(0, test.getMonths());
0501: assertEquals(0, test.getWeeks());
0502: assertEquals(31, test.getDays());
0503: assertEquals(1, test.getHours());
0504: assertEquals(1, test.getMinutes());
0505: assertEquals(1, test.getSeconds());
0506: assertEquals(1, test.getMillis());
0507: }
0508:
0509: public void testConstructor_long_long_PeriodType3()
0510: throws Throwable {
0511: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0512: DateTime dt2 = new DateTime(2004, 6, 9, 1, 1, 1, 1);
0513: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0514: PeriodType.standard().withMillisRemoved());
0515: assertEquals(PeriodType.standard().withMillisRemoved(), test
0516: .getPeriodType());
0517: assertEquals(0, test.getYears());
0518: assertEquals(0, test.getMonths());
0519: assertEquals(0, test.getWeeks());
0520: assertEquals(0, test.getDays());
0521: assertEquals(1, test.getHours());
0522: assertEquals(1, test.getMinutes());
0523: assertEquals(1, test.getSeconds());
0524: assertEquals(0, test.getMillis());
0525: }
0526:
0527: public void testToPeriod_PeriodType3() {
0528: DateTime dt1 = new DateTime(2004, 6, 9, 7, 8, 9, 10);
0529: DateTime dt2 = new DateTime(2005, 6, 9, 12, 14, 16, 18);
0530: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0531: PeriodType.yearWeekDayTime());
0532:
0533: assertEquals(PeriodType.yearWeekDayTime(), test.getPeriodType());
0534: assertEquals(1, test.getYears()); // tests using years and not weekyears
0535: assertEquals(0, test.getMonths());
0536: assertEquals(0, test.getWeeks());
0537: assertEquals(0, test.getDays());
0538: assertEquals(5, test.getHours());
0539: assertEquals(6, test.getMinutes());
0540: assertEquals(7, test.getSeconds());
0541: assertEquals(8, test.getMillis());
0542: }
0543:
0544: //-----------------------------------------------------------------------
0545: public void testConstructor_long_long_Chronology1()
0546: throws Throwable {
0547: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0,
0548: CopticChronology.getInstance());
0549: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1,
0550: CopticChronology.getInstance());
0551: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0552: CopticChronology.getInstance());
0553: assertEquals(PeriodType.standard(), test.getPeriodType());
0554: assertEquals(1, test.getYears());
0555: assertEquals(1, test.getMonths());
0556: assertEquals(0, test.getWeeks());
0557: assertEquals(1, test.getDays());
0558: assertEquals(1, test.getHours());
0559: assertEquals(1, test.getMinutes());
0560: assertEquals(1, test.getSeconds());
0561: assertEquals(1, test.getMillis());
0562: }
0563:
0564: public void testConstructor_long_long_Chronology2()
0565: throws Throwable {
0566: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0567: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
0568: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0569: (Chronology) null);
0570: assertEquals(PeriodType.standard(), test.getPeriodType());
0571: assertEquals(1, test.getYears());
0572: assertEquals(1, test.getMonths());
0573: assertEquals(0, test.getWeeks());
0574: assertEquals(1, test.getDays());
0575: assertEquals(1, test.getHours());
0576: assertEquals(1, test.getMinutes());
0577: assertEquals(1, test.getSeconds());
0578: assertEquals(1, test.getMillis());
0579: }
0580:
0581: //-----------------------------------------------------------------------
0582: public void testConstructor_long_long_PeriodType_Chronology1()
0583: throws Throwable {
0584: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0,
0585: CopticChronology.getInstance());
0586: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1,
0587: CopticChronology.getInstance());
0588: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0589: (PeriodType) null, CopticChronology.getInstance());
0590: assertEquals(PeriodType.standard(), test.getPeriodType());
0591: assertEquals(1, test.getYears());
0592: assertEquals(1, test.getMonths());
0593: assertEquals(0, test.getWeeks());
0594: assertEquals(1, test.getDays());
0595: assertEquals(1, test.getHours());
0596: assertEquals(1, test.getMinutes());
0597: assertEquals(1, test.getSeconds());
0598: assertEquals(1, test.getMillis());
0599: }
0600:
0601: public void testConstructor_long_long_PeriodType_Chronology2()
0602: throws Throwable {
0603: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0604: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
0605: Period test = new Period(dt1.getMillis(), dt2.getMillis(),
0606: (PeriodType) null, null);
0607: assertEquals(PeriodType.standard(), test.getPeriodType());
0608: assertEquals(1, test.getYears());
0609: assertEquals(1, test.getMonths());
0610: assertEquals(0, test.getWeeks());
0611: assertEquals(1, test.getDays());
0612: assertEquals(1, test.getHours());
0613: assertEquals(1, test.getMinutes());
0614: assertEquals(1, test.getSeconds());
0615: assertEquals(1, test.getMillis());
0616: }
0617:
0618: //-----------------------------------------------------------------------
0619: public void testConstructor_RI_RI1() throws Throwable {
0620: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0621: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
0622: Period test = new Period(dt1, dt2);
0623: assertEquals(PeriodType.standard(), test.getPeriodType());
0624: assertEquals(1, test.getYears());
0625: assertEquals(1, test.getMonths());
0626: assertEquals(0, test.getWeeks());
0627: assertEquals(1, test.getDays());
0628: assertEquals(1, test.getHours());
0629: assertEquals(1, test.getMinutes());
0630: assertEquals(1, test.getSeconds());
0631: assertEquals(1, test.getMillis());
0632: }
0633:
0634: public void testConstructor_RI_RI2() throws Throwable {
0635: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0636: DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
0637: Period test = new Period(dt1, dt2);
0638: assertEquals(PeriodType.standard(), test.getPeriodType());
0639: assertEquals(1, test.getYears());
0640: assertEquals(1, test.getMonths());
0641: assertEquals(1, test.getWeeks());
0642: assertEquals(1, test.getDays());
0643: assertEquals(1, test.getHours());
0644: assertEquals(1, test.getMinutes());
0645: assertEquals(1, test.getSeconds());
0646: assertEquals(1, test.getMillis());
0647: }
0648:
0649: public void testConstructor_RI_RI3() throws Throwable {
0650: DateTime dt1 = null; // 2002-06-09T01:00+01:00
0651: DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
0652: Period test = new Period(dt1, dt2);
0653: assertEquals(PeriodType.standard(), test.getPeriodType());
0654: assertEquals(3, test.getYears());
0655: assertEquals(1, test.getMonths());
0656: assertEquals(1, test.getWeeks());
0657: assertEquals(1, test.getDays());
0658: assertEquals(0, test.getHours());
0659: assertEquals(1, test.getMinutes());
0660: assertEquals(1, test.getSeconds());
0661: assertEquals(1, test.getMillis());
0662: }
0663:
0664: public void testConstructor_RI_RI4() throws Throwable {
0665: DateTime dt1 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
0666: DateTime dt2 = null; // 2002-06-09T01:00+01:00
0667: Period test = new Period(dt1, dt2);
0668: assertEquals(PeriodType.standard(), test.getPeriodType());
0669: assertEquals(-3, test.getYears());
0670: assertEquals(-1, test.getMonths());
0671: assertEquals(-1, test.getWeeks());
0672: assertEquals(-1, test.getDays());
0673: assertEquals(0, test.getHours());
0674: assertEquals(-1, test.getMinutes());
0675: assertEquals(-1, test.getSeconds());
0676: assertEquals(-1, test.getMillis());
0677: }
0678:
0679: public void testConstructor_RI_RI5() throws Throwable {
0680: DateTime dt1 = null; // 2002-06-09T01:00+01:00
0681: DateTime dt2 = null; // 2002-06-09T01:00+01:00
0682: Period test = new Period(dt1, dt2);
0683: assertEquals(PeriodType.standard(), test.getPeriodType());
0684: assertEquals(0, test.getYears());
0685: assertEquals(0, test.getMonths());
0686: assertEquals(0, test.getWeeks());
0687: assertEquals(0, test.getDays());
0688: assertEquals(0, test.getHours());
0689: assertEquals(0, test.getMinutes());
0690: assertEquals(0, test.getSeconds());
0691: assertEquals(0, test.getMillis());
0692: }
0693:
0694: //-----------------------------------------------------------------------
0695: public void testConstructor_RI_RI_PeriodType1() throws Throwable {
0696: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0697: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
0698: Period test = new Period(dt1, dt2, null);
0699: assertEquals(PeriodType.standard(), test.getPeriodType());
0700: assertEquals(1, test.getYears());
0701: assertEquals(1, test.getMonths());
0702: assertEquals(0, test.getWeeks());
0703: assertEquals(1, test.getDays());
0704: assertEquals(1, test.getHours());
0705: assertEquals(1, test.getMinutes());
0706: assertEquals(1, test.getSeconds());
0707: assertEquals(1, test.getMillis());
0708: }
0709:
0710: public void testConstructor_RI_RI_PeriodType2() throws Throwable {
0711: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0712: DateTime dt2 = new DateTime(2004, 7, 10, 1, 1, 1, 1);
0713: Period test = new Period(dt1, dt2, PeriodType.dayTime());
0714: assertEquals(PeriodType.dayTime(), test.getPeriodType());
0715: assertEquals(0, test.getYears());
0716: assertEquals(0, test.getMonths());
0717: assertEquals(0, test.getWeeks());
0718: assertEquals(31, test.getDays());
0719: assertEquals(1, test.getHours());
0720: assertEquals(1, test.getMinutes());
0721: assertEquals(1, test.getSeconds());
0722: assertEquals(1, test.getMillis());
0723: }
0724:
0725: public void testConstructor_RI_RI_PeriodType3() throws Throwable {
0726: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
0727: DateTime dt2 = new DateTime(2004, 6, 9, 1, 1, 1, 1);
0728: Period test = new Period(dt1, dt2, PeriodType.standard()
0729: .withMillisRemoved());
0730: assertEquals(PeriodType.standard().withMillisRemoved(), test
0731: .getPeriodType());
0732: assertEquals(0, test.getYears());
0733: assertEquals(0, test.getMonths());
0734: assertEquals(0, test.getWeeks());
0735: assertEquals(0, test.getDays());
0736: assertEquals(1, test.getHours());
0737: assertEquals(1, test.getMinutes());
0738: assertEquals(1, test.getSeconds());
0739: assertEquals(0, test.getMillis());
0740: }
0741:
0742: public void testConstructor_RI_RI_PeriodType4() throws Throwable {
0743: DateTime dt1 = null; // 2002-06-09T01:00+01:00
0744: DateTime dt2 = new DateTime(2005, 7, 17, 1, 1, 1, 1);
0745: Period test = new Period(dt1, dt2, PeriodType.standard());
0746: assertEquals(PeriodType.standard(), test.getPeriodType());
0747: assertEquals(3, test.getYears());
0748: assertEquals(1, test.getMonths());
0749: assertEquals(1, test.getWeeks());
0750: assertEquals(1, test.getDays());
0751: assertEquals(0, test.getHours());
0752: assertEquals(1, test.getMinutes());
0753: assertEquals(1, test.getSeconds());
0754: assertEquals(1, test.getMillis());
0755: }
0756:
0757: public void testConstructor_RI_RI_PeriodType5() throws Throwable {
0758: DateTime dt1 = null; // 2002-06-09T01:00+01:00
0759: DateTime dt2 = null; // 2002-06-09T01:00+01:00
0760: Period test = new Period(dt1, dt2, PeriodType.standard());
0761: assertEquals(PeriodType.standard(), test.getPeriodType());
0762: assertEquals(0, test.getYears());
0763: assertEquals(0, test.getMonths());
0764: assertEquals(0, test.getWeeks());
0765: assertEquals(0, test.getDays());
0766: assertEquals(0, test.getHours());
0767: assertEquals(0, test.getMinutes());
0768: assertEquals(0, test.getSeconds());
0769: assertEquals(0, test.getMillis());
0770: }
0771:
0772: //-----------------------------------------------------------------------
0773: public void testConstructor_RP_RP1() throws Throwable {
0774: YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
0775: YearMonthDay dt2 = new YearMonthDay(2005, 7, 10);
0776: Period test = new Period(dt1, dt2);
0777: assertEquals(PeriodType.standard(), test.getPeriodType());
0778: assertEquals(1, test.getYears());
0779: assertEquals(1, test.getMonths());
0780: assertEquals(0, test.getWeeks());
0781: assertEquals(1, test.getDays());
0782: assertEquals(0, test.getHours());
0783: assertEquals(0, test.getMinutes());
0784: assertEquals(0, test.getSeconds());
0785: assertEquals(0, test.getMillis());
0786: }
0787:
0788: public void testConstructor_RP_RP2() throws Throwable {
0789: YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
0790: YearMonthDay dt2 = new YearMonthDay(2005, 5, 17);
0791: Period test = new Period(dt1, dt2);
0792: assertEquals(PeriodType.standard(), test.getPeriodType());
0793: assertEquals(0, test.getYears());
0794: assertEquals(11, test.getMonths());
0795: assertEquals(1, test.getWeeks());
0796: assertEquals(1, test.getDays());
0797: assertEquals(0, test.getHours());
0798: assertEquals(0, test.getMinutes());
0799: assertEquals(0, test.getSeconds());
0800: assertEquals(0, test.getMillis());
0801: }
0802:
0803: public void testConstructor_RP_RP2Local() throws Throwable {
0804: LocalDate dt1 = new LocalDate(2004, 6, 9);
0805: LocalDate dt2 = new LocalDate(2005, 5, 17);
0806: Period test = new Period(dt1, dt2);
0807: assertEquals(PeriodType.standard(), test.getPeriodType());
0808: assertEquals(0, test.getYears());
0809: assertEquals(11, test.getMonths());
0810: assertEquals(1, test.getWeeks());
0811: assertEquals(1, test.getDays());
0812: assertEquals(0, test.getHours());
0813: assertEquals(0, test.getMinutes());
0814: assertEquals(0, test.getSeconds());
0815: assertEquals(0, test.getMillis());
0816: }
0817:
0818: public void testConstructor_RP_RP3() throws Throwable {
0819: YearMonthDay dt1 = null;
0820: YearMonthDay dt2 = new YearMonthDay(2005, 7, 17);
0821: try {
0822: new Period(dt1, dt2);
0823: fail();
0824: } catch (IllegalArgumentException ex) {
0825: }
0826: }
0827:
0828: public void testConstructor_RP_RP4() throws Throwable {
0829: YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
0830: YearMonthDay dt2 = null;
0831: try {
0832: new Period(dt1, dt2);
0833: fail();
0834: } catch (IllegalArgumentException ex) {
0835: }
0836: }
0837:
0838: public void testConstructor_RP_RP5() throws Throwable {
0839: YearMonthDay dt1 = null;
0840: YearMonthDay dt2 = null;
0841: try {
0842: new Period(dt1, dt2);
0843: fail();
0844: } catch (IllegalArgumentException ex) {
0845: }
0846: }
0847:
0848: public void testConstructor_RP_RP6() throws Throwable {
0849: YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
0850: TimeOfDay dt2 = new TimeOfDay(10, 20, 30, 40);
0851: try {
0852: new Period(dt1, dt2);
0853: fail();
0854: } catch (IllegalArgumentException ex) {
0855: }
0856: }
0857:
0858: public void testConstructor_RP_RP7() throws Throwable {
0859: Partial dt1 = new Partial()
0860: .with(DateTimeFieldType.year(), 2005).with(
0861: DateTimeFieldType.monthOfYear(), 12);
0862: Partial dt2 = new Partial()
0863: .with(DateTimeFieldType.year(), 2005).with(
0864: DateTimeFieldType.hourOfDay(), 14);
0865: try {
0866: new Period(dt1, dt2);
0867: fail();
0868: } catch (IllegalArgumentException ex) {
0869: }
0870: }
0871:
0872: public void testConstructor_RP_RP8() throws Throwable {
0873: Partial dt1 = new Partial()
0874: .with(DateTimeFieldType.year(), 2005).with(
0875: DateTimeFieldType.hourOfDay(), 12);
0876: Partial dt2 = new Partial()
0877: .with(DateTimeFieldType.year(), 2005).with(
0878: DateTimeFieldType.hourOfDay(), 14);
0879: try {
0880: new Period(dt1, dt2);
0881: fail();
0882: } catch (IllegalArgumentException ex) {
0883: }
0884: }
0885:
0886: //-----------------------------------------------------------------------
0887: public void testConstructor_RP_RP_PeriodType1() throws Throwable {
0888: YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
0889: YearMonthDay dt2 = new YearMonthDay(2005, 7, 10);
0890: Period test = new Period(dt1, dt2, PeriodType.standard());
0891: assertEquals(PeriodType.standard(), test.getPeriodType());
0892: assertEquals(1, test.getYears());
0893: assertEquals(1, test.getMonths());
0894: assertEquals(0, test.getWeeks());
0895: assertEquals(1, test.getDays());
0896: assertEquals(0, test.getHours());
0897: assertEquals(0, test.getMinutes());
0898: assertEquals(0, test.getSeconds());
0899: assertEquals(0, test.getMillis());
0900: }
0901:
0902: public void testConstructor_RP_RP_PeriodType2() throws Throwable {
0903: YearMonthDay dt1 = new YearMonthDay(2004, 6, 9);
0904: YearMonthDay dt2 = new YearMonthDay(2005, 5, 17);
0905: Period test = new Period(dt1, dt2, PeriodType.yearMonthDay());
0906: assertEquals(PeriodType.yearMonthDay(), test.getPeriodType());
0907: assertEquals(0, test.getYears());
0908: assertEquals(11, test.getMonths());
0909: assertEquals(0, test.getWeeks());
0910: assertEquals(8, test.getDays());
0911: assertEquals(0, test.getHours());
0912: assertEquals(0, test.getMinutes());
0913: assertEquals(0, test.getSeconds());
0914: assertEquals(0, test.getMillis());
0915: }
0916:
0917: public void testConstructor_RP_RP_PeriodType2Local()
0918: throws Throwable {
0919: LocalDate dt1 = new LocalDate(2004, 6, 9);
0920: LocalDate dt2 = new LocalDate(2005, 5, 17);
0921: Period test = new Period(dt1, dt2, PeriodType.yearMonthDay());
0922: assertEquals(PeriodType.yearMonthDay(), test.getPeriodType());
0923: assertEquals(0, test.getYears());
0924: assertEquals(11, test.getMonths());
0925: assertEquals(0, test.getWeeks());
0926: assertEquals(8, test.getDays());
0927: assertEquals(0, test.getHours());
0928: assertEquals(0, test.getMinutes());
0929: assertEquals(0, test.getSeconds());
0930: assertEquals(0, test.getMillis());
0931: }
0932:
0933: public void testConstructor_RP_RP_PeriodType3() throws Throwable {
0934: YearMonthDay dt1 = null;
0935: YearMonthDay dt2 = new YearMonthDay(2005, 7, 17);
0936: try {
0937: new Period(dt1, dt2, PeriodType.standard());
0938: fail();
0939: } catch (IllegalArgumentException ex) {
0940: }
0941: }
0942:
0943: public void testConstructor_RP_RP_PeriodType4() throws Throwable {
0944: YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
0945: YearMonthDay dt2 = null;
0946: try {
0947: new Period(dt1, dt2);
0948: fail();
0949: } catch (IllegalArgumentException ex) {
0950: }
0951: }
0952:
0953: public void testConstructor_RP_RP_PeriodType5() throws Throwable {
0954: YearMonthDay dt1 = null;
0955: YearMonthDay dt2 = null;
0956: try {
0957: new Period(dt1, dt2, PeriodType.standard());
0958: fail();
0959: } catch (IllegalArgumentException ex) {
0960: }
0961: }
0962:
0963: public void testConstructor_RP_RP_PeriodType6() throws Throwable {
0964: YearMonthDay dt1 = new YearMonthDay(2005, 7, 17);
0965: TimeOfDay dt2 = new TimeOfDay(10, 20, 30, 40);
0966: try {
0967: new Period(dt1, dt2, PeriodType.standard());
0968: fail();
0969: } catch (IllegalArgumentException ex) {
0970: }
0971: }
0972:
0973: public void testConstructor_RP_RP_PeriodType7() throws Throwable {
0974: Partial dt1 = new Partial()
0975: .with(DateTimeFieldType.year(), 2005).with(
0976: DateTimeFieldType.monthOfYear(), 12);
0977: Partial dt2 = new Partial()
0978: .with(DateTimeFieldType.year(), 2005).with(
0979: DateTimeFieldType.hourOfDay(), 14);
0980: try {
0981: new Period(dt1, dt2, PeriodType.standard());
0982: fail();
0983: } catch (IllegalArgumentException ex) {
0984: }
0985: }
0986:
0987: public void testConstructor_RP_RP_PeriodType8() throws Throwable {
0988: Partial dt1 = new Partial()
0989: .with(DateTimeFieldType.year(), 2005).with(
0990: DateTimeFieldType.hourOfDay(), 12);
0991: Partial dt2 = new Partial()
0992: .with(DateTimeFieldType.year(), 2005).with(
0993: DateTimeFieldType.hourOfDay(), 14);
0994: try {
0995: new Period(dt1, dt2, PeriodType.standard());
0996: fail();
0997: } catch (IllegalArgumentException ex) {
0998: }
0999: }
1000:
1001: //-----------------------------------------------------------------------
1002: public void testConstructor_RI_RD1() throws Throwable {
1003: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1004: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1005: Duration dur = new Interval(dt1, dt2).toDuration();
1006: Period test = new Period(dt1, dur);
1007: assertEquals(PeriodType.standard(), test.getPeriodType());
1008: assertEquals(1, test.getYears());
1009: assertEquals(1, test.getMonths());
1010: assertEquals(0, test.getWeeks());
1011: assertEquals(1, test.getDays());
1012: assertEquals(1, test.getHours());
1013: assertEquals(1, test.getMinutes());
1014: assertEquals(1, test.getSeconds());
1015: assertEquals(1, test.getMillis());
1016: }
1017:
1018: public void testConstructor_RI_RD2() throws Throwable {
1019: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1020: Duration dur = null;
1021: Period test = new Period(dt1, dur);
1022: assertEquals(PeriodType.standard(), test.getPeriodType());
1023: assertEquals(0, test.getYears());
1024: assertEquals(0, test.getMonths());
1025: assertEquals(0, test.getWeeks());
1026: assertEquals(0, test.getDays());
1027: assertEquals(0, test.getHours());
1028: assertEquals(0, test.getMinutes());
1029: assertEquals(0, test.getSeconds());
1030: assertEquals(0, test.getMillis());
1031: }
1032:
1033: //-----------------------------------------------------------------------
1034: public void testConstructor_RI_RD_PeriodType1() throws Throwable {
1035: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1036: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1037: Duration dur = new Interval(dt1, dt2).toDuration();
1038: Period test = new Period(dt1, dur, PeriodType.yearDayTime());
1039: assertEquals(PeriodType.yearDayTime(), test.getPeriodType());
1040: assertEquals(1, test.getYears());
1041: assertEquals(0, test.getMonths());
1042: assertEquals(0, test.getWeeks());
1043: assertEquals(31, test.getDays());
1044: assertEquals(1, test.getHours());
1045: assertEquals(1, test.getMinutes());
1046: assertEquals(1, test.getSeconds());
1047: assertEquals(1, test.getMillis());
1048: }
1049:
1050: public void testConstructor_RI_RD_PeriodType2() throws Throwable {
1051: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1052: Duration dur = null;
1053: Period test = new Period(dt1, dur, (PeriodType) null);
1054: assertEquals(PeriodType.standard(), test.getPeriodType());
1055: assertEquals(0, test.getYears());
1056: assertEquals(0, test.getMonths());
1057: assertEquals(0, test.getWeeks());
1058: assertEquals(0, test.getDays());
1059: assertEquals(0, test.getHours());
1060: assertEquals(0, test.getMinutes());
1061: assertEquals(0, test.getSeconds());
1062: assertEquals(0, test.getMillis());
1063: }
1064:
1065: //-----------------------------------------------------------------------
1066: public void testConstructor_RD_RI1() throws Throwable {
1067: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1068: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1069: Duration dur = new Interval(dt1, dt2).toDuration();
1070: Period test = new Period(dur, dt2);
1071: assertEquals(PeriodType.standard(), test.getPeriodType());
1072: assertEquals(1, test.getYears());
1073: assertEquals(1, test.getMonths());
1074: assertEquals(0, test.getWeeks());
1075: assertEquals(1, test.getDays());
1076: assertEquals(1, test.getHours());
1077: assertEquals(1, test.getMinutes());
1078: assertEquals(1, test.getSeconds());
1079: assertEquals(1, test.getMillis());
1080: }
1081:
1082: public void testConstructor_RD_RI2() throws Throwable {
1083: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1084: Duration dur = null;
1085: Period test = new Period(dur, dt1);
1086: assertEquals(PeriodType.standard(), test.getPeriodType());
1087: assertEquals(0, test.getYears());
1088: assertEquals(0, test.getMonths());
1089: assertEquals(0, test.getWeeks());
1090: assertEquals(0, test.getDays());
1091: assertEquals(0, test.getHours());
1092: assertEquals(0, test.getMinutes());
1093: assertEquals(0, test.getSeconds());
1094: assertEquals(0, test.getMillis());
1095: }
1096:
1097: //-----------------------------------------------------------------------
1098: public void testConstructor_RD_RI_PeriodType1() throws Throwable {
1099: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1100: DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
1101: Duration dur = new Interval(dt1, dt2).toDuration();
1102: Period test = new Period(dur, dt2, PeriodType.yearDayTime());
1103: assertEquals(PeriodType.yearDayTime(), test.getPeriodType());
1104: assertEquals(1, test.getYears());
1105: assertEquals(0, test.getMonths());
1106: assertEquals(0, test.getWeeks());
1107: assertEquals(31, test.getDays());
1108: assertEquals(1, test.getHours());
1109: assertEquals(1, test.getMinutes());
1110: assertEquals(1, test.getSeconds());
1111: assertEquals(1, test.getMillis());
1112: }
1113:
1114: public void testConstructor_RD_RI_PeriodType2() throws Throwable {
1115: DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
1116: Duration dur = null;
1117: Period test = new Period(dur, dt1, (PeriodType) null);
1118: assertEquals(PeriodType.standard(), test.getPeriodType());
1119: assertEquals(0, test.getYears());
1120: assertEquals(0, test.getMonths());
1121: assertEquals(0, test.getWeeks());
1122: assertEquals(0, test.getDays());
1123: assertEquals(0, test.getHours());
1124: assertEquals(0, test.getMinutes());
1125: assertEquals(0, test.getSeconds());
1126: assertEquals(0, test.getMillis());
1127: }
1128:
1129: //-----------------------------------------------------------------------
1130: /**
1131: * Test constructor (Object)
1132: */
1133: public void testConstructor_Object1() throws Throwable {
1134: Period test = new Period("P1Y2M3D");
1135: assertEquals(PeriodType.standard(), test.getPeriodType());
1136: assertEquals(1, test.getYears());
1137: assertEquals(2, test.getMonths());
1138: assertEquals(0, test.getWeeks());
1139: assertEquals(3, test.getDays());
1140: assertEquals(0, test.getHours());
1141: assertEquals(0, test.getMinutes());
1142: assertEquals(0, test.getSeconds());
1143: assertEquals(0, test.getMillis());
1144: }
1145:
1146: public void testConstructor_Object2() throws Throwable {
1147: Period test = new Period((Object) null);
1148: assertEquals(PeriodType.standard(), test.getPeriodType());
1149: assertEquals(0, test.getYears());
1150: assertEquals(0, test.getMonths());
1151: assertEquals(0, test.getWeeks());
1152: assertEquals(0, test.getDays());
1153: assertEquals(0, test.getHours());
1154: assertEquals(0, test.getMinutes());
1155: assertEquals(0, test.getSeconds());
1156: assertEquals(0, test.getMillis());
1157: }
1158:
1159: public void testConstructor_Object3() throws Throwable {
1160: Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4,
1161: PeriodType.dayTime()));
1162: assertEquals(PeriodType.dayTime(), test.getPeriodType());
1163: assertEquals(0, test.getYears());
1164: assertEquals(0, test.getMonths());
1165: assertEquals(0, test.getWeeks());
1166: assertEquals(0, test.getDays());
1167: assertEquals(1, test.getHours());
1168: assertEquals(2, test.getMinutes());
1169: assertEquals(3, test.getSeconds());
1170: assertEquals(4, test.getMillis());
1171: }
1172:
1173: public void testConstructor_Object4() throws Throwable {
1174: Period base = new Period(1, 1, 0, 1, 1, 1, 1, 1, PeriodType
1175: .standard());
1176: Period test = new Period(base);
1177: assertEquals(PeriodType.standard(), test.getPeriodType());
1178: assertEquals(1, test.getYears());
1179: assertEquals(1, test.getMonths());
1180: assertEquals(0, test.getWeeks());
1181: assertEquals(1, test.getDays());
1182: assertEquals(1, test.getHours());
1183: assertEquals(1, test.getMinutes());
1184: assertEquals(1, test.getSeconds());
1185: assertEquals(1, test.getMillis());
1186: }
1187:
1188: //-----------------------------------------------------------------------
1189: /**
1190: * Test constructor (Object)
1191: */
1192: public void testConstructor_Object_PeriodType1() throws Throwable {
1193: Period test = new Period("P1Y2M3D", PeriodType
1194: .yearMonthDayTime());
1195: assertEquals(PeriodType.yearMonthDayTime(), test
1196: .getPeriodType());
1197: assertEquals(1, test.getYears());
1198: assertEquals(2, test.getMonths());
1199: assertEquals(0, test.getWeeks());
1200: assertEquals(3, test.getDays());
1201: assertEquals(0, test.getHours());
1202: assertEquals(0, test.getMinutes());
1203: assertEquals(0, test.getSeconds());
1204: assertEquals(0, test.getMillis());
1205: }
1206:
1207: public void testConstructor_Object_PeriodType2() throws Throwable {
1208: Period test = new Period((Object) null, PeriodType
1209: .yearMonthDayTime());
1210: assertEquals(PeriodType.yearMonthDayTime(), test
1211: .getPeriodType());
1212: assertEquals(0, test.getYears());
1213: assertEquals(0, test.getMonths());
1214: assertEquals(0, test.getWeeks());
1215: assertEquals(0, test.getDays());
1216: assertEquals(0, test.getHours());
1217: assertEquals(0, test.getMinutes());
1218: assertEquals(0, test.getSeconds());
1219: assertEquals(0, test.getMillis());
1220: }
1221:
1222: public void testConstructor_Object_PeriodType3() throws Throwable {
1223: Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4,
1224: PeriodType.dayTime()), PeriodType.yearMonthDayTime());
1225: assertEquals(PeriodType.yearMonthDayTime(), test
1226: .getPeriodType());
1227: assertEquals(0, test.getYears());
1228: assertEquals(0, test.getMonths());
1229: assertEquals(0, test.getWeeks());
1230: assertEquals(0, test.getDays());
1231: assertEquals(1, test.getHours());
1232: assertEquals(2, test.getMinutes());
1233: assertEquals(3, test.getSeconds());
1234: assertEquals(4, test.getMillis());
1235: }
1236:
1237: public void testConstructor_Object_PeriodType4() throws Throwable {
1238: Period test = new Period(new Period(0, 0, 0, 0, 1, 2, 3, 4,
1239: PeriodType.dayTime()), (PeriodType) null);
1240: assertEquals(PeriodType.dayTime(), test.getPeriodType());
1241: assertEquals(0, test.getYears());
1242: assertEquals(0, test.getMonths());
1243: assertEquals(0, test.getWeeks());
1244: assertEquals(0, test.getDays());
1245: assertEquals(1, test.getHours());
1246: assertEquals(2, test.getMinutes());
1247: assertEquals(3, test.getSeconds());
1248: assertEquals(4, test.getMillis());
1249: }
1250:
1251: //-----------------------------------------------------------------------
1252: public void testFactoryYears() throws Throwable {
1253: Period test = Period.years(6);
1254: assertEquals(PeriodType.standard(), test.getPeriodType());
1255: assertEquals(6, test.getYears());
1256: assertEquals(0, test.getMonths());
1257: assertEquals(0, test.getWeeks());
1258: assertEquals(0, test.getDays());
1259: assertEquals(0, test.getHours());
1260: assertEquals(0, test.getMinutes());
1261: assertEquals(0, test.getSeconds());
1262: assertEquals(0, test.getMillis());
1263: }
1264:
1265: public void testFactoryMonths() throws Throwable {
1266: Period test = Period.months(6);
1267: assertEquals(PeriodType.standard(), test.getPeriodType());
1268: assertEquals(0, test.getYears());
1269: assertEquals(6, test.getMonths());
1270: assertEquals(0, test.getWeeks());
1271: assertEquals(0, test.getDays());
1272: assertEquals(0, test.getHours());
1273: assertEquals(0, test.getMinutes());
1274: assertEquals(0, test.getSeconds());
1275: assertEquals(0, test.getMillis());
1276: }
1277:
1278: public void testFactoryWeeks() throws Throwable {
1279: Period test = Period.weeks(6);
1280: assertEquals(PeriodType.standard(), test.getPeriodType());
1281: assertEquals(0, test.getYears());
1282: assertEquals(0, test.getMonths());
1283: assertEquals(6, test.getWeeks());
1284: assertEquals(0, test.getDays());
1285: assertEquals(0, test.getHours());
1286: assertEquals(0, test.getMinutes());
1287: assertEquals(0, test.getSeconds());
1288: assertEquals(0, test.getMillis());
1289: }
1290:
1291: public void testFactoryDays() throws Throwable {
1292: Period test = Period.days(6);
1293: assertEquals(PeriodType.standard(), test.getPeriodType());
1294: assertEquals(0, test.getYears());
1295: assertEquals(0, test.getMonths());
1296: assertEquals(0, test.getWeeks());
1297: assertEquals(6, test.getDays());
1298: assertEquals(0, test.getHours());
1299: assertEquals(0, test.getMinutes());
1300: assertEquals(0, test.getSeconds());
1301: assertEquals(0, test.getMillis());
1302: }
1303:
1304: public void testFactoryHours() throws Throwable {
1305: Period test = Period.hours(6);
1306: assertEquals(PeriodType.standard(), test.getPeriodType());
1307: assertEquals(0, test.getYears());
1308: assertEquals(0, test.getMonths());
1309: assertEquals(0, test.getWeeks());
1310: assertEquals(0, test.getDays());
1311: assertEquals(6, test.getHours());
1312: assertEquals(0, test.getMinutes());
1313: assertEquals(0, test.getSeconds());
1314: assertEquals(0, test.getMillis());
1315: }
1316:
1317: public void testFactoryMinutes() throws Throwable {
1318: Period test = Period.minutes(6);
1319: assertEquals(PeriodType.standard(), test.getPeriodType());
1320: assertEquals(0, test.getYears());
1321: assertEquals(0, test.getMonths());
1322: assertEquals(0, test.getWeeks());
1323: assertEquals(0, test.getDays());
1324: assertEquals(0, test.getHours());
1325: assertEquals(6, test.getMinutes());
1326: assertEquals(0, test.getSeconds());
1327: assertEquals(0, test.getMillis());
1328: }
1329:
1330: public void testFactorySeconds() throws Throwable {
1331: Period test = Period.seconds(6);
1332: assertEquals(PeriodType.standard(), test.getPeriodType());
1333: assertEquals(0, test.getYears());
1334: assertEquals(0, test.getMonths());
1335: assertEquals(0, test.getWeeks());
1336: assertEquals(0, test.getDays());
1337: assertEquals(0, test.getHours());
1338: assertEquals(0, test.getMinutes());
1339: assertEquals(6, test.getSeconds());
1340: assertEquals(0, test.getMillis());
1341: }
1342:
1343: public void testFactoryMillis() throws Throwable {
1344: Period test = Period.millis(6);
1345: assertEquals(PeriodType.standard(), test.getPeriodType());
1346: assertEquals(0, test.getYears());
1347: assertEquals(0, test.getMonths());
1348: assertEquals(0, test.getWeeks());
1349: assertEquals(0, test.getDays());
1350: assertEquals(0, test.getHours());
1351: assertEquals(0, test.getMinutes());
1352: assertEquals(0, test.getSeconds());
1353: assertEquals(6, test.getMillis());
1354: }
1355:
1356: //-----------------------------------------------------------------------
1357: public void testFactoryFieldDifference1() throws Throwable {
1358: YearMonthDay start = new YearMonthDay(2005, 4, 9);
1359: DateTimeFieldType[] types = new DateTimeFieldType[] {
1360: DateTimeFieldType.year(),
1361: DateTimeFieldType.monthOfYear(),
1362: DateTimeFieldType.dayOfMonth(), };
1363: Partial end = new Partial(types, new int[] { 2004, 6, 7 });
1364: Period test = Period.fieldDifference(start, end);
1365: assertEquals(PeriodType.yearMonthDay(), test.getPeriodType());
1366: assertEquals(-1, test.getYears());
1367: assertEquals(2, test.getMonths());
1368: assertEquals(0, test.getWeeks());
1369: assertEquals(-2, test.getDays());
1370: assertEquals(0, test.getHours());
1371: assertEquals(0, test.getMinutes());
1372: assertEquals(0, test.getSeconds());
1373: assertEquals(0, test.getMillis());
1374: }
1375:
1376: public void testFactoryFieldDifference2() throws Throwable {
1377: YearMonthDay ymd = new YearMonthDay(2005, 4, 9);
1378: try {
1379: Period.fieldDifference(ymd, (ReadablePartial) null);
1380: fail();
1381: } catch (IllegalArgumentException ex) {
1382: }
1383: try {
1384: Period.fieldDifference((ReadablePartial) null, ymd);
1385: fail();
1386: } catch (IllegalArgumentException ex) {
1387: }
1388: }
1389:
1390: public void testFactoryFieldDifference3() throws Throwable {
1391: YearMonthDay start = new YearMonthDay(2005, 4, 9);
1392: TimeOfDay endTime = new TimeOfDay(12, 30, 40, 0);
1393: try {
1394: Period.fieldDifference(start, endTime);
1395: fail();
1396: } catch (IllegalArgumentException ex) {
1397: }
1398: }
1399:
1400: public void testFactoryFieldDifference4() throws Throwable {
1401: DateTimeFieldType[] types = new DateTimeFieldType[] {
1402: DateTimeFieldType.year(),
1403: DateTimeFieldType.monthOfYear(),
1404: DateTimeFieldType.dayOfWeek(), };
1405: YearMonthDay start = new YearMonthDay(2005, 4, 9);
1406: Partial end = new Partial(types, new int[] { 1, 2, 3 });
1407: try {
1408: Period.fieldDifference(start, end);
1409: fail();
1410: } catch (IllegalArgumentException ex) {
1411: }
1412: }
1413:
1414: public void testFactoryFieldDifference5() throws Throwable {
1415: DateTimeFieldType[] types = new DateTimeFieldType[] {
1416: DateTimeFieldType.year(),
1417: DateTimeFieldType.dayOfMonth(),
1418: DateTimeFieldType.dayOfWeek(), };
1419: Partial start = new Partial(types, new int[] { 1, 2, 3 });
1420: Partial end = new Partial(types, new int[] { 1, 2, 3 });
1421: try {
1422: Period.fieldDifference(start, end);
1423: fail();
1424: } catch (IllegalArgumentException ex) {
1425: }
1426: }
1427:
1428: }
|