Java Code Examples for org.joda.time.DateTime#withChronology()

The following examples show how to use org.joda.time.DateTime#withChronology() . 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: CalendarDate.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get Calendar date from fields. Uses UTZ time zone
 * 
 * @param cal calendar to use, or null for default
 * @param year any integer
 * @param monthOfYear 1-12
 * @param dayOfMonth 1-31
 * @param hourOfDay 0-23
 * @param minuteOfHour 0-59
 * @param secondOfMinute 0-59
 * @return CalendarDate
 */
public static CalendarDate of(Calendar cal, int year, int monthOfYear, int dayOfMonth, int hourOfDay,
    int minuteOfHour, int secondOfMinute) {
  Chronology base = Calendar.getChronology(cal);
  /*
   * if (base == null)
   * base = ISOChronology.getInstanceUTC(); // already in UTC
   * else
   * base = ZonedChronology.getInstance( base, DateTimeZone.UTC); // otherwise wrap it to be in UTC
   */

  DateTime dt = new DateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, base);
  if (!Calendar.isDefaultChronology(cal))
    dt = dt.withChronology(Calendar.getChronology(cal));
  dt = dt.withZone(DateTimeZone.UTC);
  return new CalendarDate(cal, dt);
}
 
Example 2
Source File: CalendarDate.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static CalendarDate withDoy(Calendar cal, int year, int doy, int hourOfDay, int minuteOfHour,
    int secondOfMinute) {
  Chronology base = Calendar.getChronology(cal);
  /*
   * if (base == null)
   * base = ISOChronology.getInstanceUTC(); // already in UTC
   * else
   * base = ZonedChronology.getInstance( base, DateTimeZone.UTC); // otherwise wrap it to be in UTC
   */

  DateTime dt = new DateTime(year, 1, 1, hourOfDay, minuteOfHour, secondOfMinute, base);
  dt = dt.withZone(DateTimeZone.UTC);
  dt = dt.withDayOfYear(doy);
  if (!Calendar.isDefaultChronology(cal))
    dt = dt.withChronology(Calendar.getChronology(cal));

  return new CalendarDate(cal, dt);
}
 
Example 3
Source File: ChronologyBasedCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public DateTimeUnit toIso( DateTimeUnit dateTimeUnit )
{
    if ( dateTimeUnit.isIso8601() )
    {
        return dateTimeUnit;
    }

    DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
    dateTime = dateTime.withChronology( ISOChronology.getInstance( DateTimeZone.forTimeZone( dateTimeUnit.getTimeZone() ) ) );

    return new DateTimeUnit( DateTimeUnit.fromJodaDateTime( dateTime ), true );
}
 
Example 4
Source File: ChronologyBasedCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public DateTimeUnit fromIso( DateTimeUnit dateTimeUnit )
{
    if ( !dateTimeUnit.isIso8601() )
    {
        return dateTimeUnit;
    }

    DateTime dateTime = dateTimeUnit.toJodaDateTime( ISOChronology.getInstance( DateTimeZone.forTimeZone( dateTimeUnit.getTimeZone() ) ) );
    dateTime = dateTime.withChronology( chronology );

    return DateTimeUnit.fromJodaDateTime( dateTime );
}
 
Example 5
Source File: ChronologyBasedCalendar.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int isoWeekday( DateTimeUnit dateTimeUnit )
{
    DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
    dateTime = dateTime.withChronology( ISOChronology.getInstance( DateTimeZone.getDefault() ) );
    return dateTime.getDayOfWeek();
}
 
Example 6
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testPrint_simple() {
    DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
    assertEquals("Wed 2004-06-09T10:20:30Z", f.print(dt));
    
    dt = dt.withZone(PARIS);
    assertEquals("Wed 2004-06-09T12:20:30+02:00", f.print(dt));
    
    dt = dt.withZone(NEWYORK);
    assertEquals("Wed 2004-06-09T06:20:30-04:00", f.print(dt));
    
    dt = dt.withChronology(BUDDHIST_PARIS);
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.print(dt));
}
 
Example 7
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testPrint_chrono() {
    DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
    assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withChronology(ISO_PARIS).print(dt));
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(BUDDHIST_PARIS).print(dt));
    assertEquals("Wed 2004-06-09T10:20:30Z", f.withChronology(null).print(dt));
    
    dt = dt.withChronology(BUDDHIST_PARIS);
    assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withChronology(ISO_PARIS).print(dt));
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(BUDDHIST_PARIS).print(dt));
    assertEquals("Wed 2004-06-09T10:20:30Z", f.withChronology(ISO_UTC).print(dt));
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(null).print(dt));
}
 
Example 8
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testPrint_chrono_and_zone() {
    DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
    assertEquals("Wed 2004-06-09T10:20:30Z",
            f.withChronology(null).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(null).withZone(NEWYORK).print(dt));
    
    dt = dt.withChronology(ISO_PARIS);
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(null).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(null).withZone(NEWYORK).print(dt));
    
    dt = dt.withChronology(BUDDHIST_PARIS);
    assertEquals("Wed 2547-06-09T12:20:30+02:00",
            f.withChronology(null).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
    assertEquals("Wed 2547-06-09T06:20:30-04:00",
            f.withChronology(null).withZone(NEWYORK).print(dt));
}
 
Example 9
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testPrint_simple() {
    DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
    assertEquals("Wed 2004-06-09T10:20:30Z", f.print(dt));
    
    dt = dt.withZone(PARIS);
    assertEquals("Wed 2004-06-09T12:20:30+02:00", f.print(dt));
    
    dt = dt.withZone(NEWYORK);
    assertEquals("Wed 2004-06-09T06:20:30-04:00", f.print(dt));
    
    dt = dt.withChronology(BUDDHIST_PARIS);
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.print(dt));
}
 
Example 10
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testPrint_chrono() {
    DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
    assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withChronology(ISO_PARIS).print(dt));
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(BUDDHIST_PARIS).print(dt));
    assertEquals("Wed 2004-06-09T10:20:30Z", f.withChronology(null).print(dt));
    
    dt = dt.withChronology(BUDDHIST_PARIS);
    assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withChronology(ISO_PARIS).print(dt));
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(BUDDHIST_PARIS).print(dt));
    assertEquals("Wed 2004-06-09T10:20:30Z", f.withChronology(ISO_UTC).print(dt));
    assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(null).print(dt));
}
 
Example 11
Source File: TestDateTimeFormatter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testPrint_chrono_and_zone() {
    DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
    assertEquals("Wed 2004-06-09T10:20:30Z",
            f.withChronology(null).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(null).withZone(NEWYORK).print(dt));
    
    dt = dt.withChronology(ISO_PARIS);
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(null).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(null).withZone(NEWYORK).print(dt));
    
    dt = dt.withChronology(BUDDHIST_PARIS);
    assertEquals("Wed 2547-06-09T12:20:30+02:00",
            f.withChronology(null).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(null).print(dt));
    assertEquals("Wed 2004-06-09T12:20:30+02:00",
            f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
    assertEquals("Wed 2004-06-09T06:20:30-04:00",
            f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
    assertEquals("Wed 2547-06-09T06:20:30-04:00",
            f.withChronology(null).withZone(NEWYORK).print(dt));
}
 
Example 12
Source File: TestIslamicChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testSampleDate1() {
    DateTime dt = new DateTime(1945, 11, 12, 0, 0, 0, 0, ISO_UTC);
    dt = dt.withChronology(ISLAMIC_UTC);
    assertEquals(IslamicChronology.AH, dt.getEra());
    assertEquals(14, dt.getCenturyOfEra());  // TODO confirm
    assertEquals(64, dt.getYearOfCentury());
    assertEquals(1364, dt.getYearOfEra());
    
    assertEquals(1364, dt.getYear());
    Property fld = dt.year();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(new DateTime(1365, 12, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(12, dt.getMonthOfYear());
    fld = dt.monthOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(12, fld.getMaximumValue());
    assertEquals(12, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1365, 1, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    assertEquals(new DateTime(1364, 1, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addWrapFieldToCopy(1));
    
    assertEquals(6, dt.getDayOfMonth());
    fld = dt.dayOfMonth();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(29, fld.getMaximumValue());
    assertEquals(30, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(DateTimeConstants.MONDAY, dt.getDayOfWeek());
    fld = dt.dayOfWeek();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(7, fld.getMaximumValue());
    assertEquals(7, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(6 * 30 + 5 * 29 + 6, dt.getDayOfYear());
    fld = dt.dayOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(354, fld.getMaximumValue());
    assertEquals(355, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(0, dt.getHourOfDay());
    assertEquals(0, dt.getMinuteOfHour());
    assertEquals(0, dt.getSecondOfMinute());
    assertEquals(0, dt.getMillisOfSecond());
}
 
Example 13
Source File: TestIslamicChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testSampleDate2() {
    DateTime dt = new DateTime(2005, 11, 26, 0, 0, 0, 0, ISO_UTC);
    dt = dt.withChronology(ISLAMIC_UTC);
    assertEquals(IslamicChronology.AH, dt.getEra());
    assertEquals(15, dt.getCenturyOfEra());  // TODO confirm
    assertEquals(26, dt.getYearOfCentury());
    assertEquals(1426, dt.getYearOfEra());
    
    assertEquals(1426, dt.getYear());
    Property fld = dt.year();
    assertEquals(true, fld.isLeap());
    assertEquals(1, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    
    assertEquals(10, dt.getMonthOfYear());
    fld = dt.monthOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(12, fld.getMaximumValue());
    assertEquals(12, fld.getMaximumValueOverall());
    
    assertEquals(24, dt.getDayOfMonth());
    fld = dt.dayOfMonth();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(29, fld.getMaximumValue());
    assertEquals(30, fld.getMaximumValueOverall());
    
    assertEquals(DateTimeConstants.SATURDAY, dt.getDayOfWeek());
    fld = dt.dayOfWeek();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(7, fld.getMaximumValue());
    assertEquals(7, fld.getMaximumValueOverall());
    
    assertEquals(5 * 30 + 4 * 29 + 24, dt.getDayOfYear());
    fld = dt.dayOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(355, fld.getMaximumValue());
    assertEquals(355, fld.getMaximumValueOverall());
    
    assertEquals(0, dt.getHourOfDay());
    assertEquals(0, dt.getMinuteOfHour());
    assertEquals(0, dt.getSecondOfMinute());
    assertEquals(0, dt.getMillisOfSecond());
}
 
Example 14
Source File: TestIslamicChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testSampleDate1() {
    DateTime dt = new DateTime(1945, 11, 12, 0, 0, 0, 0, ISO_UTC);
    dt = dt.withChronology(ISLAMIC_UTC);
    assertEquals(IslamicChronology.AH, dt.getEra());
    assertEquals(14, dt.getCenturyOfEra());  // TODO confirm
    assertEquals(64, dt.getYearOfCentury());
    assertEquals(1364, dt.getYearOfEra());
    
    assertEquals(1364, dt.getYear());
    Property fld = dt.year();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(new DateTime(1365, 12, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(12, dt.getMonthOfYear());
    fld = dt.monthOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(12, fld.getMaximumValue());
    assertEquals(12, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1365, 1, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    assertEquals(new DateTime(1364, 1, 6, 0, 0, 0, 0, ISLAMIC_UTC), fld.addWrapFieldToCopy(1));
    
    assertEquals(6, dt.getDayOfMonth());
    fld = dt.dayOfMonth();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(29, fld.getMaximumValue());
    assertEquals(30, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(DateTimeConstants.MONDAY, dt.getDayOfWeek());
    fld = dt.dayOfWeek();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(7, fld.getMaximumValue());
    assertEquals(7, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(6 * 30 + 5 * 29 + 6, dt.getDayOfYear());
    fld = dt.dayOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(354, fld.getMaximumValue());
    assertEquals(355, fld.getMaximumValueOverall());
    assertEquals(new DateTime(1364, 12, 7, 0, 0, 0, 0, ISLAMIC_UTC), fld.addToCopy(1));
    
    assertEquals(0, dt.getHourOfDay());
    assertEquals(0, dt.getMinuteOfHour());
    assertEquals(0, dt.getSecondOfMinute());
    assertEquals(0, dt.getMillisOfSecond());
}
 
Example 15
Source File: TestIslamicChronology.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testSampleDate2() {
    DateTime dt = new DateTime(2005, 11, 26, 0, 0, 0, 0, ISO_UTC);
    dt = dt.withChronology(ISLAMIC_UTC);
    assertEquals(IslamicChronology.AH, dt.getEra());
    assertEquals(15, dt.getCenturyOfEra());  // TODO confirm
    assertEquals(26, dt.getYearOfCentury());
    assertEquals(1426, dt.getYearOfEra());
    
    assertEquals(1426, dt.getYear());
    Property fld = dt.year();
    assertEquals(true, fld.isLeap());
    assertEquals(1, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    
    assertEquals(10, dt.getMonthOfYear());
    fld = dt.monthOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(DurationFieldType.days(), fld.getLeapDurationField().getType());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(12, fld.getMaximumValue());
    assertEquals(12, fld.getMaximumValueOverall());
    
    assertEquals(24, dt.getDayOfMonth());
    fld = dt.dayOfMonth();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(29, fld.getMaximumValue());
    assertEquals(30, fld.getMaximumValueOverall());
    
    assertEquals(DateTimeConstants.SATURDAY, dt.getDayOfWeek());
    fld = dt.dayOfWeek();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(7, fld.getMaximumValue());
    assertEquals(7, fld.getMaximumValueOverall());
    
    assertEquals(5 * 30 + 4 * 29 + 24, dt.getDayOfYear());
    fld = dt.dayOfYear();
    assertEquals(false, fld.isLeap());
    assertEquals(0, fld.getLeapAmount());
    assertEquals(null, fld.getLeapDurationField());
    assertEquals(1, fld.getMinimumValue());
    assertEquals(1, fld.getMinimumValueOverall());
    assertEquals(355, fld.getMaximumValue());
    assertEquals(355, fld.getMaximumValueOverall());
    
    assertEquals(0, dt.getHourOfDay());
    assertEquals(0, dt.getMinuteOfHour());
    assertEquals(0, dt.getSecondOfMinute());
    assertEquals(0, dt.getMillisOfSecond());
}
 
Example 16
Source File: Literals.java    From ldp4j with Apache License 2.0 4 votes vote down vote up
private static DateTime normalizeChronology(DateTime dateTime) {
	return dateTime.withChronology(ISOChronology.getInstance());
}