1   /*
2    *  Copyright 2001-2006 Stephen Colebourne
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.joda.time;
17  
18  import junit.framework.Assert;
19  import junit.framework.TestCase;
20  
21  import org.joda.time.chrono.GregorianChronology;
22  
23  /***
24   * Test.
25   */
26  public class TempTest3 extends TestCase {
27      public void test1 () {
28  
29          Chronology chronUTC = GregorianChronology.getInstance(DateTimeZone.UTC);
30          
31          DateTime usCentralStandardInUTC = new DateTime(2008, 11, 2, 7, 0, 0, 0, chronUTC);
32          DateTime usCentralDaylightInUTC = new DateTime(2008, 11, 2, 6, 0, 0, 0, chronUTC);
33          Chronology chronUSCentral = GregorianChronology.getInstance(DateTimeZone.forID("US/Central"));
34          Assert.assertTrue("Should be standard time", chronUSCentral.getZone().isStandardOffset(usCentralStandardInUTC.getMillis()));
35          Assert.assertFalse("Should be daylight time", chronUSCentral.getZone().isStandardOffset(usCentralDaylightInUTC.getMillis()));
36          
37          DateTime usCentralStandardInUSCentral = usCentralStandardInUTC.toDateTime(chronUSCentral);
38          DateTime usCentralDaylightInUSCentral = usCentralDaylightInUTC.toDateTime(chronUSCentral);
39          assertEquals(1, usCentralStandardInUSCentral.getHourOfDay());
40          assertEquals(usCentralStandardInUSCentral.getHourOfDay(), usCentralDaylightInUSCentral.getHourOfDay());
41          Assert.assertTrue(usCentralStandardInUSCentral.getMillis() != usCentralDaylightInUSCentral.getMillis());
42          
43          
44          DateTime australiaNSWStandardInUTC = new DateTime(2008, 4, 5, 16, 0, 0, 0, chronUTC);
45          DateTime australiaNSWDaylightInUTC = new DateTime(2008, 4, 5, 15, 0, 0, 0, chronUTC);
46          Chronology chronAusNSW = GregorianChronology.getInstance(DateTimeZone.forID("Australia/NSW"));
47          Assert.assertTrue("Should be standard time", chronAusNSW.getZone().isStandardOffset(australiaNSWStandardInUTC.getMillis()));
48          Assert.assertFalse("Should be daylight time", chronAusNSW.getZone().isStandardOffset(australiaNSWDaylightInUTC.getMillis()));
49          
50          DateTime australiaNSWStandardInAustraliaNSW = australiaNSWStandardInUTC.toDateTime(chronAusNSW);
51          DateTime australiaNSWDaylightInAusraliaNSW = australiaNSWDaylightInUTC.toDateTime(chronAusNSW);
52          assertEquals(2, australiaNSWStandardInAustraliaNSW.getHourOfDay());
53          assertEquals(australiaNSWStandardInAustraliaNSW.getHourOfDay(), australiaNSWDaylightInAusraliaNSW.getHourOfDay());
54          Assert.assertTrue(australiaNSWStandardInAustraliaNSW.getMillis() != australiaNSWDaylightInAusraliaNSW.getMillis());
55          
56          // Verify that setting the hour of day on the DST boundary results in a
57          // daylight time for both time zones
58          assertEquals(usCentralDaylightInUSCentral, new DateTime(2008, 11, 2, 1, 0, 0, 0, chronUSCentral));
59          assertEquals(australiaNSWDaylightInAusraliaNSW, new DateTime(2008, 4, 6, 2, 0, 0, 0, chronAusNSW));
60          
61          
62          assertEquals(usCentralDaylightInUSCentral, usCentralStandardInUSCentral.withHourOfDay(1));
63          assertEquals(australiaNSWDaylightInAusraliaNSW, australiaNSWStandardInAustraliaNSW.withHourOfDay(2));
64      }
65  }