Java Code Examples for org.joda.time.DateTimeField#getMaximumValue()
The following examples show how to use
org.joda.time.DateTimeField#getMaximumValue() .
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: DividedDateTimeField.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Constructor. * * @param field the field to wrap, like "year()". * @param rangeField the range field, null to derive * @param type the field type this field will actually use * @param divisor divisor, such as 100 years in a century * @throws IllegalArgumentException if divisor is less than two */ public DividedDateTimeField(DateTimeField field, DurationField rangeField, DateTimeFieldType type, int divisor) { super(field, type); if (divisor < 2) { throw new IllegalArgumentException("The divisor must be at least 2"); } DurationField unitField = field.getDurationField(); if (unitField == null) { iDurationField = null; } else { iDurationField = new ScaledDurationField( unitField, type.getDurationType(), divisor); } iRangeDurationField = rangeField; iDivisor = divisor; int i = field.getMinimumValue(); int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1); int j = field.getMaximumValue(); int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1); iMin = min; iMax = max; }
Example 2
Source File: OffsetDateTimeField.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Constructor. * * @param field the field to wrap, like "year()". * @param type the field type this field actually uses * @param offset offset to add to field values * @param minValue minimum allowed value * @param maxValue maximum allowed value * @throws IllegalArgumentException if offset is zero */ public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset, int minValue, int maxValue) { super(field, type); if (offset == 0) { throw new IllegalArgumentException("The offset cannot be zero"); } iOffset = offset; if (minValue < (field.getMinimumValue() + offset)) { iMin = field.getMinimumValue() + offset; } else { iMin = minValue; } if (maxValue > (field.getMaximumValue() + offset)) { iMax = field.getMaximumValue() + offset; } else { iMax = maxValue; } }
Example 3
Source File: DividedDateTimeField.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Construct a DividedDateTimeField that compliments the given * RemainderDateTimeField. * * @param remainderField complimentary remainder field, like "yearOfCentury()". * @param type the field type this field will actually use */ public DividedDateTimeField(RemainderDateTimeField remainderField, DateTimeFieldType type) { super(remainderField.getWrappedField(), type); int divisor = iDivisor = remainderField.iDivisor; iDurationField = remainderField.iRangeField; DateTimeField field = getWrappedField(); int i = field.getMinimumValue(); int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1); int j = field.getMaximumValue(); int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1); iMin = min; iMax = max; }
Example 4
Source File: Time_18_GJChronology_s.java From coming with MIT License | 5 votes |
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
Example 5
Source File: Time_6_GJChronology_s.java From coming with MIT License | 5 votes |
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
Example 6
Source File: Time_6_GJChronology_t.java From coming with MIT License | 5 votes |
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
Example 7
Source File: DividedDateTimeField.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Construct a DividedDateTimeField that compliments the given * RemainderDateTimeField. * * @param remainderField complimentary remainder field, like "yearOfCentury()". * @param rangeField the range field, null to derive * @param type the field type this field will actually use */ public DividedDateTimeField(RemainderDateTimeField remainderField, DurationField rangeField, DateTimeFieldType type) { super(remainderField.getWrappedField(), type); int divisor = iDivisor = remainderField.iDivisor; iDurationField = remainderField.iRangeField; iRangeDurationField = rangeField; DateTimeField field = getWrappedField(); int i = field.getMinimumValue(); int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1); int j = field.getMaximumValue(); int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1); iMin = min; iMax = max; }
Example 8
Source File: Time_18_GJChronology_t.java From coming with MIT License | 5 votes |
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
Example 9
Source File: GJChronology.java From astor with GNU General Public License v2.0 | 5 votes |
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
Example 10
Source File: GJChronology.java From astor with GNU General Public License v2.0 | 5 votes |
public int getMaximumValue(ReadablePartial partial, int[] values) { Chronology chrono = GJChronology.getInstanceUTC(); long instant = 0L; for (int i = 0, isize = partial.size(); i < isize; i++) { DateTimeField field = partial.getFieldType(i).getField(chrono); if (values[i] <= field.getMaximumValue(instant)) { instant = field.set(instant, values[i]); } } return getMaximumValue(instant); }
Example 11
Source File: DividedDateTimeField.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Constructor. * * @param field the field to wrap, like "year()". * @param type the field type this field will actually use * @param divisor divisor, such as 100 years in a century * @throws IllegalArgumentException if divisor is less than two */ public DividedDateTimeField(DateTimeField field, DateTimeFieldType type, int divisor) { super(field, type); if (divisor < 2) { throw new IllegalArgumentException("The divisor must be at least 2"); } DurationField unitField = field.getDurationField(); if (unitField == null) { iDurationField = null; } else { iDurationField = new ScaledDurationField( unitField, type.getDurationType(), divisor); } iDivisor = divisor; int i = field.getMinimumValue(); int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1); int j = field.getMaximumValue(); int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1); iMin = min; iMax = max; }
Example 12
Source File: TestIslamicChronology.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek. */ public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestIslamicChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ISLAMIC_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = ISLAMIC_UTC.dayOfWeek(); DateTimeField dayOfYear = ISLAMIC_UTC.dayOfYear(); DateTimeField dayOfMonth = ISLAMIC_UTC.dayOfMonth(); DateTimeField monthOfYear = ISLAMIC_UTC.monthOfYear(); DateTimeField year = ISLAMIC_UTC.year(); DateTimeField yearOfEra = ISLAMIC_UTC.yearOfEra(); DateTimeField era = ISLAMIC_UTC.era(); int expectedDOW = new DateTime(622, 7, 16, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek(); int expectedDOY = 1; int expectedDay = 1; int expectedMonth = 1; int expectedYear = 1; while (millis < end) { int dowValue = dayOfWeek.get(millis); int doyValue = dayOfYear.get(millis); int dayValue = dayOfMonth.get(millis); int monthValue = monthOfYear.get(millis); int yearValue = year.get(millis); int yearOfEraValue = yearOfEra.get(millis); int dayOfYearLen = dayOfYear.getMaximumValue(millis); int monthLen = dayOfMonth.getMaximumValue(millis); if (monthValue < 1 || monthValue > 12) { fail("Bad month: " + millis); } // test era assertEquals(1, era.get(millis)); assertEquals("AH", era.getAsText(millis)); assertEquals("AH", era.getAsShortText(millis)); // test date assertEquals(expectedDOY, doyValue); assertEquals(expectedMonth, monthValue); assertEquals(expectedDay, dayValue); assertEquals(expectedDOW, dowValue); assertEquals(expectedYear, yearValue); assertEquals(expectedYear, yearOfEraValue); // test leap year boolean leap = ((11 * yearValue + 14) % 30) < 11; assertEquals(leap, year.isLeap(millis)); // test month length switch (monthValue) { case 1: case 3: case 5: case 7: case 9: case 11: assertEquals(30, monthLen); break; case 2: case 4: case 6: case 8: case 10: assertEquals(29, monthLen); break; case 12: assertEquals((leap ? 30 : 29), monthLen); break; } // test year length assertEquals((leap ? 355 : 354), dayOfYearLen); // recalculate date expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1; expectedDay++; expectedDOY++; if (expectedDay > monthLen) { expectedDay = 1; expectedMonth++; if (expectedMonth == 13) { expectedMonth = 1; expectedDOY = 1; expectedYear++; } } millis += SKIP; } }
Example 13
Source File: TestEthiopicChronology.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek. */ public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestEthiopicChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ETHIOPIC_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = ETHIOPIC_UTC.dayOfWeek(); DateTimeField dayOfYear = ETHIOPIC_UTC.dayOfYear(); DateTimeField dayOfMonth = ETHIOPIC_UTC.dayOfMonth(); DateTimeField monthOfYear = ETHIOPIC_UTC.monthOfYear(); DateTimeField year = ETHIOPIC_UTC.year(); DateTimeField yearOfEra = ETHIOPIC_UTC.yearOfEra(); DateTimeField era = ETHIOPIC_UTC.era(); int expectedDOW = new DateTime(8, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek(); int expectedDOY = 1; int expectedDay = 1; int expectedMonth = 1; int expectedYear = 1; while (millis < end) { int dowValue = dayOfWeek.get(millis); int doyValue = dayOfYear.get(millis); int dayValue = dayOfMonth.get(millis); int monthValue = monthOfYear.get(millis); int yearValue = year.get(millis); int yearOfEraValue = yearOfEra.get(millis); int monthLen = dayOfMonth.getMaximumValue(millis); if (monthValue < 1 || monthValue > 13) { fail("Bad month: " + millis); } // test era assertEquals(1, era.get(millis)); assertEquals("EE", era.getAsText(millis)); assertEquals("EE", era.getAsShortText(millis)); // test date assertEquals(expectedYear, yearValue); assertEquals(expectedYear, yearOfEraValue); assertEquals(expectedMonth, monthValue); assertEquals(expectedDay, dayValue); assertEquals(expectedDOW, dowValue); assertEquals(expectedDOY, doyValue); // test leap year assertEquals(yearValue % 4 == 3, year.isLeap(millis)); // test month length if (monthValue == 13) { assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis)); if (yearValue % 4 == 3) { assertEquals(6, monthLen); } else { assertEquals(5, monthLen); } } else { assertEquals(30, monthLen); } // recalculate date expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1; expectedDay++; expectedDOY++; if (expectedDay == 31 && expectedMonth < 13) { expectedDay = 1; expectedMonth++; } else if (expectedMonth == 13) { if (expectedYear % 4 == 3 && expectedDay == 7) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } else if (expectedYear % 4 != 3 && expectedDay == 6) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } } millis += SKIP; } }
Example 14
Source File: BaseDateTimeField.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Sets a value using the specified partial instant. * <p> * The value of this field (specified by the index) will be set. * If the value is invalid, an exception if thrown. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param partial the partial instant * @param fieldIndex the index of this field in the instant * @param values the values to update * @param newValue the value to set, in the units of the field * @return the updated values * @throws IllegalArgumentException if the value is invalid */ public int[] set(ReadablePartial partial, int fieldIndex, int[] values, int newValue) { FieldUtils.verifyValueBounds(this, newValue, getMinimumValue(partial, values), getMaximumValue(partial, values)); values[fieldIndex] = newValue; // may need to adjust smaller fields for (int i = fieldIndex + 1; i < partial.size(); i++) { DateTimeField field = partial.getField(i); if (values[i] > field.getMaximumValue(partial, values)) { values[i] = field.getMaximumValue(partial, values); } if (values[i] < field.getMinimumValue(partial, values)) { values[i] = field.getMinimumValue(partial, values); } } return values; }
Example 15
Source File: TestEthiopicChronology.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek. */ public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestEthiopicChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ETHIOPIC_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = ETHIOPIC_UTC.dayOfWeek(); DateTimeField dayOfYear = ETHIOPIC_UTC.dayOfYear(); DateTimeField dayOfMonth = ETHIOPIC_UTC.dayOfMonth(); DateTimeField monthOfYear = ETHIOPIC_UTC.monthOfYear(); DateTimeField year = ETHIOPIC_UTC.year(); DateTimeField yearOfEra = ETHIOPIC_UTC.yearOfEra(); DateTimeField era = ETHIOPIC_UTC.era(); int expectedDOW = new DateTime(8, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek(); int expectedDOY = 1; int expectedDay = 1; int expectedMonth = 1; int expectedYear = 1; while (millis < end) { int dowValue = dayOfWeek.get(millis); int doyValue = dayOfYear.get(millis); int dayValue = dayOfMonth.get(millis); int monthValue = monthOfYear.get(millis); int yearValue = year.get(millis); int yearOfEraValue = yearOfEra.get(millis); int monthLen = dayOfMonth.getMaximumValue(millis); if (monthValue < 1 || monthValue > 13) { fail("Bad month: " + millis); } // test era assertEquals(1, era.get(millis)); assertEquals("EE", era.getAsText(millis)); assertEquals("EE", era.getAsShortText(millis)); // test date assertEquals(expectedYear, yearValue); assertEquals(expectedYear, yearOfEraValue); assertEquals(expectedMonth, monthValue); assertEquals(expectedDay, dayValue); assertEquals(expectedDOW, dowValue); assertEquals(expectedDOY, doyValue); // test leap year assertEquals(yearValue % 4 == 3, year.isLeap(millis)); // test month length if (monthValue == 13) { assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis)); if (yearValue % 4 == 3) { assertEquals(6, monthLen); } else { assertEquals(5, monthLen); } } else { assertEquals(30, monthLen); } // recalculate date expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1; expectedDay++; expectedDOY++; if (expectedDay == 31 && expectedMonth < 13) { expectedDay = 1; expectedMonth++; } else if (expectedMonth == 13) { if (expectedYear % 4 == 3 && expectedDay == 7) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } else if (expectedYear % 4 != 3 && expectedDay == 6) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } } millis += SKIP; } }
Example 16
Source File: TestCopticChronology.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek. */ public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestCopticChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, COPTIC_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = COPTIC_UTC.dayOfWeek(); DateTimeField dayOfYear = COPTIC_UTC.dayOfYear(); DateTimeField dayOfMonth = COPTIC_UTC.dayOfMonth(); DateTimeField monthOfYear = COPTIC_UTC.monthOfYear(); DateTimeField year = COPTIC_UTC.year(); DateTimeField yearOfEra = COPTIC_UTC.yearOfEra(); DateTimeField era = COPTIC_UTC.era(); int expectedDOW = new DateTime(284, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek(); int expectedDOY = 1; int expectedDay = 1; int expectedMonth = 1; int expectedYear = 1; while (millis < end) { int dowValue = dayOfWeek.get(millis); int doyValue = dayOfYear.get(millis); int dayValue = dayOfMonth.get(millis); int monthValue = monthOfYear.get(millis); int yearValue = year.get(millis); int yearOfEraValue = yearOfEra.get(millis); int monthLen = dayOfMonth.getMaximumValue(millis); if (monthValue < 1 || monthValue > 13) { fail("Bad month: " + millis); } // test era assertEquals(1, era.get(millis)); assertEquals("AM", era.getAsText(millis)); assertEquals("AM", era.getAsShortText(millis)); // test date assertEquals(expectedYear, yearValue); assertEquals(expectedYear, yearOfEraValue); assertEquals(expectedMonth, monthValue); assertEquals(expectedDay, dayValue); assertEquals(expectedDOW, dowValue); assertEquals(expectedDOY, doyValue); // test leap year assertEquals(yearValue % 4 == 3, year.isLeap(millis)); // test month length if (monthValue == 13) { assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis)); if (yearValue % 4 == 3) { assertEquals(6, monthLen); } else { assertEquals(5, monthLen); } } else { assertEquals(30, monthLen); } // recalculate date expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1; expectedDay++; expectedDOY++; if (expectedDay == 31 && expectedMonth < 13) { expectedDay = 1; expectedMonth++; } else if (expectedMonth == 13) { if (expectedYear % 4 == 3 && expectedDay == 7) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } else if (expectedYear % 4 != 3 && expectedDay == 6) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } } millis += SKIP; } }
Example 17
Source File: TestIslamicChronology.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek. */ public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestIslamicChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, ISLAMIC_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = ISLAMIC_UTC.dayOfWeek(); DateTimeField dayOfYear = ISLAMIC_UTC.dayOfYear(); DateTimeField dayOfMonth = ISLAMIC_UTC.dayOfMonth(); DateTimeField monthOfYear = ISLAMIC_UTC.monthOfYear(); DateTimeField year = ISLAMIC_UTC.year(); DateTimeField yearOfEra = ISLAMIC_UTC.yearOfEra(); DateTimeField era = ISLAMIC_UTC.era(); int expectedDOW = new DateTime(622, 7, 16, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek(); int expectedDOY = 1; int expectedDay = 1; int expectedMonth = 1; int expectedYear = 1; while (millis < end) { int dowValue = dayOfWeek.get(millis); int doyValue = dayOfYear.get(millis); int dayValue = dayOfMonth.get(millis); int monthValue = monthOfYear.get(millis); int yearValue = year.get(millis); int yearOfEraValue = yearOfEra.get(millis); int dayOfYearLen = dayOfYear.getMaximumValue(millis); int monthLen = dayOfMonth.getMaximumValue(millis); if (monthValue < 1 || monthValue > 12) { fail("Bad month: " + millis); } // test era assertEquals(1, era.get(millis)); assertEquals("AH", era.getAsText(millis)); assertEquals("AH", era.getAsShortText(millis)); // test date assertEquals(expectedDOY, doyValue); assertEquals(expectedMonth, monthValue); assertEquals(expectedDay, dayValue); assertEquals(expectedDOW, dowValue); assertEquals(expectedYear, yearValue); assertEquals(expectedYear, yearOfEraValue); // test leap year boolean leap = ((11 * yearValue + 14) % 30) < 11; assertEquals(leap, year.isLeap(millis)); // test month length switch (monthValue) { case 1: case 3: case 5: case 7: case 9: case 11: assertEquals(30, monthLen); break; case 2: case 4: case 6: case 8: case 10: assertEquals(29, monthLen); break; case 12: assertEquals((leap ? 30 : 29), monthLen); break; } // test year length assertEquals((leap ? 355 : 354), dayOfYearLen); // recalculate date expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1; expectedDay++; expectedDOY++; if (expectedDay > monthLen) { expectedDay = 1; expectedMonth++; if (expectedMonth == 13) { expectedMonth = 1; expectedDOY = 1; expectedYear++; } } millis += SKIP; } }
Example 18
Source File: MainTest.java From astor with GNU General Public License v2.0 | 4 votes |
private void testField(DateTimeField fieldA, DateTimeField fieldB, long millis, int value, long millis2) { int a, b; long x, y; boolean m, n; // get test a = fieldA.get(millis); b = fieldB.get(millis); testValue(fieldA, fieldB, "get", millis, a, b); // getMaximumValue test // Restrict this test to the fields that matter. Class fieldClass = fieldA.getClass(); if (fieldClass == TestGJDayOfYearField.class || fieldClass == TestGJDayOfMonthField.class || fieldClass == TestGJWeekOfWeekyearField.class) { a = fieldA.getMaximumValue(millis); b = fieldB.getMaximumValue(millis); testValue(fieldA, fieldB, "getMaximumValue", millis, a, b); } // set test a = getWrappedValue (value, fieldA.getMinimumValue(millis), fieldA.getMaximumValue(millis)); b = getWrappedValue (value, fieldB.getMinimumValue(millis), fieldB.getMaximumValue(millis)); if (iMode == JULIAN_MODE && a == 0 && (fieldA.getName().equals("year") || fieldA.getName().equals("weekyear"))) { // Exclude setting Julian year of zero. } else { x = fieldA.set(millis, a); y = fieldB.set(millis, b); testMillis(fieldA, fieldB, "set", millis, x, y, a, b); } // roundFloor test x = fieldA.roundFloor(millis); y = fieldB.roundFloor(millis); testMillis(fieldA, fieldB, "roundFloor", millis, x, y); // roundCeiling test x = fieldA.roundCeiling(millis); y = fieldB.roundCeiling(millis); testMillis(fieldA, fieldB, "roundCeiling", millis, x, y); // roundHalfFloor test x = fieldA.roundHalfFloor(millis); y = fieldB.roundHalfFloor(millis); testMillis(fieldA, fieldB, "roundHalfFloor", millis, x, y); // roundHalfEven test x = fieldA.roundHalfEven(millis); y = fieldB.roundHalfEven(millis); testMillis(fieldA, fieldB, "roundHalfEven", millis, x, y); // remainder test x = fieldA.remainder(millis); y = fieldB.remainder(millis); testMillis(fieldA, fieldB, "remainder", millis, x, y); // add test x = fieldA.add(millis, value); y = fieldB.add(millis, value); testMillis(fieldA, fieldB, "add", millis, x, y); // addWrapField test x = fieldA.addWrapField(millis, value); y = fieldB.addWrapField(millis, value); testMillis(fieldA, fieldB, "addWrapField", millis, x, y); // getDifference test x = fieldA.getDifference(millis, millis2); y = fieldB.getDifference(millis, millis2); try { testValue(fieldA, fieldB, "getDifference", millis, x, y); } catch (RuntimeException e) { System.out.println("Test datetime 2: " + makeDatetime(millis2)); throw e; } // isLeap test m = fieldA.isLeap(millis); n = fieldB.isLeap(millis); testBoolean(fieldA, fieldB, "isLeap", millis, m, n); // getLeapAmount test a = fieldA.getLeapAmount(millis); b = fieldB.getLeapAmount(millis); testValue(fieldA, fieldB, "getLeapAmount", millis, a, b); }
Example 19
Source File: BaseDateTimeField.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Sets a value using the specified partial instant. * <p> * The value of this field (specified by the index) will be set. * If the value is invalid, an exception if thrown. * <p> * If setting this field would make other fields invalid, then those fields * may be changed. For example if the current date is the 31st January, and * the month is set to February, the day would be invalid. Instead, the day * would be changed to the closest value - the 28th/29th February as appropriate. * * @param partial the partial instant * @param fieldIndex the index of this field in the instant * @param values the values to update * @param newValue the value to set, in the units of the field * @return the updated values * @throws IllegalArgumentException if the value is invalid */ public int[] set(ReadablePartial partial, int fieldIndex, int[] values, int newValue) { FieldUtils.verifyValueBounds(this, newValue, getMinimumValue(partial, values), getMaximumValue(partial, values)); values[fieldIndex] = newValue; // may need to adjust smaller fields for (int i = fieldIndex + 1; i < partial.size(); i++) { DateTimeField field = partial.getField(i); if (values[i] > field.getMaximumValue(partial, values)) { values[i] = field.getMaximumValue(partial, values); } if (values[i] < field.getMinimumValue(partial, values)) { values[i] = field.getMinimumValue(partial, values); } } return values; }
Example 20
Source File: TestCopticChronology.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Tests era, year, monthOfYear, dayOfMonth and dayOfWeek. */ public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestCopticChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, COPTIC_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = COPTIC_UTC.dayOfWeek(); DateTimeField dayOfYear = COPTIC_UTC.dayOfYear(); DateTimeField dayOfMonth = COPTIC_UTC.dayOfMonth(); DateTimeField monthOfYear = COPTIC_UTC.monthOfYear(); DateTimeField year = COPTIC_UTC.year(); DateTimeField yearOfEra = COPTIC_UTC.yearOfEra(); DateTimeField era = COPTIC_UTC.era(); int expectedDOW = new DateTime(284, 8, 29, 0, 0, 0, 0, JULIAN_UTC).getDayOfWeek(); int expectedDOY = 1; int expectedDay = 1; int expectedMonth = 1; int expectedYear = 1; while (millis < end) { int dowValue = dayOfWeek.get(millis); int doyValue = dayOfYear.get(millis); int dayValue = dayOfMonth.get(millis); int monthValue = monthOfYear.get(millis); int yearValue = year.get(millis); int yearOfEraValue = yearOfEra.get(millis); int monthLen = dayOfMonth.getMaximumValue(millis); if (monthValue < 1 || monthValue > 13) { fail("Bad month: " + millis); } // test era assertEquals(1, era.get(millis)); assertEquals("AM", era.getAsText(millis)); assertEquals("AM", era.getAsShortText(millis)); // test date assertEquals(expectedYear, yearValue); assertEquals(expectedYear, yearOfEraValue); assertEquals(expectedMonth, monthValue); assertEquals(expectedDay, dayValue); assertEquals(expectedDOW, dowValue); assertEquals(expectedDOY, doyValue); // test leap year assertEquals(yearValue % 4 == 3, year.isLeap(millis)); // test month length if (monthValue == 13) { assertEquals(yearValue % 4 == 3, monthOfYear.isLeap(millis)); if (yearValue % 4 == 3) { assertEquals(6, monthLen); } else { assertEquals(5, monthLen); } } else { assertEquals(30, monthLen); } // recalculate date expectedDOW = (((expectedDOW + 1) - 1) % 7) + 1; expectedDay++; expectedDOY++; if (expectedDay == 31 && expectedMonth < 13) { expectedDay = 1; expectedMonth++; } else if (expectedMonth == 13) { if (expectedYear % 4 == 3 && expectedDay == 7) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } else if (expectedYear % 4 != 3 && expectedDay == 6) { expectedDay = 1; expectedMonth = 1; expectedYear++; expectedDOY = 1; } } millis += SKIP; } }