Java Code Examples for org.joda.time.DateTimeField#get()
The following examples show how to use
org.joda.time.DateTimeField#get() .
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: TestBuddhistChronology.java From astor with GNU General Public License v2.0 | 5 votes |
public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestBuddhistChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, BUDDHIST_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = BUDDHIST_UTC.dayOfWeek(); DateTimeField weekOfWeekyear = GJ_UTC.weekOfWeekyear(); DateTimeField dayOfYear = BUDDHIST_UTC.dayOfYear(); DateTimeField dayOfMonth = BUDDHIST_UTC.dayOfMonth(); DateTimeField monthOfYear = BUDDHIST_UTC.monthOfYear(); DateTimeField year = BUDDHIST_UTC.year(); DateTimeField yearOfEra = BUDDHIST_UTC.yearOfEra(); DateTimeField era = BUDDHIST_UTC.era(); DateTimeField gjDayOfWeek = GJ_UTC.dayOfWeek(); DateTimeField gjWeekOfWeekyear = GJ_UTC.weekOfWeekyear(); DateTimeField gjDayOfYear = GJ_UTC.dayOfYear(); DateTimeField gjDayOfMonth = GJ_UTC.dayOfMonth(); DateTimeField gjMonthOfYear = GJ_UTC.monthOfYear(); DateTimeField gjYear = GJ_UTC.year(); while (millis < end) { assertEquals(gjDayOfWeek.get(millis), dayOfWeek.get(millis)); assertEquals(gjDayOfYear.get(millis), dayOfYear.get(millis)); assertEquals(gjDayOfMonth.get(millis), dayOfMonth.get(millis)); assertEquals(gjMonthOfYear.get(millis), monthOfYear.get(millis)); assertEquals(gjWeekOfWeekyear.get(millis), weekOfWeekyear.get(millis)); assertEquals(1, era.get(millis)); int yearValue = gjYear.get(millis); if (yearValue <= 0) { yearValue++; } yearValue += 543; assertEquals(yearValue, year.get(millis)); assertEquals(yearValue, yearOfEra.get(millis)); millis += SKIP; } }
Example 2
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 3
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 4
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 5
Source File: TestBuddhistChronology.java From astor with GNU General Public License v2.0 | 4 votes |
public void testCalendar() { if (TestAll.FAST) { return; } System.out.println("\nTestBuddhistChronology.testCalendar"); DateTime epoch = new DateTime(1, 1, 1, 0, 0, 0, 0, BUDDHIST_UTC); long millis = epoch.getMillis(); long end = new DateTime(3000, 1, 1, 0, 0, 0, 0, ISO_UTC).getMillis(); DateTimeField dayOfWeek = BUDDHIST_UTC.dayOfWeek(); DateTimeField weekOfWeekyear = GJ_UTC.weekOfWeekyear(); DateTimeField dayOfYear = BUDDHIST_UTC.dayOfYear(); DateTimeField dayOfMonth = BUDDHIST_UTC.dayOfMonth(); DateTimeField monthOfYear = BUDDHIST_UTC.monthOfYear(); DateTimeField year = BUDDHIST_UTC.year(); DateTimeField yearOfEra = BUDDHIST_UTC.yearOfEra(); DateTimeField era = BUDDHIST_UTC.era(); DateTimeField gjDayOfWeek = GJ_UTC.dayOfWeek(); DateTimeField gjWeekOfWeekyear = GJ_UTC.weekOfWeekyear(); DateTimeField gjDayOfYear = GJ_UTC.dayOfYear(); DateTimeField gjDayOfMonth = GJ_UTC.dayOfMonth(); DateTimeField gjMonthOfYear = GJ_UTC.monthOfYear(); DateTimeField gjYear = GJ_UTC.year(); DateTimeField gjYearOfEra = GJ_UTC.yearOfEra(); DateTimeField gjEra = GJ_UTC.era(); while (millis < end) { assertEquals(gjDayOfWeek.get(millis), dayOfWeek.get(millis)); assertEquals(gjDayOfYear.get(millis), dayOfYear.get(millis)); assertEquals(gjDayOfMonth.get(millis), dayOfMonth.get(millis)); assertEquals(gjMonthOfYear.get(millis), monthOfYear.get(millis)); assertEquals(gjWeekOfWeekyear.get(millis), weekOfWeekyear.get(millis)); assertEquals(1, era.get(millis)); int yearValue = gjYear.get(millis); if (yearValue <= 0) { yearValue++; } yearValue += 543; assertEquals(yearValue, year.get(millis)); assertEquals(yearValue, yearOfEra.get(millis)); millis += SKIP; } }
Example 6
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 7
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 8
Source File: ZoneInfoCompiler.java From astor with GNU General Public License v2.0 | 4 votes |
static int parseDayOfWeek(String str) { DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 9
Source File: ZoneInfoCompiler.java From astor with GNU General Public License v2.0 | 4 votes |
static int parseMonth(String str) { DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 10
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 11
Source File: Time_11_ZoneInfoCompiler_s.java From coming with MIT License | 4 votes |
static int parseMonth(String str) { DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear(); return field.get(field.set(0, str, Locale.ENGLISH)); }
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: 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 14
Source File: ZoneInfoCompiler.java From astor with GNU General Public License v2.0 | 4 votes |
static int parseDayOfWeek(String str) { DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 15
Source File: ZoneInfoCompiler.java From astor with GNU General Public License v2.0 | 4 votes |
static int parseMonth(String str) { DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 16
Source File: Time_11_ZoneInfoCompiler_t.java From coming with MIT License | 4 votes |
static int parseDayOfWeek(String str) { DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 17
Source File: Time_11_ZoneInfoCompiler_t.java From coming with MIT License | 4 votes |
static int parseMonth(String str) { DateTimeField field = ISOChronology.getInstanceUTC().monthOfYear(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 18
Source File: Time_11_ZoneInfoCompiler_s.java From coming with MIT License | 4 votes |
static int parseDayOfWeek(String str) { DateTimeField field = ISOChronology.getInstanceUTC().dayOfWeek(); return field.get(field.set(0, str, Locale.ENGLISH)); }
Example 19
Source File: AbstractInstant.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Get the value of one of the fields of a datetime. * <p> * This could be used to get a field using a different Chronology. * For example: * <pre> * Instant dt = new Instant(); * int gjYear = dt.get(Chronology.getCoptic().year()); * </pre> * * @param field the DateTimeField to use, not null * @return the value * @throws IllegalArgumentException if the field is null */ public int get(DateTimeField field) { if (field == null) { throw new IllegalArgumentException("The DateTimeField must not be null"); } return field.get(getMillis()); }
Example 20
Source File: AbstractInstant.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Get the value of one of the fields of a datetime. * <p> * This could be used to get a field using a different Chronology. * For example: * <pre> * Instant dt = new Instant(); * int gjYear = dt.get(Chronology.getCoptic().year()); * </pre> * * @param field the DateTimeField to use, not null * @return the value * @throws IllegalArgumentException if the field is null */ public int get(DateTimeField field) { if (field == null) { throw new IllegalArgumentException("The DateTimeField must not be null"); } return field.get(getMillis()); }