Java Code Examples for org.joda.time.chrono.GregorianChronology#getInstance()

The following examples show how to use org.joda.time.chrono.GregorianChronology#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDateTimeZoneCutover.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testBug2182444_ausNSW() {
    Chronology chronAusNSW = GregorianChronology.getInstance(DateTimeZone.forID("Australia/NSW"));
    Chronology chronUTC = GregorianChronology.getInstance(DateTimeZone.UTC);
    DateTime australiaNSWStandardInUTC = new DateTime(2008, 4, 5, 16, 0, 0, 0, chronUTC);
    DateTime australiaNSWDaylightInUTC = new DateTime(2008, 4, 5, 15, 0, 0, 0, chronUTC);
    assertTrue("Should be standard time", chronAusNSW.getZone().isStandardOffset(australiaNSWStandardInUTC.getMillis()));
    assertFalse("Should be daylight time", chronAusNSW.getZone().isStandardOffset(australiaNSWDaylightInUTC.getMillis()));
    
    DateTime australiaNSWStandardInAustraliaNSW = australiaNSWStandardInUTC.toDateTime(chronAusNSW);
    DateTime australiaNSWDaylightInAusraliaNSW = australiaNSWDaylightInUTC.toDateTime(chronAusNSW);
    assertEquals(2, australiaNSWStandardInAustraliaNSW.getHourOfDay());
    assertEquals(australiaNSWStandardInAustraliaNSW.getHourOfDay(), australiaNSWDaylightInAusraliaNSW.getHourOfDay());
    assertTrue(australiaNSWStandardInAustraliaNSW.getMillis() != australiaNSWDaylightInAusraliaNSW.getMillis());
    assertEquals(australiaNSWStandardInAustraliaNSW, australiaNSWStandardInAustraliaNSW.withHourOfDay(2));
    assertEquals(australiaNSWStandardInAustraliaNSW.getMillis() + 3, australiaNSWStandardInAustraliaNSW.withMillisOfSecond(3).getMillis());
    assertEquals(australiaNSWDaylightInAusraliaNSW, australiaNSWDaylightInAusraliaNSW.withHourOfDay(2));
    assertEquals(australiaNSWDaylightInAusraliaNSW.getMillis() + 3, australiaNSWDaylightInAusraliaNSW.withMillisOfSecond(3).getMillis());
}
 
Example 2
Source File: TestInstant_Basics.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testIsBefore_RI() {
    Instant test1 = new Instant(TEST_TIME1);
    Instant test1a = new Instant(TEST_TIME1);
    assertEquals(false, test1.isBefore(test1a));
    assertEquals(false, test1a.isBefore(test1));
    assertEquals(false, test1.isBefore(test1));
    assertEquals(false, test1a.isBefore(test1a));
    
    Instant test2 = new Instant(TEST_TIME2);
    assertEquals(true, test1.isBefore(test2));
    assertEquals(false, test2.isBefore(test1));
    
    DateTime test3 = new DateTime(TEST_TIME2, GregorianChronology.getInstance(PARIS));
    assertEquals(true, test1.isBefore(test3));
    assertEquals(false, test3.isBefore(test1));
    assertEquals(false, test3.isBefore(test2));
    
    assertEquals(false, test2.isBefore(new MockInstant()));
    assertEquals(false, test1.isBefore(new MockInstant()));
    
    assertEquals(false, new Instant(TEST_TIME_NOW + 1).isBefore(null));
    assertEquals(false, new Instant(TEST_TIME_NOW).isBefore(null));
    assertEquals(true, new Instant(TEST_TIME_NOW - 1).isBefore(null));
}
 
Example 3
Source File: TestDateTimeZoneCutover.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testBug2182444_usCentral() {
    Chronology chronUSCentral = GregorianChronology.getInstance(DateTimeZone.forID("US/Central"));
    Chronology chronUTC = GregorianChronology.getInstance(DateTimeZone.UTC);
    DateTime usCentralStandardInUTC = new DateTime(2008, 11, 2, 7, 0, 0, 0, chronUTC);
    DateTime usCentralDaylightInUTC = new DateTime(2008, 11, 2, 6, 0, 0, 0, chronUTC);
    assertTrue("Should be standard time", chronUSCentral.getZone().isStandardOffset(usCentralStandardInUTC.getMillis()));
    assertFalse("Should be daylight time", chronUSCentral.getZone().isStandardOffset(usCentralDaylightInUTC.getMillis()));
    
    DateTime usCentralStandardInUSCentral = usCentralStandardInUTC.toDateTime(chronUSCentral);
    DateTime usCentralDaylightInUSCentral = usCentralDaylightInUTC.toDateTime(chronUSCentral);
    assertEquals(1, usCentralStandardInUSCentral.getHourOfDay());
    assertEquals(usCentralStandardInUSCentral.getHourOfDay(), usCentralDaylightInUSCentral.getHourOfDay());
    assertTrue(usCentralStandardInUSCentral.getMillis() != usCentralDaylightInUSCentral.getMillis());
    assertEquals(usCentralStandardInUSCentral, usCentralStandardInUSCentral.withHourOfDay(1));
    assertEquals(usCentralStandardInUSCentral.getMillis() + 3, usCentralStandardInUSCentral.withMillisOfSecond(3).getMillis());
    assertEquals(usCentralDaylightInUSCentral, usCentralDaylightInUSCentral.withHourOfDay(1));
    assertEquals(usCentralDaylightInUSCentral.getMillis() + 3, usCentralDaylightInUSCentral.withMillisOfSecond(3).getMillis());
}
 
Example 4
Source File: TestDateTimeZoneCutover.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testBug2182444_ausNSW() {
    Chronology chronAusNSW = GregorianChronology.getInstance(DateTimeZone.forID("Australia/NSW"));
    Chronology chronUTC = GregorianChronology.getInstance(DateTimeZone.UTC);
    DateTime australiaNSWStandardInUTC = new DateTime(2008, 4, 5, 16, 0, 0, 0, chronUTC);
    DateTime australiaNSWDaylightInUTC = new DateTime(2008, 4, 5, 15, 0, 0, 0, chronUTC);
    assertTrue("Should be standard time", chronAusNSW.getZone().isStandardOffset(australiaNSWStandardInUTC.getMillis()));
    assertFalse("Should be daylight time", chronAusNSW.getZone().isStandardOffset(australiaNSWDaylightInUTC.getMillis()));
    
    DateTime australiaNSWStandardInAustraliaNSW = australiaNSWStandardInUTC.toDateTime(chronAusNSW);
    DateTime australiaNSWDaylightInAusraliaNSW = australiaNSWDaylightInUTC.toDateTime(chronAusNSW);
    assertEquals(2, australiaNSWStandardInAustraliaNSW.getHourOfDay());
    assertEquals(australiaNSWStandardInAustraliaNSW.getHourOfDay(), australiaNSWDaylightInAusraliaNSW.getHourOfDay());
    assertTrue(australiaNSWStandardInAustraliaNSW.getMillis() != australiaNSWDaylightInAusraliaNSW.getMillis());
    assertEquals(australiaNSWStandardInAustraliaNSW, australiaNSWStandardInAustraliaNSW.withHourOfDay(2));
    assertEquals(australiaNSWStandardInAustraliaNSW.getMillis() + 3, australiaNSWStandardInAustraliaNSW.withMillisOfSecond(3).getMillis());
    assertEquals(australiaNSWDaylightInAusraliaNSW, australiaNSWDaylightInAusraliaNSW.withHourOfDay(2));
    assertEquals(australiaNSWDaylightInAusraliaNSW.getMillis() + 3, australiaNSWDaylightInAusraliaNSW.withMillisOfSecond(3).getMillis());
}
 
Example 5
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test constructor (Object, Chronology)
 */
public void testConstructor_Object_Chronology() throws Throwable {
    Date date = new Date(TEST_TIME1);
    DateTime test = new DateTime(date, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME1, test.getMillis());
}
 
Example 6
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test constructor (Object, Chronology)
 */
public void testConstructor_Object_Chronology() throws Throwable {
    Date date = new Date(TEST_TIME1);
    MutableDateTime test = new MutableDateTime(date, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME1, test.getMillis());
}
 
Example 7
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test constructor (Object, DateTimeZone)
 */
public void testConstructor_badconverterObject_DateTimeZone() throws Throwable {
    try {
        ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
        MutableDateTime test = new MutableDateTime(new Integer(0), GregorianChronology.getInstance());
        assertEquals(ISOChronology.getInstance(), test.getChronology());
        assertEquals(0L, test.getMillis());
    } finally {
        ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
    }
}
 
Example 8
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test constructor (Object, Chronology)
 */
public void testConstructor_Object_Chronology() throws Throwable {
    Date date = new Date(TEST_TIME1);
    DateTime test = new DateTime(date, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME1, test.getMillis());
}
 
Example 9
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test constructor (Object, Chronology)
 */
public void testConstructor_invalidObject_Chronology() throws Throwable {
    try {
        new DateMidnight(new Object(), GregorianChronology.getInstance());
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
Example 10
Source File: TestInstant_Basics.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testCompareTo() {
        Instant test1 = new Instant(TEST_TIME1);
        Instant test1a = new Instant(TEST_TIME1);
        assertEquals(0, test1.compareTo(test1a));
        assertEquals(0, test1a.compareTo(test1));
        assertEquals(0, test1.compareTo(test1));
        assertEquals(0, test1a.compareTo(test1a));
        
        Instant test2 = new Instant(TEST_TIME2);
        assertEquals(-1, test1.compareTo(test2));
        assertEquals(+1, test2.compareTo(test1));
        
        DateTime test3 = new DateTime(TEST_TIME2, GregorianChronology.getInstance(PARIS));
        assertEquals(-1, test1.compareTo(test3));
        assertEquals(+1, test3.compareTo(test1));
        assertEquals(0, test3.compareTo(test2));
        
        assertEquals(+1, test2.compareTo(new MockInstant()));
        assertEquals(0, test1.compareTo(new MockInstant()));
        
        try {
            test1.compareTo(null);
            fail();
        } catch (NullPointerException ex) {}
//        try {
//            test1.compareTo(new Date());
//            fail();
//        } catch (ClassCastException ex) {}
    }
 
Example 11
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test constructor (Object, Chronology)
 */
public void testConstructor_badconverterObject_Chronology() throws Throwable {
    try {
        ConverterManager.getInstance().addInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
        DateMidnight test = new DateMidnight(new Integer(0), GregorianChronology.getInstance());
        assertEquals(ISOChronology.getInstance(), test.getChronology());
        assertEquals(0L - DateTimeConstants.MILLIS_PER_HOUR, test.getMillis());
    } finally {
        ConverterManager.getInstance().removeInstantConverter(MockZeroNullIntegerConverter.INSTANCE);
    }
}
 
Example 12
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (Object=null, Chronology)
 */
public void testConstructor_nullObject_Chronology() throws Throwable {
    DateMidnight test = new DateMidnight((Object) null, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME_NOW_LONDON, test.getMillis());
}
 
Example 13
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (long, Chronology)
 */
public void testConstructor_long1_Chronology() throws Throwable {
    DateTime test = new DateTime(TEST_TIME1, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME1, test.getMillis());
}
 
Example 14
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (long, Chronology)
 */
public void testConstructor_long2_Chronology() throws Throwable {
    DateMidnight test = new DateMidnight(TEST_TIME2_UTC, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME2_LONDON, test.getMillis());
}
 
Example 15
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (long, Chronology)
 */
public void testConstructor_long2_Chronology() throws Throwable {
    DateMidnight test = new DateMidnight(TEST_TIME2_UTC, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME2_LONDON, test.getMillis());
}
 
Example 16
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (Object=null, Chronology)
 */
public void testConstructor_nullObject_Chronology() throws Throwable {
    DateTime test = new DateTime((Object) null, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME_NOW, test.getMillis());
}
 
Example 17
Source File: TestDateMidnight_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (long, Chronology)
 */
public void testConstructor_long1_Chronology() throws Throwable {
    DateMidnight test = new DateMidnight(TEST_TIME1_UTC, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME1_LONDON, test.getMillis());
}
 
Example 18
Source File: TestDateTime_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (Object=null, Chronology)
 */
public void testConstructor_nullObject_Chronology() throws Throwable {
    DateTime test = new DateTime((Object) null, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME_NOW, test.getMillis());
}
 
Example 19
Source File: TestMutableDateTime_Sets.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testSetZoneRetainFields_DateTimeZone3() {
    MutableDateTime test = new MutableDateTime(TEST_TIME1, GregorianChronology.getInstance(PARIS));
    test.setZoneRetainFields(null);
    assertEquals(TEST_TIME1 + DateTimeConstants.MILLIS_PER_HOUR, test.getMillis());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
}
 
Example 20
Source File: TestMutableDateTime_Constructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test constructor (Object=null, Chronology)
 */
public void testConstructor_nullObject_Chronology() throws Throwable {
    MutableDateTime test = new MutableDateTime((Object) null, GregorianChronology.getInstance());
    assertEquals(GregorianChronology.getInstance(), test.getChronology());
    assertEquals(TEST_TIME_NOW, test.getMillis());
}