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 junit.framework.TestCase;
0019: import junit.framework.TestSuite;
0020:
0021: /**
0022: * This class is a JUnit test for DateTimeZone.
0023: *
0024: * @author Stephen Colebourne
0025: */
0026: public class TestDateTimeZoneCutover extends TestCase {
0027:
0028: public static void main(String[] args) {
0029: junit.textui.TestRunner.run(suite());
0030: }
0031:
0032: public static TestSuite suite() {
0033: return new TestSuite(TestDateTimeZoneCutover.class);
0034: }
0035:
0036: public TestDateTimeZoneCutover(String name) {
0037: super (name);
0038: }
0039:
0040: protected void setUp() throws Exception {
0041: }
0042:
0043: protected void tearDown() throws Exception {
0044: }
0045:
0046: //-----------------------------------------------------------------------
0047: //------------------------ Bug [1710316] --------------------------------
0048: //-----------------------------------------------------------------------
0049: // The behaviour of getOffsetFromLocal is defined in its javadoc
0050: // However, this definition doesn't work for all DateTimeField operations
0051:
0052: /** Mock zone simulating Asia/Gaza cutover at midnight 2007-04-01 */
0053: private static long CUTOVER_GAZA = 1175378400000L;
0054: private static int OFFSET_GAZA = 7200000; // +02:00
0055: private static final DateTimeZone MOCK_GAZA = new MockZone(
0056: CUTOVER_GAZA, OFFSET_GAZA);
0057:
0058: //-----------------------------------------------------------------------
0059: public void test_MockGazaIsCorrect() {
0060: DateTime pre = new DateTime(CUTOVER_GAZA - 1L, MOCK_GAZA);
0061: assertEquals("2007-03-31T23:59:59.999+02:00", pre.toString());
0062: DateTime at = new DateTime(CUTOVER_GAZA, MOCK_GAZA);
0063: assertEquals("2007-04-01T01:00:00.000+03:00", at.toString());
0064: DateTime post = new DateTime(CUTOVER_GAZA + 1L, MOCK_GAZA);
0065: assertEquals("2007-04-01T01:00:00.001+03:00", post.toString());
0066: }
0067:
0068: public void test_getOffsetFromLocal_Gaza() {
0069: doTest_getOffsetFromLocal_Gaza(-1, 23, 0,
0070: "2007-03-31T23:00:00.000+02:00");
0071: doTest_getOffsetFromLocal_Gaza(-1, 23, 30,
0072: "2007-03-31T23:30:00.000+02:00");
0073: doTest_getOffsetFromLocal_Gaza(0, 0, 0,
0074: "2007-04-01T01:00:00.000+03:00");
0075: doTest_getOffsetFromLocal_Gaza(0, 0, 30,
0076: "2007-04-01T01:30:00.000+03:00");
0077: doTest_getOffsetFromLocal_Gaza(0, 1, 0,
0078: "2007-04-01T01:00:00.000+03:00");
0079: doTest_getOffsetFromLocal_Gaza(0, 1, 30,
0080: "2007-04-01T01:30:00.000+03:00");
0081: doTest_getOffsetFromLocal_Gaza(0, 2, 0,
0082: "2007-04-01T02:00:00.000+03:00");
0083: doTest_getOffsetFromLocal_Gaza(0, 3, 0,
0084: "2007-04-01T03:00:00.000+03:00");
0085: doTest_getOffsetFromLocal_Gaza(0, 4, 0,
0086: "2007-04-01T04:00:00.000+03:00");
0087: doTest_getOffsetFromLocal_Gaza(0, 5, 0,
0088: "2007-04-01T05:00:00.000+03:00");
0089: doTest_getOffsetFromLocal_Gaza(0, 6, 0,
0090: "2007-04-01T06:00:00.000+03:00");
0091: }
0092:
0093: private void doTest_getOffsetFromLocal_Gaza(int days, int hour,
0094: int min, String expected) {
0095: DateTime dt = new DateTime(2007, 4, 1, hour, min, 0, 0,
0096: DateTimeZone.UTC).plusDays(days);
0097: int offset = MOCK_GAZA.getOffsetFromLocal(dt.getMillis());
0098: DateTime res = new DateTime(dt.getMillis() - offset, MOCK_GAZA);
0099: assertEquals(res.toString(), expected, res.toString());
0100: }
0101:
0102: public void test_DateTime_roundFloor_Gaza() {
0103: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_GAZA);
0104: assertEquals("2007-04-01T08:00:00.000+03:00", dt.toString());
0105: DateTime rounded = dt.dayOfMonth().roundFloorCopy();
0106: assertEquals("2007-04-01T01:00:00.000+03:00", rounded
0107: .toString());
0108: }
0109:
0110: public void test_DateTime_roundCeiling_Gaza() {
0111: DateTime dt = new DateTime(2007, 3, 31, 20, 0, 0, 0, MOCK_GAZA);
0112: assertEquals("2007-03-31T20:00:00.000+02:00", dt.toString());
0113: DateTime rounded = dt.dayOfMonth().roundCeilingCopy();
0114: assertEquals("2007-04-01T01:00:00.000+03:00", rounded
0115: .toString());
0116: }
0117:
0118: public void test_DateTime_setHourZero_Gaza() {
0119: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_GAZA);
0120: assertEquals("2007-04-01T08:00:00.000+03:00", dt.toString());
0121: try {
0122: dt.hourOfDay().setCopy(0);
0123: fail();
0124: } catch (IllegalFieldValueException ex) {
0125: // expected
0126: }
0127: }
0128:
0129: public void test_DateTime_withHourZero_Gaza() {
0130: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_GAZA);
0131: assertEquals("2007-04-01T08:00:00.000+03:00", dt.toString());
0132: try {
0133: dt.withHourOfDay(0);
0134: fail();
0135: } catch (IllegalFieldValueException ex) {
0136: // expected
0137: }
0138: }
0139:
0140: public void test_DateTime_withDay_Gaza() {
0141: DateTime dt = new DateTime(2007, 4, 2, 0, 0, 0, 0, MOCK_GAZA);
0142: assertEquals("2007-04-02T00:00:00.000+03:00", dt.toString());
0143: DateTime res = dt.withDayOfMonth(1);
0144: assertEquals("2007-04-01T01:00:00.000+03:00", res.toString());
0145: }
0146:
0147: public void test_DateTime_minusHour_Gaza() {
0148: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_GAZA);
0149: assertEquals("2007-04-01T08:00:00.000+03:00", dt.toString());
0150:
0151: DateTime minus7 = dt.minusHours(7);
0152: assertEquals("2007-04-01T01:00:00.000+03:00", minus7.toString());
0153: DateTime minus8 = dt.minusHours(8);
0154: assertEquals("2007-03-31T23:00:00.000+02:00", minus8.toString());
0155: DateTime minus9 = dt.minusHours(9);
0156: assertEquals("2007-03-31T22:00:00.000+02:00", minus9.toString());
0157: }
0158:
0159: public void test_DateTime_plusHour_Gaza() {
0160: DateTime dt = new DateTime(2007, 3, 31, 16, 0, 0, 0, MOCK_GAZA);
0161: assertEquals("2007-03-31T16:00:00.000+02:00", dt.toString());
0162:
0163: DateTime plus7 = dt.plusHours(7);
0164: assertEquals("2007-03-31T23:00:00.000+02:00", plus7.toString());
0165: DateTime plus8 = dt.plusHours(8);
0166: assertEquals("2007-04-01T01:00:00.000+03:00", plus8.toString());
0167: DateTime plus9 = dt.plusHours(9);
0168: assertEquals("2007-04-01T02:00:00.000+03:00", plus9.toString());
0169: }
0170:
0171: public void test_DateTime_minusDay_Gaza() {
0172: DateTime dt = new DateTime(2007, 4, 2, 0, 0, 0, 0, MOCK_GAZA);
0173: assertEquals("2007-04-02T00:00:00.000+03:00", dt.toString());
0174:
0175: DateTime minus1 = dt.minusDays(1);
0176: assertEquals("2007-04-01T01:00:00.000+03:00", minus1.toString());
0177: DateTime minus2 = dt.minusDays(2);
0178: assertEquals("2007-03-31T00:00:00.000+02:00", minus2.toString());
0179: }
0180:
0181: public void test_DateTime_plusDay_Gaza() {
0182: DateTime dt = new DateTime(2007, 3, 31, 0, 0, 0, 0, MOCK_GAZA);
0183: assertEquals("2007-03-31T00:00:00.000+02:00", dt.toString());
0184:
0185: DateTime plus1 = dt.plusDays(1);
0186: assertEquals("2007-04-01T01:00:00.000+03:00", plus1.toString());
0187: DateTime plus2 = dt.plusDays(2);
0188: assertEquals("2007-04-02T00:00:00.000+03:00", plus2.toString());
0189: }
0190:
0191: public void test_DateTime_plusDayMidGap_Gaza() {
0192: DateTime dt = new DateTime(2007, 3, 31, 0, 30, 0, 0, MOCK_GAZA);
0193: assertEquals("2007-03-31T00:30:00.000+02:00", dt.toString());
0194:
0195: DateTime plus1 = dt.plusDays(1);
0196: assertEquals("2007-04-01T01:30:00.000+03:00", plus1.toString());
0197: DateTime plus2 = dt.plusDays(2);
0198: assertEquals("2007-04-02T00:30:00.000+03:00", plus2.toString());
0199: }
0200:
0201: public void test_DateTime_addWrapFieldDay_Gaza() {
0202: DateTime dt = new DateTime(2007, 4, 30, 0, 0, 0, 0, MOCK_GAZA);
0203: assertEquals("2007-04-30T00:00:00.000+03:00", dt.toString());
0204:
0205: DateTime plus1 = dt.dayOfMonth().addWrapFieldToCopy(1);
0206: assertEquals("2007-04-01T01:00:00.000+03:00", plus1.toString());
0207: DateTime plus2 = dt.dayOfMonth().addWrapFieldToCopy(2);
0208: assertEquals("2007-04-02T00:00:00.000+03:00", plus2.toString());
0209: }
0210:
0211: public void test_DateTime_withZoneRetainFields_Gaza() {
0212: DateTime dt = new DateTime(2007, 4, 1, 0, 0, 0, 0,
0213: DateTimeZone.UTC);
0214: assertEquals("2007-04-01T00:00:00.000Z", dt.toString());
0215:
0216: DateTime res = dt.withZoneRetainFields(MOCK_GAZA);
0217: assertEquals("2007-04-01T01:00:00.000+03:00", res.toString());
0218: }
0219:
0220: public void test_MutableDateTime_withZoneRetainFields_Gaza() {
0221: MutableDateTime dt = new MutableDateTime(2007, 4, 1, 0, 0, 0,
0222: 0, DateTimeZone.UTC);
0223: assertEquals("2007-04-01T00:00:00.000Z", dt.toString());
0224:
0225: dt.setZoneRetainFields(MOCK_GAZA);
0226: assertEquals("2007-04-01T01:00:00.000+03:00", dt.toString());
0227: }
0228:
0229: public void test_LocalDate_new_Gaza() {
0230: LocalDate date1 = new LocalDate(CUTOVER_GAZA, MOCK_GAZA);
0231: assertEquals("2007-04-01", date1.toString());
0232:
0233: LocalDate date2 = new LocalDate(CUTOVER_GAZA - 1, MOCK_GAZA);
0234: assertEquals("2007-03-31", date2.toString());
0235: }
0236:
0237: public void test_LocalDate_toDateTimeAtMidnight_Gaza() {
0238: LocalDate date = new LocalDate(2007, 4, 1);
0239: try {
0240: date.toDateTimeAtMidnight(MOCK_GAZA);
0241: fail();
0242: } catch (IllegalArgumentException ex) {
0243: assertEquals(
0244: true,
0245: ex
0246: .getMessage()
0247: .startsWith(
0248: "Illegal instant due to time zone offset transition"));
0249: }
0250: }
0251:
0252: public void test_LocalDate_toDateMidnight_Gaza() {
0253: LocalDate date = new LocalDate(2007, 4, 1);
0254: try {
0255: date.toDateMidnight(MOCK_GAZA);
0256: fail();
0257: } catch (IllegalArgumentException ex) {
0258: assertEquals(
0259: true,
0260: ex
0261: .getMessage()
0262: .startsWith(
0263: "Illegal instant due to time zone offset transition"));
0264: }
0265: }
0266:
0267: public void test_DateTime_new_Gaza() {
0268: try {
0269: new DateTime(2007, 4, 1, 0, 0, 0, 0, MOCK_GAZA);
0270: fail();
0271: } catch (IllegalArgumentException ex) {
0272: assertEquals(
0273: true,
0274: ex
0275: .getMessage()
0276: .indexOf(
0277: "Illegal instant due to time zone offset transition") >= 0);
0278: }
0279: }
0280:
0281: public void test_DateTime_newValid_Gaza() {
0282: new DateTime(2007, 3, 31, 19, 0, 0, 0, MOCK_GAZA);
0283: new DateTime(2007, 3, 31, 20, 0, 0, 0, MOCK_GAZA);
0284: new DateTime(2007, 3, 31, 21, 0, 0, 0, MOCK_GAZA);
0285: new DateTime(2007, 3, 31, 22, 0, 0, 0, MOCK_GAZA);
0286: new DateTime(2007, 3, 31, 23, 0, 0, 0, MOCK_GAZA);
0287: new DateTime(2007, 4, 1, 1, 0, 0, 0, MOCK_GAZA);
0288: new DateTime(2007, 4, 1, 2, 0, 0, 0, MOCK_GAZA);
0289: new DateTime(2007, 4, 1, 3, 0, 0, 0, MOCK_GAZA);
0290: }
0291:
0292: public void test_DateTime_parse_Gaza() {
0293: try {
0294: new DateTime("2007-04-01T00:00", MOCK_GAZA);
0295: fail();
0296: } catch (IllegalArgumentException ex) {
0297: assertEquals(
0298: true,
0299: ex
0300: .getMessage()
0301: .indexOf(
0302: "Illegal instant due to time zone offset transition") >= 0);
0303: }
0304: }
0305:
0306: //-----------------------------------------------------------------------
0307: //------------------------ Bug [1710316] --------------------------------
0308: //-----------------------------------------------------------------------
0309: /** Mock zone simulating America/Grand_Turk cutover at midnight 2007-04-01 */
0310: private static long CUTOVER_TURK = 1175403600000L;
0311: private static int OFFSET_TURK = -18000000; // -05:00
0312: private static final DateTimeZone MOCK_TURK = new MockZone(
0313: CUTOVER_TURK, OFFSET_TURK);
0314:
0315: //-----------------------------------------------------------------------
0316: public void test_MockTurkIsCorrect() {
0317: DateTime pre = new DateTime(CUTOVER_TURK - 1L, MOCK_TURK);
0318: assertEquals("2007-03-31T23:59:59.999-05:00", pre.toString());
0319: DateTime at = new DateTime(CUTOVER_TURK, MOCK_TURK);
0320: assertEquals("2007-04-01T01:00:00.000-04:00", at.toString());
0321: DateTime post = new DateTime(CUTOVER_TURK + 1L, MOCK_TURK);
0322: assertEquals("2007-04-01T01:00:00.001-04:00", post.toString());
0323: }
0324:
0325: public void test_getOffsetFromLocal_Turk() {
0326: doTest_getOffsetFromLocal_Turk(-1, 23, 0,
0327: "2007-03-31T23:00:00.000-05:00");
0328: doTest_getOffsetFromLocal_Turk(-1, 23, 30,
0329: "2007-03-31T23:30:00.000-05:00");
0330: doTest_getOffsetFromLocal_Turk(0, 0, 0,
0331: "2007-04-01T01:00:00.000-04:00");
0332: doTest_getOffsetFromLocal_Turk(0, 0, 30,
0333: "2007-04-01T01:30:00.000-04:00");
0334: doTest_getOffsetFromLocal_Turk(0, 1, 0,
0335: "2007-04-01T01:00:00.000-04:00");
0336: doTest_getOffsetFromLocal_Turk(0, 1, 30,
0337: "2007-04-01T01:30:00.000-04:00");
0338: doTest_getOffsetFromLocal_Turk(0, 2, 0,
0339: "2007-04-01T02:00:00.000-04:00");
0340: doTest_getOffsetFromLocal_Turk(0, 3, 0,
0341: "2007-04-01T03:00:00.000-04:00");
0342: doTest_getOffsetFromLocal_Turk(0, 4, 0,
0343: "2007-04-01T04:00:00.000-04:00");
0344: doTest_getOffsetFromLocal_Turk(0, 5, 0,
0345: "2007-04-01T05:00:00.000-04:00");
0346: doTest_getOffsetFromLocal_Turk(0, 6, 0,
0347: "2007-04-01T06:00:00.000-04:00");
0348: }
0349:
0350: private void doTest_getOffsetFromLocal_Turk(int days, int hour,
0351: int min, String expected) {
0352: DateTime dt = new DateTime(2007, 4, 1, hour, min, 0, 0,
0353: DateTimeZone.UTC).plusDays(days);
0354: int offset = MOCK_TURK.getOffsetFromLocal(dt.getMillis());
0355: DateTime res = new DateTime(dt.getMillis() - offset, MOCK_TURK);
0356: assertEquals(res.toString(), expected, res.toString());
0357: }
0358:
0359: public void test_DateTime_roundFloor_Turk() {
0360: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_TURK);
0361: assertEquals("2007-04-01T08:00:00.000-04:00", dt.toString());
0362: DateTime rounded = dt.dayOfMonth().roundFloorCopy();
0363: assertEquals("2007-04-01T01:00:00.000-04:00", rounded
0364: .toString());
0365: }
0366:
0367: public void test_DateTime_roundFloorNotDST_Turk() {
0368: DateTime dt = new DateTime(2007, 4, 2, 8, 0, 0, 0, MOCK_TURK);
0369: assertEquals("2007-04-02T08:00:00.000-04:00", dt.toString());
0370: DateTime rounded = dt.dayOfMonth().roundFloorCopy();
0371: assertEquals("2007-04-02T00:00:00.000-04:00", rounded
0372: .toString());
0373: }
0374:
0375: public void test_DateTime_roundCeiling_Turk() {
0376: DateTime dt = new DateTime(2007, 3, 31, 20, 0, 0, 0, MOCK_TURK);
0377: assertEquals("2007-03-31T20:00:00.000-05:00", dt.toString());
0378: DateTime rounded = dt.dayOfMonth().roundCeilingCopy();
0379: assertEquals("2007-04-01T01:00:00.000-04:00", rounded
0380: .toString());
0381: }
0382:
0383: public void test_DateTime_setHourZero_Turk() {
0384: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_TURK);
0385: assertEquals("2007-04-01T08:00:00.000-04:00", dt.toString());
0386: try {
0387: dt.hourOfDay().setCopy(0);
0388: fail();
0389: } catch (IllegalFieldValueException ex) {
0390: // expected
0391: }
0392: }
0393:
0394: public void test_DateTime_withHourZero_Turk() {
0395: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_TURK);
0396: assertEquals("2007-04-01T08:00:00.000-04:00", dt.toString());
0397: try {
0398: dt.withHourOfDay(0);
0399: fail();
0400: } catch (IllegalFieldValueException ex) {
0401: // expected
0402: }
0403: }
0404:
0405: public void test_DateTime_withDay_Turk() {
0406: DateTime dt = new DateTime(2007, 4, 2, 0, 0, 0, 0, MOCK_TURK);
0407: assertEquals("2007-04-02T00:00:00.000-04:00", dt.toString());
0408: DateTime res = dt.withDayOfMonth(1);
0409: assertEquals("2007-04-01T01:00:00.000-04:00", res.toString());
0410: }
0411:
0412: public void test_DateTime_minusHour_Turk() {
0413: DateTime dt = new DateTime(2007, 4, 1, 8, 0, 0, 0, MOCK_TURK);
0414: assertEquals("2007-04-01T08:00:00.000-04:00", dt.toString());
0415:
0416: DateTime minus7 = dt.minusHours(7);
0417: assertEquals("2007-04-01T01:00:00.000-04:00", minus7.toString());
0418: DateTime minus8 = dt.minusHours(8);
0419: assertEquals("2007-03-31T23:00:00.000-05:00", minus8.toString());
0420: DateTime minus9 = dt.minusHours(9);
0421: assertEquals("2007-03-31T22:00:00.000-05:00", minus9.toString());
0422: }
0423:
0424: public void test_DateTime_plusHour_Turk() {
0425: DateTime dt = new DateTime(2007, 3, 31, 16, 0, 0, 0, MOCK_TURK);
0426: assertEquals("2007-03-31T16:00:00.000-05:00", dt.toString());
0427:
0428: DateTime plus7 = dt.plusHours(7);
0429: assertEquals("2007-03-31T23:00:00.000-05:00", plus7.toString());
0430: DateTime plus8 = dt.plusHours(8);
0431: assertEquals("2007-04-01T01:00:00.000-04:00", plus8.toString());
0432: DateTime plus9 = dt.plusHours(9);
0433: assertEquals("2007-04-01T02:00:00.000-04:00", plus9.toString());
0434: }
0435:
0436: public void test_DateTime_minusDay_Turk() {
0437: DateTime dt = new DateTime(2007, 4, 2, 0, 0, 0, 0, MOCK_TURK);
0438: assertEquals("2007-04-02T00:00:00.000-04:00", dt.toString());
0439:
0440: DateTime minus1 = dt.minusDays(1);
0441: assertEquals("2007-04-01T01:00:00.000-04:00", minus1.toString());
0442: DateTime minus2 = dt.minusDays(2);
0443: assertEquals("2007-03-31T00:00:00.000-05:00", minus2.toString());
0444: }
0445:
0446: public void test_DateTime_plusDay_Turk() {
0447: DateTime dt = new DateTime(2007, 3, 31, 0, 0, 0, 0, MOCK_TURK);
0448: assertEquals("2007-03-31T00:00:00.000-05:00", dt.toString());
0449:
0450: DateTime plus1 = dt.plusDays(1);
0451: assertEquals("2007-04-01T01:00:00.000-04:00", plus1.toString());
0452: DateTime plus2 = dt.plusDays(2);
0453: assertEquals("2007-04-02T00:00:00.000-04:00", plus2.toString());
0454: }
0455:
0456: public void test_DateTime_plusDayMidGap_Turk() {
0457: DateTime dt = new DateTime(2007, 3, 31, 0, 30, 0, 0, MOCK_TURK);
0458: assertEquals("2007-03-31T00:30:00.000-05:00", dt.toString());
0459:
0460: DateTime plus1 = dt.plusDays(1);
0461: assertEquals("2007-04-01T01:30:00.000-04:00", plus1.toString());
0462: DateTime plus2 = dt.plusDays(2);
0463: assertEquals("2007-04-02T00:30:00.000-04:00", plus2.toString());
0464: }
0465:
0466: public void test_DateTime_addWrapFieldDay_Turk() {
0467: DateTime dt = new DateTime(2007, 4, 30, 0, 0, 0, 0, MOCK_TURK);
0468: assertEquals("2007-04-30T00:00:00.000-04:00", dt.toString());
0469:
0470: DateTime plus1 = dt.dayOfMonth().addWrapFieldToCopy(1);
0471: assertEquals("2007-04-01T01:00:00.000-04:00", plus1.toString());
0472: DateTime plus2 = dt.dayOfMonth().addWrapFieldToCopy(2);
0473: assertEquals("2007-04-02T00:00:00.000-04:00", plus2.toString());
0474: }
0475:
0476: public void test_DateTime_withZoneRetainFields_Turk() {
0477: DateTime dt = new DateTime(2007, 4, 1, 0, 0, 0, 0,
0478: DateTimeZone.UTC);
0479: assertEquals("2007-04-01T00:00:00.000Z", dt.toString());
0480:
0481: DateTime res = dt.withZoneRetainFields(MOCK_TURK);
0482: assertEquals("2007-04-01T01:00:00.000-04:00", res.toString());
0483: }
0484:
0485: public void test_MutableDateTime_setZoneRetainFields_Turk() {
0486: MutableDateTime dt = new MutableDateTime(2007, 4, 1, 0, 0, 0,
0487: 0, DateTimeZone.UTC);
0488: assertEquals("2007-04-01T00:00:00.000Z", dt.toString());
0489:
0490: dt.setZoneRetainFields(MOCK_TURK);
0491: assertEquals("2007-04-01T01:00:00.000-04:00", dt.toString());
0492: }
0493:
0494: public void test_LocalDate_new_Turk() {
0495: LocalDate date1 = new LocalDate(CUTOVER_TURK, MOCK_TURK);
0496: assertEquals("2007-04-01", date1.toString());
0497:
0498: LocalDate date2 = new LocalDate(CUTOVER_TURK - 1, MOCK_TURK);
0499: assertEquals("2007-03-31", date2.toString());
0500: }
0501:
0502: public void test_LocalDate_toDateTimeAtMidnight_Turk() {
0503: LocalDate date = new LocalDate(2007, 4, 1);
0504: try {
0505: date.toDateTimeAtMidnight(MOCK_TURK);
0506: fail();
0507: } catch (IllegalArgumentException ex) {
0508: assertEquals(
0509: true,
0510: ex
0511: .getMessage()
0512: .startsWith(
0513: "Illegal instant due to time zone offset transition"));
0514: }
0515: }
0516:
0517: public void test_LocalDate_toDateMidnight_Turk() {
0518: LocalDate date = new LocalDate(2007, 4, 1);
0519: try {
0520: date.toDateMidnight(MOCK_TURK);
0521: fail();
0522: } catch (IllegalArgumentException ex) {
0523: assertEquals(
0524: true,
0525: ex
0526: .getMessage()
0527: .startsWith(
0528: "Illegal instant due to time zone offset transition"));
0529: }
0530: }
0531:
0532: public void test_DateTime_new_Turk() {
0533: try {
0534: new DateTime(2007, 4, 1, 0, 0, 0, 0, MOCK_TURK);
0535: fail();
0536: } catch (IllegalArgumentException ex) {
0537: assertEquals(
0538: true,
0539: ex
0540: .getMessage()
0541: .indexOf(
0542: "Illegal instant due to time zone offset transition") >= 0);
0543: }
0544: }
0545:
0546: public void test_DateTime_newValid_Turk() {
0547: new DateTime(2007, 3, 31, 23, 0, 0, 0, MOCK_TURK);
0548: new DateTime(2007, 4, 1, 1, 0, 0, 0, MOCK_TURK);
0549: new DateTime(2007, 4, 1, 2, 0, 0, 0, MOCK_TURK);
0550: new DateTime(2007, 4, 1, 3, 0, 0, 0, MOCK_TURK);
0551: new DateTime(2007, 4, 1, 4, 0, 0, 0, MOCK_TURK);
0552: new DateTime(2007, 4, 1, 5, 0, 0, 0, MOCK_TURK);
0553: new DateTime(2007, 4, 1, 6, 0, 0, 0, MOCK_TURK);
0554: }
0555:
0556: public void test_DateTime_parse_Turk() {
0557: try {
0558: new DateTime("2007-04-01T00:00", MOCK_TURK);
0559: fail();
0560: } catch (IllegalArgumentException ex) {
0561: assertEquals(
0562: true,
0563: ex
0564: .getMessage()
0565: .indexOf(
0566: "Illegal instant due to time zone offset transition") >= 0);
0567: }
0568: }
0569:
0570: //-----------------------------------------------------------------------
0571: //-----------------------------------------------------------------------
0572: //-----------------------------------------------------------------------
0573: /** America/New_York cutover from 01:59 to 03:00 on 2007-03-11 */
0574: private static long CUTOVER_NEW_YORK_SPRING = 1173596400000L; // 2007-03-11T03:00:00.000-04:00
0575: private static final DateTimeZone ZONE_NEW_YORK = DateTimeZone
0576: .forID("America/New_York");
0577:
0578: // DateTime x = new DateTime(2007, 1, 1, 0, 0, 0, 0, ZONE_NEW_YORK);
0579: // System.out.println(ZONE_NEW_YORK.nextTransition(x.getMillis()));
0580: // DateTime y = new DateTime(ZONE_NEW_YORK.nextTransition(x.getMillis()), ZONE_NEW_YORK);
0581: // System.out.println(y);
0582:
0583: //-----------------------------------------------------------------------
0584: public void test_NewYorkIsCorrect_Spring() {
0585: DateTime pre = new DateTime(CUTOVER_NEW_YORK_SPRING - 1L,
0586: ZONE_NEW_YORK);
0587: assertEquals("2007-03-11T01:59:59.999-05:00", pre.toString());
0588: DateTime at = new DateTime(CUTOVER_NEW_YORK_SPRING,
0589: ZONE_NEW_YORK);
0590: assertEquals("2007-03-11T03:00:00.000-04:00", at.toString());
0591: DateTime post = new DateTime(CUTOVER_NEW_YORK_SPRING + 1L,
0592: ZONE_NEW_YORK);
0593: assertEquals("2007-03-11T03:00:00.001-04:00", post.toString());
0594: }
0595:
0596: public void test_getOffsetFromLocal_NewYork_Spring() {
0597: doTest_getOffsetFromLocal(3, 11, 1, 0,
0598: "2007-03-11T01:00:00.000-05:00", ZONE_NEW_YORK);
0599: doTest_getOffsetFromLocal(3, 11, 1, 30,
0600: "2007-03-11T01:30:00.000-05:00", ZONE_NEW_YORK);
0601:
0602: doTest_getOffsetFromLocal(3, 11, 2, 0,
0603: "2007-03-11T03:00:00.000-04:00", ZONE_NEW_YORK);
0604: doTest_getOffsetFromLocal(3, 11, 2, 30,
0605: "2007-03-11T03:30:00.000-04:00", ZONE_NEW_YORK);
0606:
0607: doTest_getOffsetFromLocal(3, 11, 3, 0,
0608: "2007-03-11T03:00:00.000-04:00", ZONE_NEW_YORK);
0609: doTest_getOffsetFromLocal(3, 11, 3, 30,
0610: "2007-03-11T03:30:00.000-04:00", ZONE_NEW_YORK);
0611: doTest_getOffsetFromLocal(3, 11, 4, 0,
0612: "2007-03-11T04:00:00.000-04:00", ZONE_NEW_YORK);
0613: doTest_getOffsetFromLocal(3, 11, 5, 0,
0614: "2007-03-11T05:00:00.000-04:00", ZONE_NEW_YORK);
0615: doTest_getOffsetFromLocal(3, 11, 6, 0,
0616: "2007-03-11T06:00:00.000-04:00", ZONE_NEW_YORK);
0617: doTest_getOffsetFromLocal(3, 11, 7, 0,
0618: "2007-03-11T07:00:00.000-04:00", ZONE_NEW_YORK);
0619: doTest_getOffsetFromLocal(3, 11, 8, 0,
0620: "2007-03-11T08:00:00.000-04:00", ZONE_NEW_YORK);
0621: }
0622:
0623: public void test_DateTime_setHourAcross_NewYork_Spring() {
0624: DateTime dt = new DateTime(2007, 3, 11, 0, 0, 0, 0,
0625: ZONE_NEW_YORK);
0626: assertEquals("2007-03-11T00:00:00.000-05:00", dt.toString());
0627: DateTime res = dt.hourOfDay().setCopy(4);
0628: assertEquals("2007-03-11T04:00:00.000-04:00", res.toString());
0629: }
0630:
0631: public void test_DateTime_setHourForward_NewYork_Spring() {
0632: DateTime dt = new DateTime(2007, 3, 11, 0, 0, 0, 0,
0633: ZONE_NEW_YORK);
0634: assertEquals("2007-03-11T00:00:00.000-05:00", dt.toString());
0635:
0636: try {
0637: dt.hourOfDay().setCopy(2);
0638: fail();
0639: } catch (IllegalFieldValueException ex) {
0640: // expected
0641: }
0642: }
0643:
0644: public void test_DateTime_setHourBack_NewYork_Spring() {
0645: DateTime dt = new DateTime(2007, 3, 11, 8, 0, 0, 0,
0646: ZONE_NEW_YORK);
0647: assertEquals("2007-03-11T08:00:00.000-04:00", dt.toString());
0648:
0649: try {
0650: dt.hourOfDay().setCopy(2);
0651: fail();
0652: } catch (IllegalFieldValueException ex) {
0653: // expected
0654: }
0655: }
0656:
0657: //-----------------------------------------------------------------------
0658: /** America/New_York cutover from 01:59 to 01:00 on 2007-11-04 */
0659: private static long CUTOVER_NEW_YORK_AUTUMN = 1194156000000L; // 2007-11-04T01:00:00.000-05:00
0660:
0661: //-----------------------------------------------------------------------
0662: public void test_NewYorkIsCorrect_Autumn() {
0663: DateTime pre = new DateTime(CUTOVER_NEW_YORK_AUTUMN - 1L,
0664: ZONE_NEW_YORK);
0665: assertEquals("2007-11-04T01:59:59.999-04:00", pre.toString());
0666: DateTime at = new DateTime(CUTOVER_NEW_YORK_AUTUMN,
0667: ZONE_NEW_YORK);
0668: assertEquals("2007-11-04T01:00:00.000-05:00", at.toString());
0669: DateTime post = new DateTime(CUTOVER_NEW_YORK_AUTUMN + 1L,
0670: ZONE_NEW_YORK);
0671: assertEquals("2007-11-04T01:00:00.001-05:00", post.toString());
0672: }
0673:
0674: public void test_getOffsetFromLocal_NewYork_Autumn() {
0675: doTest_getOffsetFromLocal(11, 4, 0, 0,
0676: "2007-11-04T00:00:00.000-04:00", ZONE_NEW_YORK);
0677: doTest_getOffsetFromLocal(11, 4, 0, 30,
0678: "2007-11-04T00:30:00.000-04:00", ZONE_NEW_YORK);
0679:
0680: doTest_getOffsetFromLocal(11, 4, 1, 0,
0681: "2007-11-04T01:00:00.000-04:00", ZONE_NEW_YORK);
0682: doTest_getOffsetFromLocal(11, 4, 1, 30,
0683: "2007-11-04T01:30:00.000-04:00", ZONE_NEW_YORK);
0684:
0685: doTest_getOffsetFromLocal(11, 4, 2, 0,
0686: "2007-11-04T02:00:00.000-05:00", ZONE_NEW_YORK);
0687: doTest_getOffsetFromLocal(11, 4, 2, 30,
0688: "2007-11-04T02:30:00.000-05:00", ZONE_NEW_YORK);
0689: doTest_getOffsetFromLocal(11, 4, 3, 0,
0690: "2007-11-04T03:00:00.000-05:00", ZONE_NEW_YORK);
0691: doTest_getOffsetFromLocal(11, 4, 3, 30,
0692: "2007-11-04T03:30:00.000-05:00", ZONE_NEW_YORK);
0693: doTest_getOffsetFromLocal(11, 4, 4, 0,
0694: "2007-11-04T04:00:00.000-05:00", ZONE_NEW_YORK);
0695: doTest_getOffsetFromLocal(11, 4, 5, 0,
0696: "2007-11-04T05:00:00.000-05:00", ZONE_NEW_YORK);
0697: doTest_getOffsetFromLocal(11, 4, 6, 0,
0698: "2007-11-04T06:00:00.000-05:00", ZONE_NEW_YORK);
0699: doTest_getOffsetFromLocal(11, 4, 7, 0,
0700: "2007-11-04T07:00:00.000-05:00", ZONE_NEW_YORK);
0701: doTest_getOffsetFromLocal(11, 4, 8, 0,
0702: "2007-11-04T08:00:00.000-05:00", ZONE_NEW_YORK);
0703: }
0704:
0705: public void test_DateTime_plusHour_NewYork_Autumn() {
0706: DateTime dt = new DateTime(2007, 11, 3, 18, 0, 0, 0,
0707: ZONE_NEW_YORK);
0708: assertEquals("2007-11-03T18:00:00.000-04:00", dt.toString());
0709:
0710: DateTime plus6 = dt.plusHours(6);
0711: assertEquals("2007-11-04T00:00:00.000-04:00", plus6.toString());
0712: DateTime plus7 = dt.plusHours(7);
0713: assertEquals("2007-11-04T01:00:00.000-04:00", plus7.toString());
0714: DateTime plus8 = dt.plusHours(8);
0715: assertEquals("2007-11-04T01:00:00.000-05:00", plus8.toString());
0716: DateTime plus9 = dt.plusHours(9);
0717: assertEquals("2007-11-04T02:00:00.000-05:00", plus9.toString());
0718: }
0719:
0720: public void test_DateTime_minusHour_NewYork_Autumn() {
0721: DateTime dt = new DateTime(2007, 11, 4, 8, 0, 0, 0,
0722: ZONE_NEW_YORK);
0723: assertEquals("2007-11-04T08:00:00.000-05:00", dt.toString());
0724:
0725: DateTime minus6 = dt.minusHours(6);
0726: assertEquals("2007-11-04T02:00:00.000-05:00", minus6.toString());
0727: DateTime minus7 = dt.minusHours(7);
0728: assertEquals("2007-11-04T01:00:00.000-05:00", minus7.toString());
0729: DateTime minus8 = dt.minusHours(8);
0730: assertEquals("2007-11-04T01:00:00.000-04:00", minus8.toString());
0731: DateTime minus9 = dt.minusHours(9);
0732: assertEquals("2007-11-04T00:00:00.000-04:00", minus9.toString());
0733: }
0734:
0735: //-----------------------------------------------------------------------
0736: /** Europe/Moscow cutover from 01:59 to 03:00 on 2007-03-25 */
0737: private static long CUTOVER_MOSCOW_SPRING = 1174777200000L; // 2007-03-25T03:00:00.000+04:00
0738: private static final DateTimeZone ZONE_MOSCOW = DateTimeZone
0739: .forID("Europe/Moscow");
0740:
0741: //-----------------------------------------------------------------------
0742: public void test_MoscowIsCorrect_Spring() {
0743: // DateTime x = new DateTime(2007, 7, 1, 0, 0, 0, 0, ZONE_MOSCOW);
0744: // System.out.println(ZONE_MOSCOW.nextTransition(x.getMillis()));
0745: // DateTime y = new DateTime(ZONE_MOSCOW.nextTransition(x.getMillis()), ZONE_MOSCOW);
0746: // System.out.println(y);
0747: DateTime pre = new DateTime(CUTOVER_MOSCOW_SPRING - 1L,
0748: ZONE_MOSCOW);
0749: assertEquals("2007-03-25T01:59:59.999+03:00", pre.toString());
0750: DateTime at = new DateTime(CUTOVER_MOSCOW_SPRING, ZONE_MOSCOW);
0751: assertEquals("2007-03-25T03:00:00.000+04:00", at.toString());
0752: DateTime post = new DateTime(CUTOVER_MOSCOW_SPRING + 1L,
0753: ZONE_MOSCOW);
0754: assertEquals("2007-03-25T03:00:00.001+04:00", post.toString());
0755: }
0756:
0757: public void test_getOffsetFromLocal_Moscow_Spring() {
0758: doTest_getOffsetFromLocal(3, 25, 1, 0,
0759: "2007-03-25T01:00:00.000+03:00", ZONE_MOSCOW);
0760: doTest_getOffsetFromLocal(3, 25, 1, 30,
0761: "2007-03-25T01:30:00.000+03:00", ZONE_MOSCOW);
0762:
0763: doTest_getOffsetFromLocal(3, 25, 2, 0,
0764: "2007-03-25T03:00:00.000+04:00", ZONE_MOSCOW);
0765: doTest_getOffsetFromLocal(3, 25, 2, 30,
0766: "2007-03-25T03:30:00.000+04:00", ZONE_MOSCOW);
0767:
0768: doTest_getOffsetFromLocal(3, 25, 3, 0,
0769: "2007-03-25T03:00:00.000+04:00", ZONE_MOSCOW);
0770: doTest_getOffsetFromLocal(3, 25, 3, 30,
0771: "2007-03-25T03:30:00.000+04:00", ZONE_MOSCOW);
0772: doTest_getOffsetFromLocal(3, 25, 4, 0,
0773: "2007-03-25T04:00:00.000+04:00", ZONE_MOSCOW);
0774: doTest_getOffsetFromLocal(3, 25, 5, 0,
0775: "2007-03-25T05:00:00.000+04:00", ZONE_MOSCOW);
0776: doTest_getOffsetFromLocal(3, 25, 6, 0,
0777: "2007-03-25T06:00:00.000+04:00", ZONE_MOSCOW);
0778: doTest_getOffsetFromLocal(3, 25, 7, 0,
0779: "2007-03-25T07:00:00.000+04:00", ZONE_MOSCOW);
0780: doTest_getOffsetFromLocal(3, 25, 8, 0,
0781: "2007-03-25T08:00:00.000+04:00", ZONE_MOSCOW);
0782: }
0783:
0784: public void test_DateTime_setHourAcross_Moscow_Spring() {
0785: DateTime dt = new DateTime(2007, 3, 25, 0, 0, 0, 0, ZONE_MOSCOW);
0786: assertEquals("2007-03-25T00:00:00.000+03:00", dt.toString());
0787: DateTime res = dt.hourOfDay().setCopy(4);
0788: assertEquals("2007-03-25T04:00:00.000+04:00", res.toString());
0789: }
0790:
0791: public void test_DateTime_setHourForward_Moscow_Spring() {
0792: DateTime dt = new DateTime(2007, 3, 25, 0, 0, 0, 0, ZONE_MOSCOW);
0793: assertEquals("2007-03-25T00:00:00.000+03:00", dt.toString());
0794:
0795: try {
0796: dt.hourOfDay().setCopy(2);
0797: fail();
0798: } catch (IllegalFieldValueException ex) {
0799: // expected
0800: }
0801: }
0802:
0803: public void test_DateTime_setHourBack_Moscow_Spring() {
0804: DateTime dt = new DateTime(2007, 3, 25, 8, 0, 0, 0, ZONE_MOSCOW);
0805: assertEquals("2007-03-25T08:00:00.000+04:00", dt.toString());
0806:
0807: try {
0808: dt.hourOfDay().setCopy(2);
0809: fail();
0810: } catch (IllegalFieldValueException ex) {
0811: // expected
0812: }
0813: }
0814:
0815: //-----------------------------------------------------------------------
0816: /** America/New_York cutover from 02:59 to 02:00 on 2007-10-28 */
0817: private static long CUTOVER_MOSCOW_AUTUMN = 1193526000000L; // 2007-10-28T02:00:00.000+03:00
0818:
0819: //-----------------------------------------------------------------------
0820: public void test_MoscowIsCorrect_Autumn() {
0821: DateTime pre = new DateTime(CUTOVER_MOSCOW_AUTUMN - 1L,
0822: ZONE_MOSCOW);
0823: assertEquals("2007-10-28T02:59:59.999+04:00", pre.toString());
0824: DateTime at = new DateTime(CUTOVER_MOSCOW_AUTUMN, ZONE_MOSCOW);
0825: assertEquals("2007-10-28T02:00:00.000+03:00", at.toString());
0826: DateTime post = new DateTime(CUTOVER_MOSCOW_AUTUMN + 1L,
0827: ZONE_MOSCOW);
0828: assertEquals("2007-10-28T02:00:00.001+03:00", post.toString());
0829: }
0830:
0831: // broken, and getOffsetFromLocal has no obvious way to determine which is correct
0832: // public void test_getOffsetFromLocal_Moscow_Autumn() {
0833: // doTest_getOffsetFromLocal(10, 28, 0, 0, "2007-10-28T00:00:00.000+04:00", ZONE_MOSCOW);
0834: // doTest_getOffsetFromLocal(10, 28, 0,30, "2007-10-28T00:30:00.000+04:00", ZONE_MOSCOW);
0835: // doTest_getOffsetFromLocal(10, 28, 1, 0, "2007-10-28T01:00:00.000+04:00", ZONE_MOSCOW);
0836: // doTest_getOffsetFromLocal(10, 28, 1,30, "2007-10-28T01:30:00.000+04:00", ZONE_MOSCOW);
0837: //
0838: // doTest_getOffsetFromLocal(10, 28, 2, 0, "2007-10-28T02:00:00.000+04:00", ZONE_MOSCOW);
0839: // doTest_getOffsetFromLocal(10, 28, 2,30, "2007-10-28T02:30:00.000+04:00", ZONE_MOSCOW);
0840: //
0841: // doTest_getOffsetFromLocal(10, 28, 3, 0, "2007-10-28T03:00:00.000+03:00", ZONE_MOSCOW);
0842: // doTest_getOffsetFromLocal(10, 28, 3,30, "2007-10-28T03:30:00.000+03:00", ZONE_MOSCOW);
0843: // doTest_getOffsetFromLocal(10, 28, 4, 0, "2007-10-28T04:00:00.000+03:00", ZONE_MOSCOW);
0844: // doTest_getOffsetFromLocal(10, 28, 5, 0, "2007-10-28T05:00:00.000+03:00", ZONE_MOSCOW);
0845: // doTest_getOffsetFromLocal(10, 28, 6, 0, "2007-10-28T06:00:00.000+03:00", ZONE_MOSCOW);
0846: // doTest_getOffsetFromLocal(10, 28, 7, 0, "2007-10-28T07:00:00.000+03:00", ZONE_MOSCOW);
0847: // doTest_getOffsetFromLocal(10, 28, 8, 0, "2007-10-28T08:00:00.000+03:00", ZONE_MOSCOW);
0848: // }
0849:
0850: public void test_DateTime_plusHour_Moscow_Autumn() {
0851: DateTime dt = new DateTime(2007, 10, 27, 19, 0, 0, 0,
0852: ZONE_MOSCOW);
0853: assertEquals("2007-10-27T19:00:00.000+04:00", dt.toString());
0854:
0855: DateTime plus6 = dt.plusHours(6);
0856: assertEquals("2007-10-28T01:00:00.000+04:00", plus6.toString());
0857: DateTime plus7 = dt.plusHours(7);
0858: assertEquals("2007-10-28T02:00:00.000+04:00", plus7.toString());
0859: DateTime plus8 = dt.plusHours(8);
0860: assertEquals("2007-10-28T02:00:00.000+03:00", plus8.toString());
0861: DateTime plus9 = dt.plusHours(9);
0862: assertEquals("2007-10-28T03:00:00.000+03:00", plus9.toString());
0863: }
0864:
0865: public void test_DateTime_minusHour_Moscow_Autumn() {
0866: DateTime dt = new DateTime(2007, 10, 28, 9, 0, 0, 0,
0867: ZONE_MOSCOW);
0868: assertEquals("2007-10-28T09:00:00.000+03:00", dt.toString());
0869:
0870: DateTime minus6 = dt.minusHours(6);
0871: assertEquals("2007-10-28T03:00:00.000+03:00", minus6.toString());
0872: DateTime minus7 = dt.minusHours(7);
0873: assertEquals("2007-10-28T02:00:00.000+03:00", minus7.toString());
0874: DateTime minus8 = dt.minusHours(8);
0875: assertEquals("2007-10-28T02:00:00.000+04:00", minus8.toString());
0876: DateTime minus9 = dt.minusHours(9);
0877: assertEquals("2007-10-28T01:00:00.000+04:00", minus9.toString());
0878: }
0879:
0880: //-----------------------------------------------------------------------
0881: //-----------------------------------------------------------------------
0882: //-----------------------------------------------------------------------
0883: /** America/Guatemala cutover from 23:59 to 23:00 on 2006-09-30 */
0884: private static long CUTOVER_GUATEMALA_AUTUMN = 1159678800000L; // 2006-09-30T23:00:00.000-06:00
0885: private static final DateTimeZone ZONE_GUATEMALA = DateTimeZone
0886: .forID("America/Guatemala");
0887:
0888: //-----------------------------------------------------------------------
0889: public void test_GuatemataIsCorrect_Autumn() {
0890: DateTime pre = new DateTime(CUTOVER_GUATEMALA_AUTUMN - 1L,
0891: ZONE_GUATEMALA);
0892: assertEquals("2006-09-30T23:59:59.999-05:00", pre.toString());
0893: DateTime at = new DateTime(CUTOVER_GUATEMALA_AUTUMN,
0894: ZONE_GUATEMALA);
0895: assertEquals("2006-09-30T23:00:00.000-06:00", at.toString());
0896: DateTime post = new DateTime(CUTOVER_GUATEMALA_AUTUMN + 1L,
0897: ZONE_GUATEMALA);
0898: assertEquals("2006-09-30T23:00:00.001-06:00", post.toString());
0899: }
0900:
0901: public void test_getOffsetFromLocal_Guatemata_Autumn() {
0902: doTest_getOffsetFromLocal(2006, 9, 30, 23, 0,
0903: "2006-09-30T23:00:00.000-05:00", ZONE_GUATEMALA);
0904: doTest_getOffsetFromLocal(2006, 9, 30, 23, 30,
0905: "2006-09-30T23:30:00.000-05:00", ZONE_GUATEMALA);
0906:
0907: doTest_getOffsetFromLocal(2006, 9, 30, 23, 0,
0908: "2006-09-30T23:00:00.000-05:00", ZONE_GUATEMALA);
0909: doTest_getOffsetFromLocal(2006, 9, 30, 23, 30,
0910: "2006-09-30T23:30:00.000-05:00", ZONE_GUATEMALA);
0911:
0912: doTest_getOffsetFromLocal(2006, 10, 1, 0, 0,
0913: "2006-10-01T00:00:00.000-06:00", ZONE_GUATEMALA);
0914: doTest_getOffsetFromLocal(2006, 10, 1, 0, 30,
0915: "2006-10-01T00:30:00.000-06:00", ZONE_GUATEMALA);
0916: doTest_getOffsetFromLocal(2006, 10, 1, 1, 0,
0917: "2006-10-01T01:00:00.000-06:00", ZONE_GUATEMALA);
0918: doTest_getOffsetFromLocal(2006, 10, 1, 1, 30,
0919: "2006-10-01T01:30:00.000-06:00", ZONE_GUATEMALA);
0920: doTest_getOffsetFromLocal(2006, 10, 1, 2, 0,
0921: "2006-10-01T02:00:00.000-06:00", ZONE_GUATEMALA);
0922: doTest_getOffsetFromLocal(2006, 10, 1, 2, 30,
0923: "2006-10-01T02:30:00.000-06:00", ZONE_GUATEMALA);
0924: doTest_getOffsetFromLocal(2006, 10, 1, 3, 0,
0925: "2006-10-01T03:00:00.000-06:00", ZONE_GUATEMALA);
0926: doTest_getOffsetFromLocal(2006, 10, 1, 3, 30,
0927: "2006-10-01T03:30:00.000-06:00", ZONE_GUATEMALA);
0928: doTest_getOffsetFromLocal(2006, 10, 1, 4, 0,
0929: "2006-10-01T04:00:00.000-06:00", ZONE_GUATEMALA);
0930: doTest_getOffsetFromLocal(2006, 10, 1, 4, 30,
0931: "2006-10-01T04:30:00.000-06:00", ZONE_GUATEMALA);
0932: doTest_getOffsetFromLocal(2006, 10, 1, 5, 0,
0933: "2006-10-01T05:00:00.000-06:00", ZONE_GUATEMALA);
0934: doTest_getOffsetFromLocal(2006, 10, 1, 5, 30,
0935: "2006-10-01T05:30:00.000-06:00", ZONE_GUATEMALA);
0936: doTest_getOffsetFromLocal(2006, 10, 1, 6, 0,
0937: "2006-10-01T06:00:00.000-06:00", ZONE_GUATEMALA);
0938: doTest_getOffsetFromLocal(2006, 10, 1, 6, 30,
0939: "2006-10-01T06:30:00.000-06:00", ZONE_GUATEMALA);
0940: }
0941:
0942: public void test_DateTime_plusHour_Guatemata_Autumn() {
0943: DateTime dt = new DateTime(2006, 9, 30, 20, 0, 0, 0,
0944: ZONE_GUATEMALA);
0945: assertEquals("2006-09-30T20:00:00.000-05:00", dt.toString());
0946:
0947: DateTime plus1 = dt.plusHours(1);
0948: assertEquals("2006-09-30T21:00:00.000-05:00", plus1.toString());
0949: DateTime plus2 = dt.plusHours(2);
0950: assertEquals("2006-09-30T22:00:00.000-05:00", plus2.toString());
0951: DateTime plus3 = dt.plusHours(3);
0952: assertEquals("2006-09-30T23:00:00.000-05:00", plus3.toString());
0953: DateTime plus4 = dt.plusHours(4);
0954: assertEquals("2006-09-30T23:00:00.000-06:00", plus4.toString());
0955: DateTime plus5 = dt.plusHours(5);
0956: assertEquals("2006-10-01T00:00:00.000-06:00", plus5.toString());
0957: DateTime plus6 = dt.plusHours(6);
0958: assertEquals("2006-10-01T01:00:00.000-06:00", plus6.toString());
0959: DateTime plus7 = dt.plusHours(7);
0960: assertEquals("2006-10-01T02:00:00.000-06:00", plus7.toString());
0961: }
0962:
0963: public void test_DateTime_minusHour_Guatemata_Autumn() {
0964: DateTime dt = new DateTime(2006, 10, 1, 2, 0, 0, 0,
0965: ZONE_GUATEMALA);
0966: assertEquals("2006-10-01T02:00:00.000-06:00", dt.toString());
0967:
0968: DateTime minus1 = dt.minusHours(1);
0969: assertEquals("2006-10-01T01:00:00.000-06:00", minus1.toString());
0970: DateTime minus2 = dt.minusHours(2);
0971: assertEquals("2006-10-01T00:00:00.000-06:00", minus2.toString());
0972: DateTime minus3 = dt.minusHours(3);
0973: assertEquals("2006-09-30T23:00:00.000-06:00", minus3.toString());
0974: DateTime minus4 = dt.minusHours(4);
0975: assertEquals("2006-09-30T23:00:00.000-05:00", minus4.toString());
0976: DateTime minus5 = dt.minusHours(5);
0977: assertEquals("2006-09-30T22:00:00.000-05:00", minus5.toString());
0978: DateTime minus6 = dt.minusHours(6);
0979: assertEquals("2006-09-30T21:00:00.000-05:00", minus6.toString());
0980: DateTime minus7 = dt.minusHours(7);
0981: assertEquals("2006-09-30T20:00:00.000-05:00", minus7.toString());
0982: }
0983:
0984: //-----------------------------------------------------------------------
0985: //-----------------------------------------------------------------------
0986: //-----------------------------------------------------------------------
0987:
0988: // public void test_toDateMidnight_SaoPaolo() {
0989: // // RFE: 1684259
0990: // DateTimeZone zone = DateTimeZone.forID("America/Sao_Paulo");
0991: // LocalDate baseDate = new LocalDate(2006, 11, 5);
0992: // DateMidnight dm = baseDate.toDateMidnight(zone);
0993: // assertEquals("2006-11-05T00:00:00.000-03:00", dm.toString());
0994: // DateTime dt = baseDate.toDateTimeAtMidnight(zone);
0995: // assertEquals("2006-11-05T00:00:00.000-03:00", dt.toString());
0996: // }
0997:
0998: //-----------------------------------------------------------------------
0999: //-----------------------------------------------------------------------
1000: //-----------------------------------------------------------------------
1001: private void doTest_getOffsetFromLocal(int month, int day,
1002: int hour, int min, String expected, DateTimeZone zone) {
1003: doTest_getOffsetFromLocal(2007, month, day, hour, min,
1004: expected, zone);
1005: }
1006:
1007: private void doTest_getOffsetFromLocal(int year, int month,
1008: int day, int hour, int min, String expected,
1009: DateTimeZone zone) {
1010: DateTime dt = new DateTime(year, month, day, hour, min, 0, 0,
1011: DateTimeZone.UTC);
1012: int offset = zone.getOffsetFromLocal(dt.getMillis());
1013: DateTime res = new DateTime(dt.getMillis() - offset, zone);
1014: assertEquals(res.toString(), expected, res.toString());
1015: }
1016:
1017: }
|