Java Code Examples for org.joda.time.DateTimeZone#toTimeZone()

The following examples show how to use org.joda.time.DateTimeZone#toTimeZone() . 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: SettableDataSetterFactoryTest.java    From SimpleFlatMapper with MIT License 6 votes vote down vote up
private <T extends ReadablePartial> void testJodaDate(T joda, Date date) throws Exception {
    Setter<SettableByIndexData, T> setter = factory.getSetter(newPM(joda.getClass(), DataType.timestamp()));
    setter.set(statement, joda);
    verify(statement).setTimestamp(0, date);
    setter.set(statement, null);
    verify(statement).setToNull(0);

    DateTimeZone tz2 = getNonDefaultDateTimeZone(date);

    Setter<SettableByIndexData, T> setterTZ =
            factory.getSetter(newPM(joda.getClass(), DataType.timestamp(), new JodaDateTimeZoneProperty(tz2)));
    setterTZ.set(statement, joda);
    verify(statement).setTimestamp(1, new Date(date.getTime() + TimeUnit.HOURS.toMillis(2)));

    TimeZone jtz = tz2.toTimeZone();

    Setter<SettableByIndexData, T> setterJTZ =
            factory.getSetter(newPM(joda.getClass(), DataType.timestamp(), new TimeZoneProperty(jtz)));
    setterJTZ.set(statement, joda);
    verify(statement).setTimestamp(1, new Date(date.getTime() + TimeUnit.HOURS.toMillis(2)));

}
 
Example 2
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeZoneConversion() {
    TimeZone jdkTimeZone = TimeZone.getTimeZone("GMT-10");
    assertEquals("GMT-10:00", jdkTimeZone.getID());
    
    DateTimeZone jodaTimeZone = DateTimeZone.forTimeZone(jdkTimeZone);
    assertEquals("-10:00", jodaTimeZone.getID());
    assertEquals(jdkTimeZone.getRawOffset(), jodaTimeZone.getOffset(0L));
    
    TimeZone convertedTimeZone = jodaTimeZone.toTimeZone();
    assertEquals("GMT-10:00", jdkTimeZone.getID());
    
    assertEquals(jdkTimeZone.getID(), convertedTimeZone.getID());
    assertEquals(jdkTimeZone.getRawOffset(), convertedTimeZone.getRawOffset());
}
 
Example 3
Source File: CalendarDate.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public GregorianCalendar toGregorianCalendar() {
  DateTimeZone zone = dateTime.getZone();
  GregorianCalendar cal = new GregorianCalendar(zone.toTimeZone());
  cal.setTime(toDate());
  return cal;
}
 
Example 4
Source File: TestDateTimeZone.java    From joda-time-android with Apache License 2.0 4 votes vote down vote up
@Test
public void testToTimeZone() {
    DateTimeZone zone = DateTimeZone.forID("Europe/Paris");
    TimeZone tz = zone.toTimeZone();
    assertEquals("Europe/Paris", tz.getID());
}
 
Example 5
Source File: AbstractDateTime.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Get the date time as a <code>java.util.GregorianCalendar</code>,
 * assigning exactly the same millisecond instant.
 * <p>
 * The JDK and Joda-Time both have time zone implementations and these
 * differ in accuracy. Joda-Time's implementation is generally more up to
 * date and thus more accurate - for example JDK1.3 has no historical data.
 * The effect of this is that the field values of the <code>Calendar</code>
 * may differ from those of this object, even though the milliseond value
 * is the same. Most of the time this just means that the JDK field values
 * are wrong, as our time zone information is more up to date.
 *
 * @return a GregorianCalendar initialised with this datetime
 */
public GregorianCalendar toGregorianCalendar() {
    DateTimeZone zone = getZone();
    GregorianCalendar cal = new GregorianCalendar(zone.toTimeZone());
    cal.setTime(toDate());
    return cal;
}
 
Example 6
Source File: AbstractDateTime.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Get the date time as a <code>java.util.GregorianCalendar</code>,
 * assigning exactly the same millisecond instant.
 * <p>
 * The JDK and Joda-Time both have time zone implementations and these
 * differ in accuracy. Joda-Time's implementation is generally more up to
 * date and thus more accurate - for example JDK1.3 has no historical data.
 * The effect of this is that the field values of the <code>Calendar</code>
 * may differ from those of this object, even though the milliseond value
 * is the same. Most of the time this just means that the JDK field values
 * are wrong, as our time zone information is more up to date.
 *
 * @return a GregorianCalendar initialised with this datetime
 */
public GregorianCalendar toGregorianCalendar() {
    DateTimeZone zone = getZone();
    GregorianCalendar cal = new GregorianCalendar(zone.toTimeZone());
    cal.setTime(toDate());
    return cal;
}